[Solved] Python script calling GMIC, not recognized in Gimp AppImage


(Nicolas Beaudet) #1

Hello all,

I am using Gimp AppImage 2.10.8 ‘with plug-ins’ under Ubuntu 18.04 LTS. I am attempting to script a custom filter (GMIC.nb_Composants), hoping to manipulate the output layers later in GIMP.

The following .py is never recognized by my installation. Attempts to locate the py script in my menu system fails.

What am I doing wrong?

python script:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

#https://discuss.pixls.us/t/integrate-gmic-as-a-menu-in-gimp/10183
#from MareroQ
from gimpfu import *
from gimpenums import *

def python-fu_GMICComp(image, drawable):
        inLayersMode = 1 #GMIC input layers mode
        outMode = 1 #GMIC layers
        command = "nb_Composants"#"Mes composants"
        pdb.plug_in_gmic_qt(image, drawable, inLayersMode, outMode, command, run_mode=1)

register(
        "python-fu_GMICComp",	
        "Create RGB-CMYK-HSL Component Masks of Layer",
        "Nicolas Beaudet",
        "Nicolas Beaudet",
        "License ",
        "2018.12 PY",
        "GMICComp PY",
        "<Image>/MesScriptsMAP",
        "RGB*",
        [
                (PF_IMAGE, "inImage", "Image active", None),
                (PF_DRAWABLE, "inLayer", "Calque actif", None),
        ],
        [],
        python-fu_GMICComp,#  menu="<Image>/nbGMIC")
        
main()

(Mica) #2

What folder are you putting this script in?


(Carmelo Dr Raw) #3

I suspect the problem might be due to the hashbang you are using. Could you try to replace

#!/usr/bin/env python

by

#! python

and see if it works?


(Nicolas Beaudet) #4

This script resides along my other successful python scripts.


(Nicolas Beaudet) #5

I have replaced the line with your suggestion. No change in the behavior of the script.


(Carmelo Dr Raw) #6

Where exactly do you put the python script that fails to be loaded?


(Nicolas Beaudet) #7

This is the location of my script:

/media/nicolas/860Turnbull/Nicolas/maison/Images/Outils/MAP/GMICComp.py


(Carmelo Dr Raw) #8

@nbeaudet you might need to put your script under

$HOME/.local/config/GIMP-AppImage/plugins

Could you try and report back?

Thanks


(Nicolas Beaudet) #9

@Carmelo_DrRaw
I put the script under $HOME/.local/config/GIMP-AppImage/plugins and the result is the same as previously mentioned.

I did try also to put the script in $HOME/.config/GIMP-AppImage/2.10/plug-ins with the same result.

I made sure to have the script ‘executable’ , as per Linux standards.

I also noticed the name of the script flashing as GIMP is loading. Is that a good sign?

Thank you for looking in this matter.


(Carmelo Dr Raw) #10

I would say yes. And you are right, the correct path of the plugins folder is $HOME/.config/GIMP-AppImage/2.10/plug-ins.

Please post the full terminal output that you get when running the AppImage.


#11

Just try to execute the script in a terminal and the problem is obvious:

>python badGMIC.py 
File "badGMIC.py", line 9
    def python-fu_GMICComp(image, drawable):
            ^
SyntaxError: invalid syntax

You can’t have a - in a Python symbol…

You can take the habit to try to run your script at least once in a command prompt. If there are any big syntax problems they will show up there (indentation problems, unbalanced quotes/parentheses, encoding, etc…). No point trying to run in Gimp until you get:

Traceback (most recent call last):
File "badGMIC.py", line 6, in <module>
    from gimpfu import *
ImportError: No module named gimpfu

You can’t get any further in a command prompt since gimpfu is defined only when you run under Gimp, but when you get this the worst syntax problems have been fixed.

Since you are under Linux, start Gimp from a terminal, if there are “finer” syntax errors or runtime problems when the script is run for registration you will see them there.


(Nicolas Beaudet) #12

@Carmelo_DrRaw & @Ofnuts:
Thank you for looking in this matter.

I followed your instructions as per location of my GMICComp.py. Unfortunately, the script does not show up in my menus. The script works fine in the GIMP.Python console.

I agree to investigate messages while Gimp AppImage is loading. My only way, at this moment, to launch Gimp Appimage is by double clicking its file (GIMP_AppImage-release-2.10.8-withplugins-x86_64.AppImage). I have no idea how to launch ‘verbose style’ the AppImage. I am familiar with the FlatPak.Gimp version and can launch it ‘verbose style’. But unfortunately , FlatPak.Gimp does not include GMIC.

Hope to hear from you soon.


(Nicolas Beaudet) #13

Hello to all,

I have managed to launch GIMP.AppImage from the terminal with:

$ gimp --verbose

GIMP.AppImage is now verbose! So usefull!

Now with my ill GMICComp.py, the terminal answers with :

Querying plug-in: ‘/media/nicolas/860Turnbull/Nicolas/maison/Images/Outils/MAP/GMICComp.py’
Traceback (most recent call last):
File “/media/nicolas/860Turnbull/Nicolas/maison/Images/Outils/MAP/GMICComp.py”, line 16, in
register(
NameError: name ‘register’ is not defined

With this information, I can locate my (typing error) at line 16. How can ‘register’ be not defined when my successful .py scripts carry the same instruction?

Regards


#14

Carefully check you registration parameters. You are specifying the menu twice, if you use the menu= named parm, the other should just be the final menu label. A sample registration looks like this:

from gimpfu import *

def executedFunction(image,drawable):
    pdb.gimp_message("Hello, Gimpers!")
    
# Registration

register(
    "plugin-identifier-must-be-unique",
    "Plug-in summary for procedure browser and mouse-over in menus",
    '''
    Full Plug-in description
    
    This is the real plugin description that shows up in the procedure browser.
    It can contain complementary information to the auto-generated argument descriptions.
    ''',
    "Author's Name",
    "Copyright owner's name",
    "Copyright date",
    "String for menu label",
    "*", # Supported image types
    [ # Description of input arguments
        (PF_IMAGE, "image", "Label/description in auto-generated dialog and procedure browser", None),
        (PF_DRAWABLE, "drawable", "Label/description in auto-generated dialog and procedure browser", None),
    ], 
    [], # Descripton of return values
    executedFunction,
    menu="<Image>/Menubar Entry/Submenu/"
)

main()

Also did you fix the python-fu_GMICComp problem, including where it appears in the register() call?


(Nicolas Beaudet) #15

Hello to all,

I have managed to get the script shown in the menus, and it executes as expected.

My original script carried the instruction:

import gimpfu

that I had to replace with

from gimpfu import *

I dont understand the reason (?).

Any way you have been very helpful in solving my problem.

Thanks


#16

If you use import gimpfu, only gimpfu is added to the global name space, and things in gimpfu have to be accessed via gimpfu: gimpfu.gimp, gimpfu.pdb, etc…

If you use from gimpfu import * all symbols in gimpfu are added to the global name space and can be accessed directly: gimp, pdb.

It is usually recommended to use the import package form because it avoids possible name clashes when you import many packages. When the package has a long name you can use an alias: import longpackagename as lpn and then use the alias: lpn.someFunction().

The from form is also considered OK if you import a few selected symbols: from package import someFunction.

The blunt form from package import * is usually advised against, but for gimpfu this is of little consequence since most labels are “defined constants”, and prefixing every usage with gimpfu wouldn’t be very readable.