Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
using python scripts wiht gimp 2.10 flatpak
#1
Python 
Hi there,
I recently installed ubuntu 22.10 and gimp 2.10 via flatpak. I tried to create a script with python as I was used to on previous installations, but I cant get gimp to acknowledge my scripts. I checked the folders in the preference menu, I had to create the folder because it was not done by the installation for some reason.

here is the script of my .py file

Code:
:~/.config/GIMP/2.10/scripts$ cat clothfy.py
#!/usr/bin/python
import math
from gimpfu import *

have_gimp11 = gimp.major_version > 1 or \
          gimp.major_version == 1 and gimp.minor_version >= 1

def python_clothify(timg, tdrawable, bx=9, by=9,
            azimuth=135, elevation=45, depth=3):
    bx = 9 ; by = 9 ; azimuth = 135 ; elevation = 45 ; depth = 3
    width = tdrawable.width
    height = tdrawable.height
    img = gimp.image(width, height, RGB)
    layer_one = gimp.layer(img, "X Dots", width, height, RGB_IMAGE,
                   100, NORMAL_MODE)
    img.disable_undo()
    if have_gimp11:
        pdb.gimp_edit_fill(layer_one)
    else:
        pdb.gimp_edit_fill(img, layer_one)
    img.add_layer(layer_one, 0)
    pdb.plug_in_noisify(img, layer_one, 0, 0.7, 0.7, 0.7, 0.7)
    layer_two = layer_one.copy()
    layer_two.mode = MULTIPLY_MODE
    layer_two.name = "Y Dots"
    img.add_layer(layer_two, 0)
    pdb.plug_in_gauss_rle(img, layer_one, bx, 1, 0)
    pdb.plug_in_gauss_rle(img, layer_two, by, 0, 1)
    img.flatten()
    bump_layer = img.active_layer
    pdb.plug_in_c_astretch(img, bump_layer)
    pdb.plug_in_noisify(img, bump_layer, 0, 0.2, 0.2, 0.2, 0.2)
    pdb.plug_in_bump_map(img, tdrawable, bump_layer, azimuth,
                 elevation, depth, 0, 0, 0, 0, TRUE, FALSE, 0)
    gimp.delete(img)

register(
    "python_fu_clothify",
    "Make the specified layer look like it is printed on cloth",
    "Make the specified layer look like it is printed on cloth",
    "James Henstridge",
    "James Henstridge",
    "1997-1999",
    "<Image>/Filters/Artistic/Clothify",
    "RGB*, GRAY*",
    [
        (PF_INT, "x_blur", "X Blur", 9),
        (PF_INT, "y_blur", "Y Blur", 9),
        (PF_INT, "azimuth", "Azimuth", 135),
        (PF_INT, "elevation", "elevation", 45),
        (PF_INT, "depth", "Depth", 3)
    ],
    [],
    python_clothify)
main()

some ideas of troubleshooting I can think of :
- this example of python script is very old. Where could I find a more recent one ?
- flatpak is a kind of sandbox isn't it ? is there a complementary operation I should do for gimp to accept to read a .py file ?
- the first line of the code says /usr/bin/python . but my /usr/bin folder does not contain any python file or folder. It contains python3, python3.10, python3-config and other stuffs starting with python3. Is it an issue ?

Any idea someone ?
Reply
#2
The flatpak app is sandboxed, it has its own view of the file system. What it sees as /usr is actually in the flatpack tree, which is why you don't see some folders on your system. Other things to know about the flatpak version:
  • It cannot access files outside of your home tree.
  • It cannot use the real /tmp. This was a big problem for me since some apps share files with Gimp through /tmp.
  • It has its own copy of the "recent files" so if you want to upload files you just saved with Gimp, you will have to navigate your directory tree instead of reaching the file quickly through Recently used (but IIRC there is a workaround for that).

IIRC you can normally put your script/plugins in your own Gimp profile (~/.config/GIMP/2.10/ IIRC). If not you can add a folder in Preferences/Folders/Plug-ins and put your script there (hint: put some recognizable files in the folder before you pick it from Gimp, so you will know if you see a folder from the flatpak or a "real" folder).

Make sure that your script has the executable flag, and no syntax errors.

If you start Gimp from a terminal, Python errors will show  in the terminal. You can use a print '********************' at the beginning of the code to see if it is at least called and executed.

You can use script from my collection as examples (and steal all the code you want). Beware that some may use some tricks when registering several functions (I hate to repeat myself). Usually the smaller ones (check the ZIP size) are the simplest. In any case you can always ask.
Reply
#3
Some observations.

There is already a clothify but a script-fu For a flatpak buried in 
/var/lib/flatpak/app/org.gimp.GIMP/x86_64/stable/active/files/share/gimp/2.0/scripts/

The python version as posted gives an error on my installation.
Traceback (most recent call last):
  File "/home/rich/gimp-flat-plugin/clothify.py", line 5, in <module>
    have_gimp11 = gimp.major_version > 1 or \

    
but there is a python version here: 
https://gitlab.gnome.org/GNOME/gimp/-/tr...p/plug-ins

For any Gimp, especially flatpak, if you use it frequently and add resources, make an easy to find folder and add to the resource path.

   

Both scm and py working here, can't see any difference in results.

   

Edit:
Quote:I had to create the folder because it was not done by the installation for some reason.

I have come across this before, seems linked to having a Gimp user profile (~/.config/GIMP)  left over from an existing/old installation.

If you start the flatpak in a terminal flatpak run org.gimp.GIMP rather than from the menu you might get a clue from any error message.
Reply
#4
Hi, thanks for the responses.
What does IIRC stand for ?


In edit>preferences>folders, any of the path listed existed in my computer. If I try to create them or add a new path and put python files in it, it won't work.

(04-20-2023, 09:59 PM)Ofnuts Wrote: IIRC you can normally put your script/plugins in your own Gimp profile (~/.config/GIMP/2.10/ IIRC).

That was the solution all along ! I dont know why, but the files in this folder are taken into account, besides it is not part of the path listed in edit>preferences>folders.
Fun fact, when I make a syntax mistake, the output given by the gimp at startup clams that the file is in the folder listed in the gimp preferences:


Code:
jacques@france:~/.config/GIMP/2.10/plug-ins$ gedit python-test-error.py

jacques@france:~/.config/GIMP/2.10/plug-ins$ cat python-test-error.py
print "this code contains an error on line 2"
print 2+"three"

jacques@france:~/.config/GIMP/2.10/plug-ins$ gimpflatpak
Gtk-Message: 20:58:02.257: Failed to load module "atk-bridge"
Gtk-Message: 20:58:02.260: Failed to load module "canberra-gtk-module"
this code contains an error on line 2
Traceback (most recent call last):
  File "/home/jacques/.var/app/org.gimp.GIMP/config/GIMP/2.10/plug-ins/python-test-error.py", line 2, in <module>
    print 2+"three"
TypeError: unsupported operand type(s) for +: 'int' and 'str'
gimp-2.10: LibGimpBase-AVERTISSEMENT: gimp-2.10: gimp_wire_read(): error
*************python test**************
gimp-2.10: LibGimpBase-AVERTISSEMENT: gimp-2.10: gimp_wire_read(): error


rich Wrote:seems linked to having a Gimp user profile (~/.config/GIMP)  left over from an existing/old installation.
Yes, I installed the "normal" version of gimp before uninstalling it and install the flatpak version.

Long story short, it works, and it's good enough for me. But I am very puzzled by the way flatpak deals with path and folders.
thank you both Wink
Reply


Forum Jump: