Gimp-Forum.net
Problem with Gimp 3 Python plug-in color_argument - 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)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: Problem with Gimp 3 Python plug-in color_argument (/Thread-Problem-with-Gimp-3-Python-plug-in-color-argument)



Problem with Gimp 3 Python plug-in color_argument - Volker - 11-16-2025

I try to migrate my Python plug-in to decorate a jpeg photo with margin, border and description from Gimp 2 to Gimp 3.

it works as intended as long as I don't add a color-argument. What is wrong with this code?
Code:
import sys
import os
from glob import glob
import gi
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp
gi.require_version('GimpUi', '3.0')
from gi.repository import GimpUi
from gi.repository import GObject
from gi.repository import GLib
#from gi.repository import Gtk
from gi.repository import Gio
from gi.repository import Gegl

...

class MarginBorder(Gimp.PlugIn):
 def do_query_procedures(self):
   return [plugInMBProc]
 def do_create_procedure(self, name):
   procedure = None
   if name == plugInMBProc:
     procedure = Gimp.ImageProcedure.new(self, name,
                                         Gimp.PDBProcType.PLUGIN,
                                         margin_border_run, None)
     procedure.set_sensitivity_mask(Gimp.ProcedureSensitivityMask.DRAWABLE |
                                    Gimp.ProcedureSensitivityMask.NO_DRAWABLES)
     procedure.set_menu_label("Rand und Rahmen")
     procedure.set_attribution("Volker", "Volker Lenhardt", "2025")
     procedure.add_menu_path("<Image>/Volker")
     procedure.set_documentation("Volkers Rand, Rahmen und Bildtext",
                                 "Fügt dem aktiven Bild die Dekorationsebenen "\
                                 + "Rand, Rahmen und Bildtext hinzu.",
                                 None)
     procedure.add_font_argument("font", # name
                                 "Font", # nick
                                 None, # blurb
                                 True, # none_ok
                                 Gimp.Font.get_by_name(
                                   "URW Gothic L Book"), # default_value
                                 False, # default_to_context
                                 GObject.ParamFlags.READWRITE) # flags
     procedure.add_string_argument("desc", # name
                                   "Bildbeschreibung", # nick
                                   None, # blurb
                                   "Irgendwo", # value
                                   GObject.ParamFlags.READWRITE) # flags
     procedure.add_double_argument("marginRelation", # name
                                   "Randbreite in Promille der größten Bildausdehnung", # nick
                                   None, # blurb
                                   0.0, # min
                                   30.0, # max
                                   9.0, # value
                                   GObject.ParamFlags.READWRITE) # flags
     procedure.add_double_argument("borderRelation", # name
                                   "Rahmenbreite in Promille der größten Bildausdehnung", # nick
                                   None, # blurb
                                   0.0, # min
                                   10.0, # max
                                   1.8, # value
                                   GObject.ParamFlags.READWRITE) # flags
     procedure.add_color_argument("borderColor", # name
                                  "Rahmenfarbe", # nick
                                  None, # blurb
                                  False, # has_alpha
                                  Gegl.Color.new("black"), # value
                                  GObject.ParamFlags.READWRITE) # flags
   return procedure

Gimp.main(MarginBorder.__gtype__, sys.argv)

If I omit the procedure.add_color_argument all is well, but with it the plug-in doesn't even show up in Gimp.

I can't find any code errors, or do you?

Thanks in advance for your help.


RE: Problem with Gimp 3 Python plug-in color_argument - programmer_ceds - 11-16-2025

(4 hours ago)Volker Wrote: ... 
I can't find any code errors, or do you?

Thanks in advance for your help.

If you run GIMP in a terminal window you will see the error that is preventing your script from running.

You need to call Babl.init() (just before the add_color_argument would do)

Also you need the following lines near the start of the file:

gi.require_version('Babl', '0.1')
from gi.repository import Babl


RE: Problem with Gimp 3 Python plug-in color_argument - Volker - 11-16-2025

With Babl.init() at the right place the script works as expected.

Thank you.


RE: Problem with Gimp 3 Python plug-in color_argument - programmer_ceds - 11-16-2025

(3 hours ago)Volker Wrote: With Babl.init() at the right place the script works as expected.

Thank you.

Pleased that it worked. I forgot to mention earlier that I think that you should also have a call of Babl.exit() at the end of your processing to free up the resources it uses.