I've just started learning about Gimp scripting using Python, and was wondering, how do I output text to the console?
I am using version 2.7.5 on Windows 7.
I tried the print function, but it does not write anything to the python-fu console or the dev console that launches with Gimp.
Is there a function I should use to do this? or is this a problem with the 2.7.5 release?
I found a few mentions of "gimp-message" but that seems to be a function used with Scheme (Script-fu)
Thanks!
(also posted as a thread here)
Use:
pdb.gimp_message('This is displayed as a message')
However... this shows in the Error console if the console window is up, else in a message dialog with an OK button, waiting for user acknowledgment. So you can really use it only once or twice in the script...
There is also
pdb.gimp_progress_set_text('This goes to the status bar')
That goes to the status bar (IIRC) and to the plugin progress dialog, if any, but is rather temporary.
You can also use plain print statements for debug purposes. On Linux their output shows up in the terminal from which you started Gimp, and on Windows they may appear in gimp-console if you started Gimp that way (so the general user won't see anything unless you really tell them where to look).
We can redirect stdout and stderr.
#!/usr/bin/env python
# coding: iso-8859-1
from gimpfu import *
import sys
sys.stderr = open( 'c:\\temp\\gimpstderr.txt', 'w')
sys.stdout = open( 'c:\\temp\\gimpstdout.txt', 'w')
def MyUsefulFilter(img, drw):
# these print redirected to gimpstdout.txt
print 'hello world'
print img
print drw
# this error redirected to gimpstderr.txt
x = 0
y = 1/x
pdb.gimp_image_undo_group_start(img)
# useful code here
pdb.gimp_image_undo_group_end(img)
register(
"useful_filter",
"very useful indeed",
"",
"MF",
"GPL",
"2013",
"<Image>/Filters/Photo/Useful Filter",
"RGB*",
[],
[],
MyUsefulFilter)
main()
Printing froma python script will just print to GIMP`s stdout channel - it is possible that in Windows you have to start GIMP itself from the command line, instead of starting it from the menu.