added option to select local vektorkollektor.js file
This commit is contained in:
parent
375ccb664d
commit
c0756e6e05
@ -4,8 +4,16 @@
|
||||
<id>fablabchemnitz.de.vektorkollektor</id>
|
||||
<param name="tab" type="notebook">
|
||||
<page name="tab_settings" gui-text="Settings">
|
||||
<label appearance="header">Input Source</label>
|
||||
<param name="download_or_local" gui-text="Input" type="optiongroup" appearance="radio">
|
||||
<option value="remote">Download recent vektorkollektor.js file using the given URL</option>
|
||||
<option value="local">Use local input file using given path</option>
|
||||
</param>
|
||||
<param name="vk_url" type="string" gui-text="Data URL" gui-description="default: http://www.vektorkollektor.com/vektordaten/vektorkollektor.js">http://www.vektorkollektor.com/vektordaten/vektorkollektor.js</param>
|
||||
<param name="vk_id" type="int" gui-text="Vektorkollektor ID" min="0" max="99999" gui-description="The desired Vektorkolletor drawing ID">0</param>
|
||||
<param name="vk_inputfile" type="path" gui-text="Local file (*.js)" gui-description="Full path to your raw Vektorkollektor *.js file" filetypes="js" mode="file">C:\Users\</param>
|
||||
<param name="showinfo" type="bool" gui-text="Show additional information">false</param>
|
||||
<label appearance="header">Vektorkollektor ID</label>
|
||||
<param name="vk_id" type="int" gui-text="Number" min="0" max="99999" gui-description="The desired Vektorkolletor drawing ID">0</param>
|
||||
</page>
|
||||
<page name="tab_about" gui-text="About">
|
||||
<label appearance="header">Vektorkollektor</label>
|
||||
|
@ -13,19 +13,33 @@ from lxml import etree
|
||||
import inkex
|
||||
from inkex import PathElement, Path
|
||||
import re
|
||||
import os
|
||||
from ast import literal_eval
|
||||
|
||||
class Vektorkollektor(inkex.EffectExtension):
|
||||
|
||||
def add_arguments(self, pars):
|
||||
pars.add_argument("--tab")
|
||||
pars.add_argument("--vk_inputfile")
|
||||
pars.add_argument("--download_or_local", default='local')
|
||||
pars.add_argument("--showinfo", type=inkex.Boolean, default=False)
|
||||
pars.add_argument("--vk_url", default="http://www.vektorkollektor.com/vektordaten/vektorkollektor.js")
|
||||
pars.add_argument("--vk_id", type=int, default=1)
|
||||
|
||||
def effect(self):
|
||||
|
||||
if self.options.download_or_local == "local":
|
||||
if not os.path.exists(self.options.vk_inputfile):
|
||||
self.msg("The input file does not exist. Please select a proper file and try again.")
|
||||
exit(1)
|
||||
with open(self.options.vk_inputfile, 'r') as file:
|
||||
vkData = file.read()
|
||||
else:
|
||||
# Download the recent vektorkollektor data file and parse it
|
||||
handler = urllib.request.HTTPBasicAuthHandler()
|
||||
opener = urllib.request.build_opener(handler)
|
||||
vkData = opener.open(self.options.vk_url).read().decode("utf-8")
|
||||
urllib.request.install_opener(opener)
|
||||
|
||||
try:
|
||||
xP = [] #x-coordinate
|
||||
@ -33,8 +47,6 @@ class Vektorkollektor(inkex.EffectExtension):
|
||||
cP = [] #draw
|
||||
fN = [] #original vektorkollektor .PLT file number
|
||||
|
||||
vkData = opener.open(self.options.vk_url).read().decode("utf-8")
|
||||
urllib.request.install_opener(opener)
|
||||
for match in re.compile(r"""^var xP = .*;""", re.MULTILINE).finditer(vkData):
|
||||
xP = literal_eval(match.group(0).split("var xP = ")[1].split(";")[0])
|
||||
for match in re.compile(r"""^var yP = .*;""", re.MULTILINE).finditer(vkData):
|
||||
@ -44,6 +56,9 @@ class Vektorkollektor(inkex.EffectExtension):
|
||||
for match in re.compile(r"""^var fN = .*;""", re.MULTILINE).finditer(vkData):
|
||||
fN = literal_eval(match.group(0).split("var fN = ")[1].split(";")[0])
|
||||
|
||||
if self.options.showinfo is True:
|
||||
self.msg("Input file contains {} drawings.".format(fN[-2])) #last number is always 0, so we use the second last
|
||||
|
||||
vkGroup = self.document.getroot().add(inkex.Group(id="vektorkollektor-{}".format(self.options.vk_id)))
|
||||
for move in range(0, len(fN)):
|
||||
begin = None
|
||||
@ -63,6 +78,10 @@ class Vektorkollektor(inkex.EffectExtension):
|
||||
newLine.style = "fill:none;stroke:#000000;stroke-width:1;stroke-linecap:round"
|
||||
vkGroup.append(newLine)
|
||||
|
||||
if self.options.showinfo is True:
|
||||
self.msg("The drawing with id {} contains {} drawable vectors.".format(self.options.vk_id, len(vkGroup)))
|
||||
|
||||
|
||||
except Exception as e:
|
||||
inkex.errormsg(e)
|
||||
|
||||
|
Reference in New Issue
Block a user