2 hours ago
Development on Windows 11 using python 3 in Gimp 3.0.6.
I can find no way of getting the path from a GFile returned from the parameter setting dialog in a plugin.
A file parameter is created by
The purpose of this is to allow browsing for a directory. It shows up in the plugin dialog as a directory browser, and a directory can be selected.
The parameter is then obtained after the dialog has run as
This has returned a GFile, not (unfortunately) a string path. The question is, how do I get the path out of the GFile? (I need it because I need to do some manipulations on it).
I've tried various things - src_gfile.get_path() produced nothing (though in another plugin I looked at it clearly did looking at the code, but that may have been on Linux, not Windows). I did find that if in the python console I create a GFile and get the path as
I do get the path as 'C:\a\b\c' - but not when it comes from the config as above.
src_gfile.get_uri() does produce the URI as a string, looking something line 'file:\\\C:\a\b\c'. Being a URI, it has the scheme on the from, and I can lose the 'file:\\\' by editing the string, but can't help feeling that is a bodge, certainly not cross platform.
I then found query_info(). So I tried
I do get something back - but it's only the final leaf, ie 'c', not the full path and I can't find any method that does that.
So, basically, I can find no way of tidily get the full path as a string from a GFile. Can anyone help?
I can find no way of getting the path from a GFile returned from the parameter setting dialog in a plugin.
A file parameter is created by
Code:
procedure.add_file_argument("src-folder",
"Source folder",
"Location of files to parse",
Gimp.FileChooserAction.CREATE_FOLDER,
False,
None,
GObject.ParamFlags.READWRITE)The parameter is then obtained after the dialog has run as
Code:
src_gfile = config.get_property("src-folder")I've tried various things - src_gfile.get_path() produced nothing (though in another plugin I looked at it clearly did looking at the code, but that may have been on Linux, not Windows). I did find that if in the python console I create a GFile and get the path as
Code:
file = Gio.File.new_for_path("C:\\a\\b\\c")
file.get_path()src_gfile.get_uri() does produce the URI as a string, looking something line 'file:\\\C:\a\b\c'. Being a URI, it has the scheme on the from, and I can lose the 'file:\\\' by editing the string, but can't help feeling that is a bodge, certainly not cross platform.
I then found query_info(). So I tried
Code:
file_info = src_gfile.query_info("standard::*", Gio.FileQueryInfoFlags.NONE, None)
file_info.get_display_name()So, basically, I can find no way of tidily get the full path as a string from a GFile. Can anyone help?

