![]() |
|
How to get the full path from a GFile - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +--- Thread: How to get the full path from a GFile (/Thread-How-to-get-the-full-path-from-a-GFile) Pages:
1
2
|
How to get the full path from a GFile - nmw01223 - 01-21-2026 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 Code: procedure.add_file_argument("src-folder",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")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)So, basically, I can find no way of tidily get the full path as a string from a GFile. Can anyone help? RE: How to get the full path from a GFile - programmer_ceds - 01-21-2026 Would this help? https://docs.gtk.org/gio/method.File.get_path.html RE: How to get the full path from a GFile - nmw01223 - 01-21-2026 Thanks, yes, that's the function I used. In some circumstances it works, as when I created the GFile with new,_from_path(), but not when the GFile is returned from config.get_property(). The help says sometimes it can return a path, sometimes not. Still looking, can't believe it can be this obscure, I must have missed something. RE: How to get the full path from a GFile - MrsP-from-C - 01-21-2026 Maybe this helps you: Code: # filename howto:RE: How to get the full path from a GFile - nmw01223 - 01-21-2026 Yes thanks, but actually the path is not created by me, it's created by the dialog that is automatically built by Gimp for setting the parameters for the plugin. One in my case is a directory browser to allow selecting a directory to save images to. Then I get the path from the parameter stored in the config after the dialog has run. But, it returns a GFile not a path string, I'm trying to get the path string out of the GFile as I need to manipulate the path. The GFile must know what the path is - but it won't tell me. RE: How to get the full path from a GFile - MrsP-from-C - 01-21-2026 What about: Code: Gimp.file_get_utf8_name(gfile)gfile as from the example above. RE: How to get the full path from a GFile - nmw01223 - 01-21-2026 Thanks. Odd result again. If I use that in the python console on a GFile I create with ...new_for_path(<path>), it's fine, I get the path back, but if I use it on the GFile that comes out of the config, ie set by the dialog, I get file:\\\<path> - same therefore as gf.get_uri(). Hey ho. RE: How to get the full path from a GFile - programmer_ceds - 01-22-2026 (01-21-2026, 10:46 PM)nmw01223 Wrote: Thanks. Odd result again. As a quick and dirty test I 'mangled' the save histogram script to use as a test-bed. Run GIMP from a terminal window and you should get 4 lines of diagnostic output when the script is run (ignore the error that follows this output - its just because it doesn't save the histogram and returns a result in an unexpected format). On Linux Mint 22.3 Cinnamon I get the following output when selected the Documents folder For get_url file:///home/un/Documents For get_path /home/un/Documents For get_parse_name /home/un/Documents For get_basename Documents RE: How to get the full path from a GFile - nmw01223 - 01-22-2026 Thanks, I'll take a look. But as an aside, I am now wondering if this might be a difference between the Windows and Linux platforms. RE: How to get the full path from a GFile - nmw01223 - 01-22-2026 Quote:On Linux Mint 22.3 Cinnamon I get the following output when selected the Documents folder Yes, checked it all now. I get the same as you - on Linux (Ubuntu 24.04.3). I just don't on Windows 11. Suspect it may therefore be a bug. UPDATE: Reported it as bug #15734. |