如何在Gimp python脚本中将信息输出到控制台?

Ara*_*lox 8 python console gimp gimpfu

我刚刚开始学习使用Python编写Gimp脚本,并且想知道如何将文本输出到控制台?我在Windows 7上使用的是2.7.5版.

我尝试了print函数,但它没有向python-fu控制台或使用Gimp启动的开发控制台写任何东西.有没有我应该用来做这个功能?或者这是2.7.5版本的问题?我发现了一些"gimp-message",但这似乎与Scheme一起使用的函数(Script-fu)

谢谢!

(也在这里发布了一个帖子)

Mas*_*llo 9

我们可以重定向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中(所以一般用户除非你真的告诉他们在哪里看,否则不会看到任何内容) .