GIMP Python 和网络套接字

GIMP Python and websockets

我广泛使用了 GIMP 2 和 WebSockets(在 java 和 js 中),但我是 Python 的新手。

我想在我的 gimp 插件中使用 websocket 客户端,所以我自己安装了 Python 2.7.14(pip 附带),并且我在上面找到了 运行 安装说明websocket 实现:https://github.com/websocket-client/websocket-client

我看到它依赖于'six'和'backports.ssl_match_hostname',所以我用pip安装了两个,已经安装了六个,并更新了backports。

我的插件如下:

#!/usr/bin/env python

from gimpfu import *
import websocket

def python_pytest(img, layer) :
    # Actual plug-in code will go here
    ws = websocket.WebSocket()
    ws.connect("ws://example.com/websocket", http_proxy_host="proxy_host_name", http_proxy_port=3128)
    return

register(
    "python_fu_pytest", #Name so other scripts can find us
    "Collaborative Editing", #Short Desc
    "WebSocket based collaborative editing", #Long description
    "Jonathan Crowder", #Author
    "Open Source", #Copyright Holder
    "2017", #Copyright Date
    "NetCanvas", #Plugin name in menus
    "*", #Image types we can handle
    [], #Params shown to user
    [], #Return values
    python_pytest, #Main function
    menu="<Image>/NetCanvas") #Where to show in menus
main()

如果我去掉 websocket 相关的代码,它似乎工作得很好,但是我在上面的代码中遇到了这个错误:

(gimp-2.8.exe:5508): LibGimpBase-WARNING **: gimp-2.8.exe: gimp_wire_read(): error
Querying plug-in: 'C:\Users\Jonathan\.gimp-2.8\plug-ins\netcanvas.py'

(gimp-2.8.exe:5508): LibGimpBase-WARNING **: gimp-2.8.exe: gimp_wire_read(): error

我不是调试的狂热爱好者,但没有足够的信息让我找出问题所在。我使用命令得到了输出:

gimp-2.8 --verbose --console-messages

我做错了什么? gimp python 插件不能读取我安装的库吗?有没有办法从 gimp 中获取更多信息?我以为 --verbose 实际上是..好吧,冗长。

编辑- 澄清一下,这是我的全部日志,以防你认为我没有包括重要的调试信息..:[=​​16=]

INIT: gimp_load_config
Parsing 'C:\Users\Jonathan\.gimp-2.8\unitrc'
Parsing 'C:\Program Files\GIMP 2\etc\gimp.0\gimprc'
Parsing 'C:\Users\Jonathan\.gimp-2.8\gimprc'
gimp_composite: verbose=no
Processor instruction sets: +mmx +sse +sse2 -3dnow -altivec -vis
Adding theme 'Default' (C:\Program Files\GIMP 2\share\gimp.0\themes\Default)
Adding theme 'Small' (C:\Program Files\GIMP 2\share\gimp.0\themes\Small)
Writing 'C:\Users\Jonathan\.gimp-2.8\themerc'
Trying splash 'C:\Users\Jonathan\.gimp-2.8\gimp-splash.png' ... failed
Trying splash 'C:\Program Files\GIMP 2\share\gimp.0\images\gimp-splash.png' ..
. OK
INIT: gimp_initialize
INIT: gimp_real_initialize
INIT: gui_initialize_after_callback
INIT: gimp_restore
Parsing 'C:\Users\Jonathan\.gimp-2.8\parasiterc'
Loading 'brush factory' data
Loading 'dynamics factory' data
Loading 'pattern factory' data
Loading 'palette factory' data
Loading 'gradient factory' data
Loading fonts
Loading 'tool preset factory' data
Parsing 'C:\Users\Jonathan\.gimp-2.8\templaterc'
Parsing 'C:\Users\Jonathan\.gimp-2.8\modulerc'
Loading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libcolor-selector-c
myk.dll'
Unloading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libcolor-selector
-cmyk.dll'
Loading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libcolor-selector-w
ater.dll'
Unloading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libcolor-selector
-water.dll'
Loading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libcolor-selector-w
heel.dll'
Unloading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libcolor-selector
-wheel.dll'
Loading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libcontroller-dx-di
nput.dll'
Unloading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libcontroller-dx-
dinput.dll'
Loading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libdisplay-filter-c
olor-blind.dll'
Unloading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libdisplay-filter
-color-blind.dll'
Loading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libdisplay-filter-g
amma.dll'
Unloading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libdisplay-filter
-gamma.dll'
Loading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libdisplay-filter-h
igh-contrast.dll'
Unloading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libdisplay-filter
-high-contrast.dll'
Loading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libdisplay-filter-l
cms.dll'
Unloading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libdisplay-filter
-lcms.dll'
Loading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libdisplay-filter-p
roof.dll'
Unloading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libdisplay-filter
-proof.dll'
INIT: gui_restore_callback
clipboard: writable pixbuf format: image/png
clipboard: writable pixbuf format: image/bmp
clipboard: writable pixbuf format: image/x-bmp
clipboard: writable pixbuf format: image/x-MS-bmp
clipboard: writable pixbuf format: image/x-icon
clipboard: writable pixbuf format: image/x-ico
clipboard: writable pixbuf format: image/x-win-bitmap
clipboard: writable pixbuf format: image/tiff
clipboard: writable pixbuf format: image/jpeg
Parsing 'C:\Users\Jonathan\.gimp-2.8\sessionrc'
Parsing 'C:\Users\Jonathan\.gimp-2.8\dockrc'
Parsing 'C:\Users\Jonathan\.gimp-2.8\toolrc'
Parsing 'C:\Users\Jonathan\.gimp-2.8\contextrc'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-rect-select-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-ellipse-select-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-free-select-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-fuzzy-select-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-by-color-select-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-iscissors-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-foreground-select-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-vector-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-color-picker-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-zoom-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-measure-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-move-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-align-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-crop-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-rotate-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-scale-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-shear-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-perspective-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-flip-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-cage-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-text-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-bucket-fill-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-blend-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-pencil-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-paintbrush-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-eraser-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-airbrush-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-ink-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-clone-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-heal-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-perspective-clone-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-convolve-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-smudge-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-dodge-burn-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-desaturate-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-color-balance-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-hue-saturation-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-colorize-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-brightness-contrast-tool'

Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-threshold-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-levels-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-curves-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-posterize-tool'
Parsing 'C:\Users\Jonathan\.gimp-2.8\tool-options\gimp-gegl-tool'
INIT: gimp_real_restore
Parsing 'C:\Users\Jonathan\.gimp-2.8\pluginrc'
Querying plug-in: 'C:\Program Files\GIMP 2\lib\gimp.0\plug-ins\pyconsole.py'

(gimp-2.8.exe:5508): LibGimpBase-WARNING **: gimp-2.8.exe: gimp_wire_read(): err
or
Querying plug-in: 'C:\Users\Jonathan\.gimp-2.8\plug-ins\netcanvas.py'

(gimp-2.8.exe:5508): LibGimpBase-WARNING **: gimp-2.8.exe: gimp_wire_read(): err
or
Writing 'C:\Users\Jonathan\.gimp-2.8\pluginrc'
Starting extension: 'extension-script-fu'
INIT: gui_restore_after_callback
Parsing 'C:\Users\Jonathan\.gimp-2.8\menurc'
Parsing 'C:\Users\Jonathan\.gimp-2.8\devicerc'
Parsing 'C:\Users\Jonathan\.gimp-2.8\controllerrc'
Parsing 'C:\Users\Jonathan\.gimp-2.8\colorrc'
loading menu 'C:\Program Files\GIMP 2\share\gimp.0\menus\image-menu.xml' for /
image-menubar
Loading module 'C:\Program Files\GIMP 2\lib\gimp.0\modules\libdisplay-filter-l
cms.dll'
EXIT: gimp_exit
EXIT: gui_exit_callback
Writing 'C:\Users\Jonathan\.gimp-2.8\sessionrc'
Writing 'C:\Users\Jonathan\.gimp-2.8\dockrc'
Writing 'C:\Users\Jonathan\.gimp-2.8\colorrc'
Writing 'C:\Users\Jonathan\.gimp-2.8\menurc'
Writing 'C:\Users\Jonathan\.gimp-2.8\controllerrc'
Writing 'C:\Users\Jonathan\.gimp-2.8\toolrc'
EXIT: gimp_real_exit
Writing 'C:\Users\Jonathan\.gimp-2.8\templaterc'
Writing 'C:\Users\Jonathan\.gimp-2.8\parasiterc'
Writing 'C:\Users\Jonathan\.gimp-2.8\unitrc'
EXIT: gui_exit_after_callback
EXIT: app_exit_after_callback
(Type any character to close this window)

在 Windows 上,Gimp 带有自己的 Python 解释器,因此您要么必须:

  • 为该解释器实例安装包(恕我直言,最简单的解决方案)
  • 让 Gimp 使用其他解释器(向其中添加 gimpfu 模块和可能的其他...)(请参阅 Gimp 安装目录中的 lib/gimp/2.0/interpreters/pygimp.interp

一些提示可以调试 Gimp python 脚本 here