Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python-Fu console crash
#1
Hi

Trying to start with Python scripting and got problem with console crash. Trying both from saved file and entering script in console, when main() function is called console crashes, saying that (translated directly from my language so in details may be little bit different, but: "An error occurred in the plug-in: "python-console.py, The plug-in, by aborting due to an error, may have corrupted the internal state of GIMP. To be safe, it is recommended to save the images and restart the program." Tried different scripts, even with empty main function.
Tried on two computers, version 2.10.38, Windows 11 Pro
Reply
#2
Did you install a specific Python runtime or are you using the one that came with Gimp?

Also, your code shouldn't define a main(). The main() called in a plug-in actually is defined the gimpfu module.
Reply
#3
(08-05-2024, 05:05 PM)Ofnuts Wrote: Did you install a specific Python runtime or are you using the one that came with Gimp?

Also, your code shouldn't define a main(). The main() called in a plug-in actually is defined the gimpfu module.

I'm using the one from Gimp, didn't install any stand-alone Python version. And i'm not defining main() function in script, i mean main script function, which i register. I took few examples from different tutorials, but effect was the same.
Reply
#4
Can you zip one of your failing Python script and attach the ZIP here? Can you show what the empty python-fu console displays?
Reply
#5
Photo 
(08-06-2024, 07:49 AM)Ofnuts Wrote: Can you zip one of your failing Python script and attach the ZIP here? Can you show what the empty python-fu console displays?

Sample codei've tried. Attached screens with empty and entered script console and error output (transaltion in the first post)

Code:
from gimpfu import *

def hello_warning(image, drawable):
    pdb.gimp_message("Hello world!")
    
register(
    "python-fu-hello_warning",
    "SHORT DESCRIPTION",
    "LONG DESCRIPTION",
    "rg", "rg", "2024",
    "Hello_warning",
    "", # type of image it works on (*, RGB, RGB*, RGBA, GRAY etc...)
    [
        # basic parameters are:  (UI_ELEMENT, "variable", "name", Default)
        (PF_IMAGE, "image", "takes current image", None),
        (PF_DRAWABLE, "drawable", "input layer", None)
    ],
    [],
    hello_warning, menu="<Image>/File")  # second item in menu location
    
main()


Attached Files Thumbnail(s)
           
Reply
#6
This is because you call main() in the Python console. In fact the whole idea of copy-pasting your complete plugin code in the console isn't correct. You can try functions, but the structure of the plugin code clashes with the environment of the python console which is also a python plugin. What you can do is try a function up to the body  of your plugin (the function you define in the register() call), in which case you have to figure out a way to pass the parameters (find an image reference, and a layer in our case probably using gimp.image_list[()[0] for the image and image.active_layer for the layer.

Otherwise, if you put you code in the right directory, it works:

   
Reply
#7
OfnutsOtherwise, if you put you code in the right directory, it works:

Thanks! Now it seems to work, however, when i run this script got window with warnings, so question - is still something wrong?


Attached Files Thumbnail(s)
   
Reply
#8
These warnings are nothing to worry about (I also have them...on Linux).

What you can watch for in that window is Python syntax errors (or Python errors in general) especially if your plugin doesn't appear in the menu (this usually means it crashed before it could register). The output of Python print statements should also appear there and for debugging they are a bit more practical than gimp.message().
Reply


Forum Jump: