Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with plugin
#1
Hello!
My first attempt in phyton, and... plugin doesn't register. Huh Suspect fault is something very basic... Sad
Can somebody help, please?
Many  thanks!


Attached Files
.zip   group-text2path.zip (Size: 1,005 bytes / Downloads: 303)
Reply
#2
(10-10-2019, 05:33 PM)carmen Wrote: Hello!
My first attempt in phyton, and... plugin doesn't register. Huh Suspect fault is something very basic... Sad
Can somebody help, please?
Many  thanks!

First thing to do is to run your script outside of Gimp. This weeds out the worst mistakes:

Code:
22:17:31 @ python/ : >python group-text2path.py
  File "group-text2path.py", line 25
    path = pdb.gimp-vectors-new-from-text-layer(image,textLayer)
                                   ^
SyntaxError: invalid syntax

So, pitfall #1: the doc for Python is a somewhat verbatim copy of the Scheme doc. But if in Scheme you can have symbols-with-dashes, these are not allowed in Python (undistinguishable from a subtraction). So in the Python API, symbols-with-dashes are really symbols_with_underscores.  Use the Apply button in the PDB browser to get a Python-acceptable version of the call copied to the Python console.


Other problems:
  • you are using image is a function but you didn't pass it as a parameter
  • pdb.gimp_image_add_vectors(...) doesn't return anything. So to make the path visible, just use yourpath variable: pdb.gimp_item_set_visible(path,TRUE)
Once you have done that, it works, congratulations!
Reply
#3
Ofnuts--First: many, many thanks! Following your kind explanations, I have got the plugin installed and running. Maybe tomorrow I can post an example of its use (small fonts in maps / 'single path' fonts...)
Now, you say
Quote:Use the Apply button in the PDB browser to get a Python-acceptable version of the call copied to the Python console.
Well--although I have got Linux installed in an old laptop (unopened, alas! for months) I work chiefly in Win7, and my procedures browser doesn't include any gimp_..., but only gimp-... entries. I can only hope that a substitution of -/_ will cover most cases, it's one of those instance where I miss a cheat sheat!
Just discovered that the Apply button appears when one calls the PDB browser with phyton console opened.

New hitch: editing

Code:
import sys
sys.stderr = open('G:/Tests/Gimp_plug/python-fu-output.txt','a')
sys.stdout=sys.stderr # So that they both go to the same file
to

Code:
import sys
sys.stderr = open(os.path.devnull,'a')
made the plugin unaloadable:

Code:
Traceback (most recent call last):
  File "G:\GimpResources\plug-ins\group-text2path.py", line 15, in <module>
    sys.stderr = open(os.path.devnull,'a')
NameError: name 'os' is not defined
Is there an alternative, or just comment out the call to traceback for normal use?
Thanks, gracias, merci...
Reply
#4
(10-10-2019, 10:03 PM)carmen Wrote: Ofnuts--First: many, many thanks! Following your kind explanations, I have got the plugin installed and running. Maybe tomorrow I can post an example of its use (small fonts in maps / 'single path' fonts...)
Now, you say
Quote:Use the Apply button in the PDB browser to get a Python-acceptable version of the call copied to the Python console.
Well--although I have got Linux installed in an old laptop (unopened, alas! for months) I work chiefly in Win7, and my procedures browser doesn't include any gimp_..., but only gimp-... entries. I can only hope that a substitution of -/_ will cover most cases, it's one of those instance where I miss a cheat sheat!
Just discovered that the Apply button appears when one calls the PDB browser with phyton console opened.
The substitution works in all cases. The PDB browser is you reference because it contains all the help for the plugins you installed, assuming the other put relevant strings in the registration data.

(10-10-2019, 10:03 PM)carmen Wrote: New hitch: editing

Code:
import sys
sys.stderr = open('G:/Tests/Gimp_plug/python-fu-output.txt','a')
sys.stdout=sys.stderr # So that they both go to the same file
to

Code:
import sys
sys.stderr = open(os.path.devnull,'a')
made the plugin unaloadable:

Code:
Traceback (most recent call last):
  File "G:\GimpResources\plug-ins\group-text2path.py", line 15, in <module>
    sys.stderr = open(os.path.devnull,'a')
NameError: name 'os' is not defined
Is there an alternative, or just comment out the call to traceback for normal use?
Thanks, gracias, merci...

You have to do import os before you can use os.

Personallu, I start my scripts with:

Code:
debug='OFN_DEBUG' in os.environ

def trace(s):
    if debug:
        print s

And I use the  trace() instead of print in the code. trace() only prints something if the variable OFN_DEBUG is set in the environment, and this variable is set automatically in the terminal that is associated with my code editor.
Reply
#5
Photo 
Interesting! Now I understand better the beginnings of your plugins--I need some kind of template to launch from, but can use only the parts I understand more or less. If I do some more phyton coding (being also an user of calibre and sigil) I may check (someday) if notepad++ can do something of the sort.

And, as I threatened, 2 examples of what I want the plugin for.
   
1. In this map I have used font Almendra Display for the text, all in it's own group. The font itself renders almost transparent in Gimp (reported bug, affecting all small/fine fonts: Bernard Mode, Architect..) so  *I did a group_text2path, and stroked the result at line 1px in a new transparent layer*. Voilá!
2. As the symbols are also text, all save one taken from webdings (although all entered as Times New Roman) they both platform-dependant and subject to sudden change by windows update: so, another global conversion to path for backup.
   
Here, I duplicated the text layer group in 1, toggled visibility for the original, and on the copy made a group_changefont (thanks again, Ofnuts!) to 1CamBam_Stick_5: which, being a 'wire' font, renders in Gimp only as dots for o and d (the only closed paths in the whole text). Repeated *...*, made the group layer invisible, and behold!
Of course, it needs some changes: seeing the result, one would decrease letter-spacing and increase line-height, although I didn't bother...
To Do: plugin to change the whole font-style in the group in one fell swoop...  Wink
Reply


Forum Jump: