在windows上用python编写gimp插件如何调试?输出在哪里?

2024-10-01 13:39:37 发布

您现在位置:Python中文网/ 问答频道 /正文

大量编辑了一些新信息(和悬赏)

我试图在python中为gimp创建一个插件。(在windows上) 这个页面http://gimpbook.com/scripting/notes.html建议从shell运行它,或者查看~/.xsession错误

都没用。 我可以从命令shell运行它,就像

gimp-2.8.exe -c --verbose ## (as suggested by http://gimpchat.com/viewtopic.php?f=9&t=751 )

这会导致输出来自“pdb.gimp_消息(……)”去终点站。在

但是!!!这只在一切按预期运行的情况下有效,我在崩溃时没有得到任何输出。在

我试过打印报表,但没用。在

另一个人也有类似的问题,但讨论偏离了方向。 Plugins usually don't work, how do I debug?


在某些地方,我看到了在pythonfu控制台中运行它的建议。在

这让我一无所获。我需要注释掉import gimpfu,因为它会引起错误,而且我不能让gtk工作。在


我目前的问题是,即使插件注册并显示在菜单上,当出现一些错误并且它的行为不符合预期时,我不知道从哪里开始寻找提示。 (我尝试过在各种上下文中单击,w-w/o selection,w/o image。)在

我能够从http://gimpbook.com/scripting/复制并执行示例插件 我得到了,正在工作,但是当我所做的更改破坏了某些东西时,我不知道是什么,并且一行一行地改变现有程序是乏味的(每次都必须关闭并重新启动gimp)


所以总结一下-

1-我可以在不重启gimp的情况下刷新插件吗?(所以至少我的慢变形会更快)

2-我可以从python fu shell运行插件吗。(而不是仅仅导入它们以确保它们解析。)

3-是否有我丢失的错误日志,或类似的东西?在

4-有没有办法在windows上从shell运行gimp来查看输出?(在cygwin(或virtualbox..)下我会更好吗?在

5-我还没有找到如何将winpdb连接到现有进程。如何将它连接到运行在gimp中的python进程?在

谢谢


Tags: com插件信息http编辑进程windows错误
3条回答

我是python的新手,但我想先对winpdb大声疾呼,然后再对这个将winpdb集成到GIMP的评论发表意见。 同样的过程也适用于libreoffice4。在

如果允许我发泄一下的话,我对visualbasic有一定的经验,或多或少是在最糟糕的水平上,但几年前,当微软威胁要放弃VB而改用Mac时,我决定进入OpenOffice。我不想说VB在OpenOffice中是繁重的,但是缺少任何类似IDE的东西是乏味的。现在,有了winpdb,我再也不会回头了。从现在开始就是Python了,宝贝。在

采取的步骤:

正如上面Omid所建议的,我首先让winpdb用完GIMP(相对来说是无痛的)。在

我将rpdb2.py文件复制到C:\Program Files\LibreOffice 4\Program\python-core-3.3.3\lib\site packages\rpdb2.py。(胜利7,图书馆4.4.03)

我编辑了地狱世界.pyC:\Program Files\LibreOffice 4\share\Scripts\python目录中的文件(保存在WinPDb中_地狱世界.py到同一目录)。在

# HelloWorld python script for the scripting framework
# This file is part of the LibreOffice project.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. blah, blah, blah ...

import rpdb2
#rpdb2.start_embedded_debugger("Your Password Here")    # << DON'T start debugger here.
    # It only gets you lost in the LO python wrapper when debugging.

def HelloWorldPython( ):
    """Prints the string 'Hello World(in Python)' into the current document"""

    # start debugger INSIDE function, where it will be called from LO Macros   Duh!!
    rpdb2.start_embedded_debugger("YourPasswordHere") 

    #get the doc from the scripting context which is made available to all scripts
    desktop = XSCRIPTCONTEXT.getDesktop() 
    #... etc., see HelloWorld.py

WinPDb\u HelloWorld出现在宏选择器的LibreOffice宏下(有关详细信息,请参见https://wiki.openoffice.org/wiki/Python_as_a_macro_language)。在

(无法以来宾身份向您显示图片)

1- can i refresh a plugin without restarting gimp ? (so at least my slow-morph will be faster )

添加脚本或更改register()时必须重新启动GIMP。 更改脚本的其他部分时无需重新启动它作为单独的进程运行,每次都将从磁盘重新读取。在

有用来源: http://gimpbook.com/scripting/notes.html

2- can i run plug-ins from the python-fu shell. (as opposed to just importing them to make sure they parse.)

是的,您可以通过以下方式访问已注册的插件python-fu控制台:

>>> pdb.name_of_registerd_plug-in

可以这样称呼它:

^{pr2}$

同样在python-fu对话框控制台中,您可以单击Browse ..选项并找到您注册的插件, 然后单击Apply,将其导入python-fu控制台。在

有用来源: http://registry.gimp.org/node/28434

3- is there an error-log i am missing, or something to that effect?

要进行日志记录,可以定义如下函数:

def gimp_log(text):
    pdb.gimp_message(text)

并在您的代码中随时使用它。在

要查看日志,在gimp程序中,在Windows菜单中打开Error ConsolefromDockable Dialogs,否则每次创建日志时都会弹出一个消息框。在

您还可以将stdinstdout重定向到一个文件:

import sys
sys.stderr = open('er.txt', 'a')
sys.stdout = open('log.txt', 'a')

执行此操作时,exceptions将转到err.txt,所有打印输出都将转到log.txt 请注意,使用a选项而不是w打开文件来保存日志文件。在

有用的来源:

How do I output info to the console in a Gimp python script?

http://www.exp-media.com/content/extending-gimp-python-python-fu-plugins-part-2

4- is there a way to run gimp on windows from a shell to see output ? (am i better off under cygwin (or virtualbox.. ))?

我有一些错误,但可以再试一次。。。在

5- i haven't yet looked up how to connect winpdb to an existing process. how would i go about connecting it to a python process that runs inside gimp?

首先安装winpdb,同时安装wxPython(Winpdb GUI依赖于wxPython)

注意,Gimp有自己的python解释器,您可能想将winpdb安装到默认的python解释器或gimp python解释器。在

如果将winpdb安装到默认的python解释器,则需要将rpdb2.py安装的文件复制到gimp python解释器路径的..\Lib\site-packages。在

之后,您应该能够从gimp的Python-Fu控制台导入pdb2模块:

GIMP 2.8.10 Python Console
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)]
>>> import rpdb2
>>>

现在在插件代码中,例如在main函数中添加以下代码:

import rpdb2 # may be included out side of function.
rpdb2.start_embedded_debugger("pass") # a password that will asked by winpdb

接下来,转到gimp并运行您的python插件,当您运行插件时,它将运行,然后等待到达上面的代码。在

现在要打开Winpdb GUI,请转到..\PythonXX\Scripts,然后运行winpdb_.pyw。在

(请注意,使用Winpdb进行远程调试时,请确保途中的任何firewall已打开TCP端口51000。请注意,如果使用端口51000,Winpdb将搜索51000和51023之间的替代端口。)

然后在Winpdb GUI中的File菜单中选择attach,并给pass作为密码,然后您可以在该列表中看到您的插件脚本,选择它并一步一步开始调试。在

debug python gimp plugin with Winpdb

有用资源: Installing PyGIMP on Windows

有用的来源:

http://wiki.gimp.org/index.php/Hacking:Plugins

http://www.gimp.org/docs/python/index.html

http://wiki.elvanor.net/index.php/GIMP_Scripting

http://www.exp-media.com/gimp-python-tutorial

http://coderazzi.net/python/gimp/pythonfu.html

http://www.ibm.com/developerworks/opensource/library/os-autogimp/os-autogimp-pdf.pdf

How do I output info to the console in a Gimp python script?所述

添加

import sys
sys.stderr = open( 'c:\\temp\\gimpstderr.txt', 'w') 
sys.stdout = open( 'c:\\temp\\gimpstdout.txt', 'w')

在插件文件的开头。在

相关问题 更多 >