As a learning exercise I have created a Python script which takes a plug-in template, allows changes from the keyboard, and then saves it as a new blank plug-in.
I can use PF_STRING to enter one item of data (although it is not a pretty sight!), but it would seem that I can only use a PF_STRING once in a program.
Is there an elegant way that I can enter multiple items into variables, such as Name, Description, etc. via the keyboard in response to screen prompts?
However, the GIMP Python script I have written works perfectly from the terminal, but I am curious to know why it can't find my template file (tmplt.py) when i run it in GIMP. I have tried putting every level of the path, without success.
As usual it could be something very simple which I am overlooking!
The attached .zip file contains the plug-in and the template file.
Your continued assistance is always appreciated. Perhaps one day I will be able to spot the cause of problems myself.
Still flogging a dead horse, in the hope is that I may yet learn something!
Background: I am using the GIMP 2.10.25 Appimage, extracted, thanks to Rich's help.
When I run my "new_template" from the terminal it works. When I add "workPath = os.getcwd()" it shows the working path as "/home/david/GIMP-2.10.21/squashfs-root".
Run directly from GIMP the working path is "/home/david" which is obviously incorrect. I can prove this by changing my "file open" to the full path and it then works correctly.
If I use "os.path.abspath("tmplt.py")" from GIMP it gives me a path of "/home/david/tmplt.py" which is also incorrect.
Whilst I can get it working, I would like to be able to code it so that it is machine/OS independant, but also understand why the problem occurs.
One of the difficulties, when scouring the internet, is that much of the Python information is not clear as to what version it refers.
I suspect that this comes from the virtual filesystem used by AppImage (equivalent problems with snap and flatpak) (hence your squashfs-rootn because AFAIK AppImage uses SquashFS). The gimp object has a bunch of calls to determine directories. In the gimp console, try:
Code:
➤> [x for x in dir(gimp) if 'directory' in x]
['data_directory', 'directory', 'locale_directory', 'plug_in_directory', 'sysconf_directory', 'user_directory']
So
directory is the user Profile (~/.config/GIMP/2.10)
data_directory is the add-ons directory (brushes, etc... and also scripts) (/usr/share/gimp/2.0)
plug_in_directory is the plugins directory (/usr/lib/gimp/2.0)
sysconf_directory is some initial values for the user profiles (/etc/gimp/2.0/)
user_directory is a function that takes an integer, depending on integer you get:
0: ~/Desktop
1: ~/Documents
2: ~/Downloads
3: ~/Music
4: ~/Pictures
5: ~/Public
6: ~/Templates
7: ~/Videos
so for instance gimp.user_directory(4) is where you expect the user to keep images. These directories have equivalents across Windows, OSX, and the various Linux desktops.