Search code examples
pythongimppython-fu

How to define a directory input parameter for Gimp Python-Fu plugin


I am building a plugin for Gimp using the Python-Fu interface, and I want the user to specify an output directory where my plugin would then generate several subdirectories and save output files in them. To define a file selection parameter for my plugin, I specify it in an array of parameter definitions in my call to the plugin function 'register()', below.

register(
   ... ,
   [
    (PF_FILE, "filepath", "Output Filepath", "/Default/Path"), ...
   ]
   ...,
)

My problem is that using the above parameter type PF_FILE, the file selector dialog that comes up will not allow the user to select a directory - it requires that a file be selected. How can I alter this parameter definition so that the file dialog will allow a directory to be returned?


Solution

  • You can use PF_DIRNAME:

    register(
       ... ,
       [
        (PF_DIRNAME, "source_directory", "Source Directory", ""), ...
       ]
       ...,
     )
    

    http://git.gnome.org/browse/gimp/tree/plug-ins/pygimp/gimpfu.py