Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python plug-in error when no image
#1
Hi guys,
So I'm on the road to develop a plug-in for GIMP 2.99.16, but I've just started out. I am taking baby steps and ran into this error at the get-go.

What I want to achieve:
I want the plug-in menu item to be enabled when there is no image opened.

What I changed:
procedure.set_image_types('*')  <- Works.

to:
procedure.set_image_types('')   # <- Broken.

What happens is that the menu item becomes enabled, but when I start the plug-in, I get an error:

"Procedure 'jb-plug-in-first-try' has been called with an invalid ID for argument 'image'. Most likely a plug-in is trying to work on an image that doesn't exist any longer."

I am using the code found at:
plug-in tutorial

 This code doesn't reference an image.
Code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import gi

gi.require_version('Gimp', '3.0')
gi.require_version('GimpUi', '3.0')

from gi.repository import Gimp
from gi.repository import GLib


class MyFirstPlugin (Gimp.PlugIn):
   def do_query_procedures(self):
       return [ "jb-plug-in-first-try" ]

   def do_set_i18n (self, name):
       return False

   def do_create_procedure(self, name):
       procedure = Gimp.ImageProcedure.new(
           self,
           name,
           Gimp.PDBProcType.PLUGIN,
           self.run,
           None
       )

       # Requires no image, ''.
       # procedure.set_image_types('*')  <- Works.
       procedure.set_image_types('')   # <- Broken.

       procedure.set_menu_label("My first Python plug-in")
       procedure.add_menu_path('<Image>/Filters/Tutorial/')
       procedure.set_documentation(
           "My first Python plug-in tryout",
           "My first Python 3 plug-in for GIMP 3",
           name
       )
       procedure.set_attribution("Your name", "Your name", "2024")
       return procedure

   def run(self, procedure, *arg):
       Gimp.message("Hello world!")
       # do what you want to do, then, in case of success, return:
       return procedure.new_return_values(
           Gimp.PDBStatusType.SUCCESS, GLib.Error()
       )


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


On another matter, is there a way to refresh the plug-in, as in have GIMP reload it, so that I can edit code and not have to restart GIMP?

Thank you all for your attention,
Charles


Attached Files
.zip   MyFirstPlugin.zip (Size: 775 bytes / Downloads: 32)
Reply
#2
You don't have to reload or restart, unless you change stuff in what formerly was the registration.

To start without an image check this answer here:
https://discourse.gnome.org/t/gimp-2-99-...mage/12544

A first little tutorial is here:
https://testing.docs.gimp.org/2.99/en/gi...orial.html
Reply
#3
Thank you nelo. I found the solution. The correct way is to start the plug-in without an image is to call:
procedure.set_sensitivity_mask(Gimp.ProcedureSensitivityMask.ALWAYS)

Cheers,
Charles
Reply


Forum Jump: