small fixes

This commit is contained in:
leyghisbb 2021-05-07 22:39:01 +02:00
parent e1e91ef731
commit 0758fbface
2 changed files with 21 additions and 9 deletions

View File

@ -5,6 +5,7 @@ import subprocess
import shutil import shutil
import os import os
import sys import sys
import warnings
""" """
Extension for InkScape 1.X Extension for InkScape 1.X
@ -14,7 +15,7 @@ Features
Author: Mario Voigt / FabLab Chemnitz Author: Mario Voigt / FabLab Chemnitz
Mail: mario.voigt@stadtfabrikanten.org Mail: mario.voigt@stadtfabrikanten.org
Date: 21.04.2021 Date: 21.04.2021
Last patch: 21.04.2021 Last patch: 07.05.2021
License: GNU GPL v3 License: GNU GPL v3
Used version of Vivus JS library: https://github.com/maxwellito/vivus/releases/tag/v0.4.6 - MIT License Used version of Vivus JS library: https://github.com/maxwellito/vivus/releases/tag/v0.4.6 - MIT License
@ -29,9 +30,21 @@ ToDo:
- the generated SVGs can be downloaded again and include all animations! - the generated SVGs can be downloaded again and include all animations!
- calculate the total length of all paths and auto-adjust the speed to have good visibility - calculate the total length of all paths and auto-adjust the speed to have good visibility
""" """
DETACHED_PROCESS = 0x00000008
class AnimateOrder (inkex.EffectExtension): class AnimateOrder (inkex.EffectExtension):
def spawnIndependentProcess(self, args): #function to spawn non-blocking inkscape instance. the inkscape command is available because it is added to ENVIRONMENT when Inkscape main instance is started
if os.name == 'nt':
warnings.simplefilter('ignore', ResourceWarning) #suppress "enable tracemalloc to get the object allocation traceback"
subprocess.Popen(args, close_fds=True, creationflags=DETACHED_PROCESS)
warnings.simplefilter("default", ResourceWarning)
else:
pid = os.fork()
if pid == 0: # new process
os.system("nohup " + args + " &")
exit()
def add_arguments(self, pars): def add_arguments(self, pars):
pars.add_argument("--tab") pars.add_argument("--tab")
pars.add_argument("--time", type=float, default = 5.0, help="Duration (frames)") pars.add_argument("--time", type=float, default = 5.0, help="Duration (frames)")
@ -48,9 +61,11 @@ class AnimateOrder (inkex.EffectExtension):
target_html = os.path.join(extension_dir, "animate_order.html") target_html = os.path.join(extension_dir, "animate_order.html")
title = "Animate Order - " + self.document.getroot().get("{http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd}docname") docTitle = self.document.getroot().get("{http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd}docname")
if title is None: if docTitle is None:
title = "Animate Order - Vivus JS" title = "Animate Order - Vivus JS"
else:
title = "Animate Order - " + docTitle
vivus_include = "./vivus-0.4.6/dist/vivus.js" vivus_include = "./vivus-0.4.6/dist/vivus.js"
duration = self.options.time * self.options.fps # we guess we have 20 ... 60 fps. depends on performance of the machine duration = self.options.time * self.options.fps # we guess we have 20 ... 60 fps. depends on performance of the machine
@ -81,10 +96,7 @@ class AnimateOrder (inkex.EffectExtension):
#now open firefox #now open firefox
args = [self.options.browser, target_html] args = [self.options.browser, target_html]
proc = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.spawnIndependentProcess(args)
stdout, stderr = proc.communicate()
if proc.returncode != 0:
inkex.utils.debug("%d %s %s" % (proc.returncode, stdout, stderr))
if __name__ == '__main__': if __name__ == '__main__':
AnimateOrder().run() AnimateOrder().run()

View File

@ -9,7 +9,7 @@
<param name="dxf_exporter_path" type="path" mode="file" filetypes="py" gui-text="Location of dxf_outlines.py">/usr/share/inkscape/extensions/dxf_outlines.py</param> <param name="dxf_exporter_path" type="path" mode="file" filetypes="py" gui-text="Location of dxf_outlines.py">/usr/share/inkscape/extensions/dxf_outlines.py</param>
<param name="export_dxf" type="bool" gui-text="Export as DXF R14 file (mm units)">false</param> <param name="export_dxf" type="bool" gui-text="Export as DXF R14 file (mm units)">false</param>
<param name="export_pdf" type="bool" gui-text="Export as PDF 1.5">false</param> <param name="export_pdf" type="bool" gui-text="Export as PDF 1.5">false</param>
<param name="newwindow" type="bool" gui-text="Open file in new blocking Inkscape window">false</param> <param name="newwindow" type="bool" gui-text="Open file in new Inkscape instance">false</param>
<effect needs-document="true" needs-live-preview="false"> <effect needs-document="true" needs-live-preview="false">
<object-type>all</object-type> <object-type>all</object-type>
<effects-menu> <effects-menu>