Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threading / Loops in Python Plugin
#12
Hello all - mainly Ofnuts!.  So back at doing some work on this.  I was able to get the Gimp->Prism Pipeline outbound comms to work.  But now I am trying to get the inbound to work.  I had to divide this up into three scripts:

 -  Prism_Menu: registers the menu items and sends cli command's to the bridge (outbound)
 -  Prism_Bridge: does not register as a plugin and runs in Py3.11 and communicates with Prism (outbound)
 -  Prism_Functions: registers as a plugin, starts the script server, and will execute python-fu procedures. (inbound)

I am using 2.99 (yes I know it is in development), but it is working for us and by the time I finally get this finished I don't want to write it again.

So to get my external script coming from Prism to communicate with Gimp, I have started using the script server - I could never get a non-blocking listening script to work.

The external script is sending:

       f'(python-fu-prism-saveAction "{filepath}")'

to the script server and is being receiving correctly:

ScriptFu server: received request #0 from IP address 127.0.0.1: (python-fu-prism-saveAction "N:/Data/Projects/Prism Tests/01_Production/Assets/Building/Scenefiles/gimp/Paint/Building_Paint_v003.xcf"),[queue length: 1] on Thu Apr 18 11:15:52 2024

But I need my functions plugin to be able to parse the arg of the file path it receives to use in the procedure (this is just the first bit of functionality - when I get this all working I will add more procedures).  As you can see with all the commented-out lines, I have tried a bunch of things I have found around the web.  But I cannot get anything to work.  If I hardcode the filePath either in the saveAction(), or PrismFunctions(Gimp.PlugIn) it works, but I cannot get it to use the passed argument.

So it boils down to does anybody know how to pass the received argument to the callback function?

FYI:  I might either be missing something simple, there may be a completely better way to do this, or it cannot be done in Gimp.



In the below code, the "data" print statement always show "data" is empty.

Prism_Fuctions.py:

...other code...
def saveAction(procedure, run_mode, data):

   print("\n*** IN saveAction ***\n")                          #   DEBUG

   print("*** data:  ", data, "\n\n")

   # filePath = data["filePath"]

   # print("*** filePath:  ", filePath, "\n\n")

   # filePath = r"C:\tmp\Building_Paint_v001.xcf"      #    HARDCODED FOR TESTING

   ### vvvv WORKING vvvvv ####
   # images = pdb.gimp_get_images()
   # imageList = images[1]
   # currentImage = imageList.data[0]

   # file = Gio.File.new_for_path(filePath)

   # # Save the image in the .xcf file format
   # pdb.gimp_xcf_save(image=currentImage , file=file)
   ### ^^^^ WORKING ^^^^ ####

   return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())


class PrismFunctions(Gimp.PlugIn):

   def __init__(self):
       super().__init__()
       self._filePath = ""                     #   NEEDED???

   ## Parameter: filePath ##
   # @GObject.Property(type=str,
   #                   nick= _("File Path"),
   #                   blurb= _("File Path"))
   
   # def filePath(self):
   #     return self._filePath
   
   # def set_filePath(self, file_path):
   #     self._filePath = file_path

   # @filePath.setter
   # def filePath(self, filePath):
   #     self._filePath = filePath

   __gproperties__ = {
       "filePath": (
           str,
           _("filePath"),
           "File Path",
           "File Path",
           GObject.ParamFlags.READWRITE,
           )
       }

   
   ## GimpPlugIn virtual methods ##
   def do_set_i18n(self, procname):
       return True, 'gimp30-python', None

   def do_query_procedures(self):
       return [ "python-fu-prism-saveAction" ]

   def do_create_procedure(self, name):

       procedure = None
       
       if name == 'python-fu-prism-saveAction':

           data = {"filePath": None}

           procedure = Gimp.Procedure.new(self,
                                       name,
                                       Gimp.PDBProcType.PLUGIN,
                                       # Gimp.PDBProcType.EXTENSION,  # Change to EXTENSION ???
                                       saveAction,
                                       data
                                       )
           
           procedure.set_documentation(_("Prism save action"),
                                       help_doc,
                                       "")
           
           procedure.set_attribution("Joshua Breckeen",
                                     "Prism Pipeline",
                                     "2024")
           
           procedure.add_argument_from_property(self, "filePath")

           # procedure.set_property("filePath", self._filePath)


           # # Get the list of arguments
           # arguments = procedure.get_arguments()
           
           # # The first (and only) argument should be the filePath
           # file_path = arguments[0]
           
           # # Set the filePath property with the received value
           # self.filePath = file_path


       else:
           procedure = None

       return procedure

   
   print("***** Loading Prism Functions ******")                   #   DEBUG
   time.sleep(.1)

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


Messages In This Thread
Threading / Loops in Python Plugin - by JBreckeen - 01-01-2024, 05:11 PM
RE: Threading / Loops in Python Plugin - by JBreckeen - 04-18-2024, 03:45 PM

Forum Jump: