GIMP 2.99/ Python3 Replacement for PF_OPTIONS?

How do we replace PF_OPTION?

I’ve found all kinds of

__gproperties__{

}

like

"file": (Gio.File,
         "Some File",
         "Some File",
         GObject.ParamFlags.READWRITE),
"example float":  (float,
                 "Example Float",
                 "Example Float",
                 0.001, 1.0, 0.01,
                 GObject.ParamFlags.READWRITE),
"example bool": (bool,
		         "Yes or NO",
		         "Yes or No",
		          False,
		          GObject.ParamFlags.READWRITE),
"example string": (str,
                  Example String,
                  "Example String",
                  "Preset",
                  GObject.ParamFlags.READWRITE)

But how can we handle options?

PF_OPTION hasn’t been implemented yet, see e.g. here.

For now at least, you have to use int. See e.g. palette-sort which in 2.10 used PF_OPTION for selections, channel1, channel2, and pchannel.

Thank you.
I’ll look into that.

I ahve found it useful to use the descriptive part of the parameter definition as a reminder of what the numbers that are set actually mean. Example is
“metal”:(int, “_Metal colour”, “0=Aluminium, 1=Brass, 2=Bronze, 3=Copper, 4=Gold, 5=Nickel, 6=Silver, 7=Titanium, 8=Custom”, 0, 8, 4, GObject.ParamFlags.READWRITE),
Really do need a proper op[tion though!

That’s a good idea @JimDee2.
I’ll keep that in mind.
Thanks.

There’s a proposed merge request to re-implement SF-OPTIONS in Script-fu: 2.99 ScriptFu: add custom widgets to GimpProcedureDialog (!1318) · Merge requests · GNOME / GIMP · GitLab

So hopefully once that’s in, it’ll lead to PF-OPTIONS being re-implemented as well.

Thanks for that news @CmykStudent.
What about PF_Layers to select layers?
Do we already have that?

Not yet, but it’s planned as part of the final API improvements: 2.99 libgimp: enhance, item chooser widget for plugin dialogs; PF_DRAWABLE etc. for PDB procedure arguments (#9390) · Issues · GNOME / GIMP · GitLab

Respectfully, I don’t know if anyone is working on a direct replacement for PF_ENUM.

Also, the chooser for Layer is done in libgimp.
So if you declare an argument of type Layer for a Python plugin,
wouldn’t GimpProcedureDialog already show a widget for that argument?

(There is a test script Sphere v3 that demonstrates all the widgets for plugin arguments. We need one for Python too, demonstrating the replacements or lack thereof for all the PF_ of PyGimp v2. AFAIK there is only “Test dialog” but it is only demonstrating the widgets for GimpResource.)

See my other post below.

TLDR: I think you must build custom GUI, at least for an enum.

I am not actively working on the Python side of plugins, only on ScriptFu.
Whatever I say could be wrong.

I don’t think there will be something like PF_OPTION,
where GIMP creates a GUI widget from a declaration.
In GIMP issues, we discussed something like what was mentioned earlier in this post:
encoding the enum declaration in the blurb string of the argument declaration for a plugin argument.
I don’t think it is going to happen, because we don’t like encoding and decoding in strings.
I might be able to find a reference to the discussion.
(There were other proposals, like declaring an enum into the PDB.)

I believe a Python plugin author will need to do something like what is done in C.
An example is plug-ins/common/align-layers.c.
I am not aware of a Python example (although one is needed.)

Briefly, you create a dialog, then call methods to insert custom widgets,
then call the fill method and it fills in the rest of the widgets
for the declared arguments.
There are Python example plugins for that, except for custom enum widgets?
Arguments are one-to-one with properties of the plugin procedure.
I use “custom” to mean one that the plugin author builds,
versus “stock” for one that GimpProcedureDialog will build automatically.
Widgets for enums are much more complicated than the stock widgets for primitive types.

For a custom enum widget:
Declare an enum in Python.
Use it to create a GimpIntStore, which is a model of an enum.
Pass the model to specialize when you create a GtkIntComboBox.
Call a method of GimpProcedureDialog to insert that custom widget.
Then call the fill method.

We could generalize this, a Python procedure that takes a Python enum,
uses its special methods to create a GimpIntStore.
Then we could put that Python procedure in the GIMP repo,
and all Python plugins could use it.
But there is no precedent for Python modules
that are shipped with GIMP 3.
(I suppose PyGimp was in v2.)

Ah, my mistake - I meant to reference your report from here: 2.99 libgimp: enhance, replace PF_OPTION for PDB procedure arguments (#9133) · Issues · GNOME / GIMP · GitLab

In theory, someone could follow your work with SF_OPTION and fix this for Python as well. I’d be interested in learning more about that, but hopefully someone else will come along who can finish it faster. :slight_smile: