Inkscape CLI FileRevert 在 1.1 或 1.2 中不起作用,试图刷新 Inkscape GUI

问题描述 投票:0回答:3

我正在开发一个使用 inkscape 来操作 SVG 的动画 SVG 工具,我需要更新 inkscape 以显示动画 SVG 的选定状态,以便让用户进行更改(它是外部工具而不是插件)。

例如:一个矩形从x:100到x:300,当矩形在x:200时用户暂停动画,然后工具用x:200保存SVG状态,唯一的问题是inkscape没有刷新,所以我需要关闭并打开 inkscape,或者手动转到文件>还原。

我一直在调查,我发现有一个名为 FileRevert 的动词(在 1.2 中删除动词之前),我尝试使用 1.1 版并使用 inkscape GUI 打开此命令:

inkscape --verb FileRevert test.svg

这是命令的完整输出:(最后的完整日志)

user@user:~/Desktop$ ./ink2.AppImage --verb FileRevert test.svg

WARNING: ignoring verb FileRevert - GUI required for this verb.

** (org.inkscape.Inkscape:6946): CRITICAL **: 08:40:38.988: static void Inkscape::FileVerb::perform(SPAction*, void*): assertion 'ensure_desktop_valid(action)' failed

所以错误似乎是没有检测到 GUI,idk 如果我必须告诉 cli GUI 在哪里或从 GUI 打开 inkscape,但我试过了,终端被阻塞,直到你关闭 inkscape。

然后我尝试使用 inkscape 1.2 动作,因为文档说所有动词都可以作为动作使用:

但是 --action-list 中没有 FileRevert 操作,也没有关于 1.2 发行说明中任何 FileRevert 弃用的信息,所以很难猜测发生了什么。

这是使用操作尝试 FileRevert 的输出:(最后的完整日志)

user@user:~/Desktop$ ./ink.AppImage --actions="FileRevert" test.svg

InkscapeApplication::parse_actions: could not find action for: FileRevert

所以它似乎无法找到 FileRevert 操作,可能这意味着它不受支持或弃用。

我使用 linux mint 以防万一。

欢迎任何帮助,或解决我的问题的任何替代解决方案...atm 我正在考虑如此糟糕的替代方案,例如每次您想要刷新它时自动关闭并重新打开 inkscape,或者选择 inkscape 窗口并触发热键来恢复文件。

谢谢!

Full log 1.1 Verb try:

  user@user:~/Desktop$ ./ink2.AppImage --verb FileRevert test.svg
        Setting _INKSCAPE_GC=disable as a workaround for broken libgc
        Gtk-Message: 08:40:38.030: Failed to load module "xapp-gtk3-module"
        
        ** (org.inkscape.Inkscape:6946): WARNING **: 08:40:38.964: <svg:rect id="">: CSS Style property: "stroke-width" with default value (1) not needed.
        
        ** (org.inkscape.Inkscape:6946): WARNING **: 08:40:38.964: <svg:rect id="rect786">: CSS Style property: "stroke-width" with default value (1) not needed.
        
        ** (org.inkscape.Inkscape:6946): WARNING **: 08:40:38.964: <svg:rect id="rect786">: CSS Style property: "stroke-width" with default value (1) not needed.
    
        WARNING: ignoring verb FileRevert - GUI required for this verb.
        
        ** (org.inkscape.Inkscape:6946): CRITICAL **: 08:40:38.988: static void Inkscape::FileVerb::perform(SPAction*, void*): assertion 'ensure_desktop_valid(action)' failed

完整日志1.2动作尝试:

user@user:~/Desktop$ ./ink.AppImage --actions="FileRevert" test.svg
    Setting _INKSCAPE_GC=disable as a workaround for broken libgc
    Gtk-Message: 08:49:36.363: Failed to load module "xapp-gtk3-module"
    InkscapeApplication::parse_actions: could not find action for: FileRevert
    
    ** (org.inkscape.Inkscape:7139): WARNING **: 08:49:37.377: <svg:rect id="">: CSS Style property: "stroke-width" with default value (1) not needed.
    
    ** (org.inkscape.Inkscape:7139): WARNING **: 08:49:37.377: <svg:rect id="rect786">: CSS Style property: "stroke-width" with default value (1) not needed.
    
    ** (org.inkscape.Inkscape:7139): WARNING **: 08:49:37.378: <svg:rect id="rect786">: CSS Style property: "stroke-width" with default value (1) not needed.

编辑:在 Inkscape 中工作和更新的工具演示: https://www.youtube.com/watch?v=fDAIVKd19YU

svg inkscape
3个回答
2
投票

Inkscape 1.2.x 及以上版本似乎没有实现file_revert 动作。看到问题here.

但是,我建议改用 dbus。这是一个关于如何在运行 inkscape 时使用 dbus 恢复文档的示例:

gdbus call --session --dest org.inkscape.Inkscape --object-path /org/inkscape/Inkscape/window/1 --method org.gtk.Actions.Activate document-revert [] {}

要获取可以通过 dbus 调用的操作列表,请运行以下命令:

gdbus call --session --dest org.inkscape.Inkscape --object-path /org/inkscape/Inkscape/window/1 --method org.gtk.Actions.List

除了终端,您还可以在 C++、Python 等代码上使用 dbus。有关绑定列表,请参阅:here.


1
投票

对于 Inkscape 1.1.x,使用

dbus
:

gdbus call --session --dest org.inkscape --object-path /org/inkscape/desktop_0 --method org.inkscape.document.call_verb "FileRevert"

0
投票

OP 在这里,如果像我一样你只是想从脚本或外部程序引用 inkscape UI,在 inkscape 1.3 上会有一个“file-rebase”inkscape 动作是为了这个目的而做的,不需要使用 dbus,允许我们可以在 windows、linux 和 mac 上使用它,我们还可以定位当前打开的窗口,感谢 Javier 所做的所有工作和 inkscape 社区。 (您可以直接从终端执行此操作,有两个终端,一个用于启动 shell,另一个用于向当前窗口发送命令)我让它在 electron.js 应用程序中工作,如下所示:

首先我们存储子进程:

this.inkscapeProcess = spawn(`${inkscapePath}`, ['-q', '--shell'])

--q 用于告诉它以当前打开的 inkscape 窗口为目标 --shell 用于告诉它保持 shell 模式,这样我们就可以发送将要立即执行的操作(之前它需要一秒钟或更长时间,因为它每次都必须等待启动进程)

现在我们可以通过标准输入发送动作:

 this.inkscapeProcess.stdin.write(`selection-set-backup; file-rebase; selection-restore-backup; selection-empty-backup
    `)

(请注意,字符串末尾的换行符是触发命令所必需的,它有点模拟回车键)

这四个动作不仅使用 filerebase 刷新 inkscape UI,而且还恢复选择(例如,如果您选择了路径的 10 个节点或一个矩形和一个圆)

您还可以触发任何其他 Inkscape 操作

正如我所说,这仅适用于 inkscape 1.3,目前尚未发布,因此您需要转到 gitlab repo 并下载 master

© www.soinside.com 2019 - 2024. All rights reserved.