Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keyboard entries into script
#1
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?
Reply
#2
PF_TEXT gives you a multi-line text entry.
Reply
#3
Thanks Ofnuts,

PF_TEXT will work, but it is even more ugly as an input method than PF_STRING!!!
Reply
#4
(10-08-2021, 09:28 AM)david Wrote: Thanks Ofnuts,

PF_TEXT will work, but it is even more ugly as an input method than PF_STRING!!!

OTOH I wonder why you need to use Gimp's plugin interface to write more plugins. Can't you do that in native Python outside of Gimp?
Reply
#5
Ofnuts,

I think native Python is the correct answer.

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.

david.


Attached Files
.zip   new_template.zip (Size: 2.18 KB / Downloads: 196)
Reply
#6
In something that works, add
Code:
import sys
gimp.message("%r" % sys.path)
That will show you the directories from which you can add something. You can alter the path before doing an import:
Code:
sys.path=['/some/additional/directory']+sys.path
import something # from /some/additional/directory, hopefully
You can also add the current directory:
Code:
sys.path=['.']+sys.path
import something # from current directory, hopefully
Reply
#7
Ofnuts,

Thanks. Your reply allowed me to understand the problem.

When trying to learn something the "why" is always more important than the solution!
Reply
#8
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.
Reply
#9
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.
Reply


Forum Jump: