Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Migrating Python plug-in from Gimp 2.10
#3
(05-28-2025, 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


Messages In This Thread
RE: Migrating Python plug-in from Gimp 2.10 - by nerudaj - 05-28-2025, 02:42 PM

Forum Jump: