我正在为Inkscape开发一个插件。一些版本:
安装位置:
myplugin.inx
,myplugin.py
,MyPlugin.exe
我已经制作了一个插件,出于开发原因,该插件目前可以正常使用。
最重要的是,它可以运行,当我从MonoDevelop或内置的exe本身运行时(既将生成的.dll等在同一位置,也可以仅将exe复制到其他位置) )。
我使用SugarPillStudio's python script(略作编辑的版本)运行.exe文件。但是,当我通过调用扩展名运行该python脚本时,不会启动.exe。 Inkscape会闪烁显示“ MyPlugin正在启动...”的消息,并以打开后的速度将其关闭。
我知道python脚本有效,因为我可以将调试行打印到桌面上的.log文件中。我知道.exe不会启动,因为我也将它写入同一.log文件的行,这是在调用main()时的第一件事。当我(成功)运行.exe时,它确实会打印到文件中,而当我运行扩展名时,它不会。
这使我相信调用.exe的python脚本存在问题。有帮助吗?
Python脚本:
#!/usr/bin/env python
'''
sugarpillstudios.com/wp/?p=142
'''
import os, sys, subprocess, datetime
f=open("C:\Users\Diamundo\Documents\plugin.log", "a+")
f.write("[PYT] %s Python script called at: %s.\n" % (datetime.datetime.now().isoformat(), os.getcwd() ) )
argv = []
for arg in sys.argv[:]:
if arg.startswith("--executable="):
executable = arg.split("=")[1]
else:
argv.append(arg)
argv[0] = executable
f.write("[PYT] %s %s\n" % ( datetime.datetime.now().isoformat(), executable ) )
process = subprocess.Popen(argv,shell=False,stdout=subprocess.PIPE)
print process.communicate()[0]
Plugin.inx:
<inkscape-extension>
<name>MyPlugin</name>
<id>name.space.plugin.main</id>
<param name="executable" type="string" gui-hidden="true">MyPlugin.exe</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu _name="MyPlugin"/>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">myplugin.py</command>
</script>
</inkscape-extension>
额外的Monodevelop版本:
Runtime:
Microsoft .NET 4.0.30319.42000
GTK+ 2.24.26 (Light theme)
GTK# 2.12.45
NuGet
Version: 4.3.1.4445
.NET Core
Runtime: C:\Program Files\dotnet\dotnet.exe
Runtime Versions:
2.0.9
2.0.5
SDK: C:\Program Files\dotnet\sdk\2.1.202\Sdks
SDK Versions:
2.1.202
2.1.4
MSBuild SDKs: Not installed
答案 0 :(得分:0)
Inkscape使用了它附带的Python 2.7,除非您在设置文件中进行了不同的设置(手动编辑)。
如果要编写Inkscape扩展名,可以通过以下方法了解如何做:
答案 1 :(得分:0)
基于pathops.py文件(由Moini中的her answer链接),我想出了以下文件。
它使用inkex.py(source on GitLab)库来声明Inkscape Effect
。 Effect
类使用OptionParser
库来解析默认的给定参数(例如,--id=$$
用于选定的节点,其中$$
是XML节点的“ id”标记的值)。通过添加自定义executable
选项,我们还可以对此进行解析。
OptionParser
完成解析后,值将在self.options
中可见,即我们的可执行文件现在位于self.options.executable
中(由于action="store"
和{{1 }}参数。
此外,可以在dest="executable"
中找到Inkscape创建的临时SVG文件。
如前所述,Inkscape创建一个临时文件,其中SVG的内容处于当前状态。您(r插件)进行的所有编辑均应不保存回该文件,但应返回给Inkscape本身-这是self.svg_file
类的前提:它编辑SVG并将修改返回给Inkscape。 Further reading here.
相反,在您的插件中,您应该( readonly )打开文件,读取其内容,然后进行编辑。完成编辑后,将整个SVG写入命令行。
然后,行Effect
将获取您插件的输出和错误输出。 这些用于将信息返回给Inkscape。
out, err = process.communicate(None)
数组的结构并不重要,除了可执行文件应作为第一个元素出现的事实以外。所有其他数组元素可以是任何顺序的任何东西,我刚刚在每个ID中添加了cmd
,因为这是Inkscape所使用的方式,并且它看起来就像没有Python中间件一样。我放在最后的'--id=$$'
也是一样,Inkscape在其参数中也做同样的事情-为了清楚起见,您也可以从中制作self.svg_file
。
'--file='+self.svg_file