Uncategorized

Python plug-in error when no image



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



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *