我们可以重定向stdout和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()
Run Code Online (Sandbox Code Playgroud)
小智 6
使用:
pdb.gimp_message('This is displayed as a message')
Run Code Online (Sandbox Code Playgroud)
但是......如果控制台窗口已启动,则会在错误控制台中显示,否则会在带有"确定"按钮的消息对话框中显示,等待用户确认.所以你可以在脚本中只使用一次或两次......
还有
pdb.gimp_progress_set_text('This goes to the status bar')
Run Code Online (Sandbox Code Playgroud)
这将转到状态栏(IIRC)和插件进度对话框(如果有),但这是暂时的.
您还可以使用普通打印语句进行调试.在Linux上,它们的输出显示在你启动Gimp的终端中,而在Windows上,如果你以这种方式启动Gimp,它们可能会出现在gimp-console中(所以一般用户除非你真的告诉他们在哪里看,否则不会看到任何内容) .