Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Migrating Python plug-in from Gimp 2.10
#1
Hi,

I'd appreciate some help with the migration of one of my Python-based Gimp 2.10 plugins to Gimp 3. I've already managed to write two unrelated plugins that do some import/export shenanigans so I am able to add new plugin, debug it somewhat etc.

However, I have three issues:
1) It seems that not all Procedure::add_xy_argument work or at least they don't behave as intended. My understanding is that calling:
Code:
dialog = GimpUi.ProcedureDialog.new(procedure, config, plug_in_name)
dialog.fill()
will render all arguments that I added to a procedure. That doesn't seem to happen. For example, uint argument doesn't show up while int argument does. Is it that some arguments require extra leg work during the initialization of ProcedureDialog to show up?

2) It seems that I am not able to simply add widgets to ProcedureDialog, I can only refer to id's added to the procedure during do_create_procedure. Therefore, I can't for example add buttons with callback actions or a dropdown that would list all layer groups but not regular layers. Is there any workaround for this?

3) I didn't find a way to disable a bunch of default buttons that render for each plugin, namely these:

   

Is it possible to hide all of these?

Now why am I asking? Here's a plugin demo I have for 2.10:
[Image: tile_preview.gif]
As you can see, this plugin is only a preview with its own rendering canvas to which I copy layers selected in the dropdown menus. I am attempting to port it to Gimp3, but I don't know how to interface with Gtk3 directly so I can add whatever widgets I need during plugin run and not during initialization (not to mention I can't add buttons). Source for the 2.10 plugin is here: gimp-pixel-art-utils/tile-preview/tile-preview.py at main · nerudaj/gimp-pixel-art-utils

Any ideas how to achieve the same result in Gimp3?
Reply
#2
1) AFAIK not all argument types have existing selectors in current Gimp3 versions (for instance, image and paths) so when they are used as arguments, there is nothing for them in the auto-generated dialog

2) you can generate you own complete dialog. AFAIK you can add GimpUI elements in a regular pyGTK script.

3) see 2)
Reply
#3
(Yesterday, 07:42 AM)Ofnuts Wrote: 1) AFAIK not all argument types have existing selectors in current Gimp3 versions (for instance, image and paths) so when they are used as arguments, there is nothing for them in the auto-generated dialog

2) you can generate you own complete dialog. AFAIK you can add GimpUI elements in a regular pyGTK script.

3) see 2)

Thanks for your response. I didn't realize I can just ignore ProcedureDialog and create my own window with Gtk. If anybody else stumbles upon this thread, here's a minimal Python plugin that opens its own window:

Code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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 Gegl
import sys
#import pygtk
#import gtk

plug_in_proc = "plug-in-nerudaj-tile-preview"
plug_in_binary = "py3-tile-preview"
plug_in_author = "nerudaj"
plug_in_org = "Pixel Art Utils"
plug_in_year = "2025"
plug_in_docs = "Plug-in for previewing how a layer would like when tiled."
plug_in_name = "Tile Preview"
plug_in_path = "<Image>/Pixel Art"

def log(message):
   proc = Gimp.get_pdb().lookup_procedure("gimp-message")
   config = proc.create_config()
   config.set_property("message", message)
   proc.run(config)

def tile_preview_run(procedure, run_mode, image, drawables, config, data):
   if run_mode != Gimp.RunMode.INTERACTIVE:
       return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, None)

   window = Gtk.Window.new(Gtk.WindowType.TOPLEVEL)
   window.resize(400, 600)
   window.show();
   Gtk.main()

   return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, None)

class TilePreview (Gimp.PlugIn):
   def do_query_procedures(self):
       return [ plug_in_proc ]

   def do_create_procedure(self, name):
       if name != plug_in_proc:
           return None

       procedure = Gimp.ImageProcedure.new(self,
                                           name,
                                           Gimp.PDBProcType.PLUGIN,
                                           tile_preview_run,
                                           None)

       procedure.set_sensitivity_mask(Gimp.ProcedureSensitivityMask.DRAWABLE |
                                      Gimp.ProcedureSensitivityMask.NO_DRAWABLES)
       procedure.set_menu_label(plug_in_name)
       procedure.set_attribution(plug_in_author, plug_in_org, plug_in_year)
       procedure.add_menu_path(plug_in_path)
       procedure.set_documentation(plug_in_docs, None)

       return procedure

Gimp.main(TilePreview.__gtype__, sys.argv)
Reply


Forum Jump: