Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python-fu plugin UI
#1
I have two questions regarding Python-fu plugin user interfaces.

1. Let say I am integrating two or more algorithms into my plugin. The user choose the algorithm with the PF_OPTION control. I would like the plugin user interface to update itself by hiding or making visible certain UI controls. Is it possible to achieve this behaviour with Python-fu? If not, is there any way to achieve something like this with any other tool?

2. An image is worth a thousand words. Instead of showing a PF_OPTION with a list of names trying to describe the output effect, is it possible to have a PF_OPTION showing a list of example pictures of the effects? I'm not interested in generating a preview!!!
Reply
#2
1. Not with the auto-generated dialog. Your plugin can have its own custom-built interface (PyGTK is a good idea since AFAIK it is available in all Gimp installations: Linux, OSX and Windows). Another solution is to have the Python code register two(or more) different entries, one for each algorithm. Since the registration is different, they can have different parameters and therefore auto-generated tailored dialogs. Since they are in the same file, they can easily share a lot of code. Many of my scripts do so.

2. AFAIK not with the auto-generated dialog. Your plugin can have its own custom-built interface (PyGTK is a good idea since AFAIK it is available in all Gimp installations: Linux, OSX and Windows). If you take my drift Smile
Reply
#3
(01-16-2019, 10:16 PM)Ofnuts Wrote: Your plugin can have its own custom-built interface (PyGTK is a good idea since AFAIK it is available in all Gimp installations: Linux, OSX and Windows). If you take my drift Smile

Thank you very much!!!

Do you have some examples that I can look to connect Python-fu with pyGTK?
Reply
#4
The only example I understand: https://sourceforge.net/projects/gimp-to...y/download
Reply
#5
(01-16-2019, 11:21 PM)Ofnuts Wrote: The only example I understand:  https://sourceforge.net/projects/gimp-to...y/download

Thanks very much! Looking at the example, you used pygtk with gtk 2.0. Do you think it is possible to use gtk+ 3 with python-fu? At the moment I've tryed to do:

Code:
from gimpfu import *
import gi
import os
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk, GObject, GdkPixbuf
GObject.threads_init()

but I'm getting this error when executing grimp from the terminal:

Code:
Traceback (most recent call last):
 File "/home/davide/.config/GIMP/2.10/plug-ins/style-transfer/style-transfer.py", line 2, in <module>
   import gi as gi3
 File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 39, in <module>
   raise ImportError(_static_binding_error)
ImportError: When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject". See: https://bugzilla.gnome.org/show_bug.cgi?id=709183
Reply
#6
Try to import gi before gimpfu.  However gimpfu itself requires GTK2.

* digs in the Gimp source code *

In fact you don't need gimpfu. gimpfu is just a convenience layer to build the GUI for you and manage a few things (such as saving parameters between uses, etc). You don't absolutely need it to build your Python plugin and there are lower-level imports that won't drag GTK2 in and let you use GTK3(*). I'll let you pore over the doc from the source code.

I may be able to answer a few questions, even though you are quickly leaving my comfort zone Smile

(*) But you have to be aware that using GTK3 makes your plugin Linux-only, on other platforms you will only find a GTK2 port available with Gimp.
Reply
#7
(01-19-2019, 06:32 PM)Ofnuts Wrote: Try to import gi before gimpfu.  However gimpfu itself requires GTK2.

* digs in the Gimp source code *

In fact you don't need gimpfu. gimpfu is just a convenience layer to build the GUI for you and manage a few things (such as saving parameters between uses, etc). You don't absolutely need it to build your Python plugin and there are lower-level imports that won't drag GTK2 in and let you use GTK3(*). I'll let you pore over the doc from the source code.

I may be able to answer a few questions, even though you are quickly leaving my comfort zone Smile

(*) But you have to be aware that using GTK3 makes your plugin Linux-only, on other platforms you will only find a GTK2 port available with Gimp.

Thank you for this answer!!! Smile

Today I had a bit of time to look at the documentation and the source code as well. I think it is impossible to use GTK3 code within Python-fu. While it is true that gimpfu is just a convenience layer, I've seen that gtk 2 is integrated in the gimp module (which is then imported by gimpfu, gimpplugin, ...).

I've tryed to import "gi" before "gimpfu" (or any other gimp module"), but I always got the error:


Code:
ImportError: could not import gobject (could not find _PyGObject_API object)

Later I will look at the possibility to further separate the GTK3 interface from the Python fu script. I'll let you know! Smile
Reply


Forum Jump: