Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Troubleshooting Python plugin to load an XCF file
#1
In connection with troubleshooting my bigger project (thread here: https://www.gimp-forum.net/Thread-Gimp-P...d-question) I'm trying to create a really simple plugin to open an XCF file in the GUI. Eventually I will make this non-interactive and make it a wrapper to launch my other function, but for now I just want it to open the GUI and use pdb.gimp_xcf_load to open my XCF. 

I know definitions are not completely needed, but having them seems to make it easier to call a function from the command line, so I have a definition for now. 

The command line opens the Gimp UI, but doesn't open my XCF, and throws some errors. Any idea what I'm doing wrong here in this very simple plugin?

Command line argument:
Code:
gimp --batch-interpreter python-fu-eval -b '(python_fu_open_xcf "/Users/TimB/Desktop/template.xcf")'



Plugin:
Code:
#!/usr/bin/env python
#
# Script to open .XCF file

from gimpfu import *

def open_xcf(file):
   
   try:
       # Open XCF file
       image = pdb.gimp_xcf_load(file, file)
       layer = pdb.gimp_image_get_active_layer(image)

   except Exception as err:
       gimp.message("Unexpected error: " + str(err))

register(
   "python_fu_open_xcf",
   "Add image to layer",
   "Add image to layer and flatten.",
   "TCB",
   "TCB",
   "2021",
   "<Image>/Filters/Tim/Open XCF",
   "*",
   [
       (PF_FILE, "file", "XCF file to open", ""),
   ],
   [],
   open_xcf)

main()

Terminal output:
Code:
GIMP is started as MacOS application
2021-03-18 23:02:16.722 gimp[9241:136602] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
Cannot spawn a message bus without a machine-id: Unable to load /var/lib/dbus/machine-id or /etc/machine-id: Failed to open file “/var/lib/dbus/machine-id”: No such file or directory
/Applications/GIMP-2.10.app/Contents/MacOS/gimp: LibGimpBase-WARNING: gimp: gimp_wire_read(): error
gimp_check_updates_callback: loading of https://www.gimp.org/gimp_versions.json failed: Operation not supported
Traceback (most recent call last):
 File "/Applications/GIMP-2.10.app/Contents/Resources/lib/gimp/2.0/python/gimpfu.py", line 827, in _run
   return apply(func, params[1:])
 File "/Applications/GIMP-2.10.app/Contents/Resources/lib/gimp/2.0/plug-ins/python-eval.py", line 25, in code_eval
   exec code in globals()
 File "<string>", line 1
   (python_fu_open_xcf "/Users/TimB/Desktop/template.xcf")
                                                        ^
SyntaxError: invalid syntax
batch command experienced an execution error
Reply


Messages In This Thread
Troubleshooting Python plugin to load an XCF file - by TimorousMe - 03-19-2021, 03:06 AM

Forum Jump: