better ui for create links

This commit is contained in:
leyghisbb 2021-04-14 14:26:24 +02:00
parent 3fb3a020f8
commit 3c5ef0d9d5
2 changed files with 63 additions and 52 deletions

View File

@ -4,49 +4,57 @@
<id>fablabchemnitz.de.create_links</id> <id>fablabchemnitz.de.create_links</id>
<param name="main_tabs" type="notebook"> <param name="main_tabs" type="notebook">
<page name="settings" gui-text="Settings"> <page name="settings" gui-text="Settings">
<param name="path_types" type="optiongroup" appearance="combo" gui-text="Apply for"> <hbox>
<option value="open_paths">open paths</option> <vbox>
<option value="closed_paths">closed paths</option> <param name="path_types" type="optiongroup" appearance="combo" gui-text="Apply for">
<option value="both">both</option> <option value="open_paths">open paths</option>
</param> <option value="closed_paths">closed paths</option>
<param name="creationtype" type="optiongroup" appearance="combo" gui-text="Creation"> <option value="both">both</option>
<option value="use_existing">Existing dash style from element</option> </param>
<option value="custom_dasharray">Custom dash pattern</option> <param name="creationtype" type="optiongroup" appearance="combo" gui-text="Creation">
<option value="entered_values">Render by unit and link settings</option> <option value="use_existing">Existing dash style from element</option>
</param> <option value="custom_dashpattern">Custom dash pattern</option>
<param name="creationunit" type="optiongroup" appearance="combo" gui-text="Creation Units"> <option value="entered_values">Render by unit and link settings</option>
<option value="mm">mm</option> </param>
<option value="cm">cm</option> <param name="creationunit" type="optiongroup" appearance="combo" gui-text="Creation Units">
<option value="m">m</option> <option value="mm">mm</option>
<option value="in">in</option> <option value="cm">cm</option>
<option value="pt">pt</option> <option value="m">m</option>
<option value="px">px</option> <option value="in">in</option>
<option value="pc">pc</option> <option value="pt">pt</option>
<option value="percent">%</option> <option value="px">px</option>
</param> <option value="pc">pc</option>
<label appearance="header">Creation: Link Settings</label> <option value="percent">%</option>
<param name="link_count" type="int" min="1" max="9999" gui-text="Link count">1</param> </param>
<param name="length_link" type="float" min="0.000" max="9999.000" precision="3" gui-text="Link length (the length of the gap)">1.000</param> <label appearance="header">Creation: Link Settings</label>
<param name="link_multiplicator" type="int" min="0" max="9999" gui-text="Link multiplicator" gui-description="If set, we create a set of multiple gaps of same size next to the main gap">0</param> <param name="link_count" type="int" min="1" max="9999" gui-text="Link count">1</param>
<param name="link_offset" type="float" min="-9999.000.000" max="9999.000" precision="3" gui-text="Link offset (+/-)">0.000</param> <param name="link_multiplicator" type="int" min="0" max="9999" gui-text="Link multiplicator" gui-description="If set, we create a set of multiple gaps of same size next to the main gap">0</param>
<label appearance="header">Creation: Custom Dash Pattern Settings</label> <param name="length_link" type="float" min="0.000" max="9999.000" precision="3" gui-text="Link length (the length of the gap)">1.000</param>
<param name="custom_dasharray_value" type="string" gui-text="Dash pattern" gui-description="A list of separated lengths that specify the lengths of alternating dashes and gaps. Input only accepts numbers. It ignores percentages or other characters.">10 5.5 2.0 2.0</param> <param name="link_offset" type="float" min="-9999.000.000" max="9999.000" precision="3" gui-text="Link offset (+/-)">0.000</param>
<label appearance="header">Other Settings</label> <label appearance="header">Creation: Custom Dash Pattern Settings</label>
<param name="length_filter" type="bool" gui-text="Enable path length filtering">false</param> <param name="custom_dasharray_value" type="string" gui-text="Dash pattern" gui-description="A list of separated lengths that specify the lengths of alternating dashes and gaps. Input only accepts numbers. It ignores percentages or other characters.">10 5.5 2.0 2.0</param>
<param name="length_filter_value" type="float" min="0.000" max="9999.000" precision="3" gui-text="Paths with length more than">0.000</param> <param name="custom_dashoffset_value" type="float" min="-9999.000.000" max="9999.000" precision="3" gui-text="Link offset (+/-)">0.000</param>
<param name="length_filter_unit" type="optiongroup" appearance="combo" gui-text="Length filter unit"> </vbox>
<option value="mm">mm</option> <separator/>
<option value="cm">cm</option> <vbox>
<option value="m">m</option> <label appearance="header">General Settings</label>
<option value="in">in</option> <param name="length_filter" type="bool" gui-text="Enable path length filtering">false</param>
<option value="pt">pt</option> <param name="length_filter_value" type="float" min="0.000" max="9999.000" precision="3" gui-text="Paths with length more than">0.000</param>
<option value="px">px</option> <param name="length_filter_unit" type="optiongroup" appearance="combo" gui-text="Length filter unit">
<option value="pc">pc</option> <option value="mm">mm</option>
</param> <option value="cm">cm</option>
<param name="keep_selected" type="bool" gui-text="Keep selected elements">false</param> <option value="m">m</option>
<param name="no_convert" type="bool" gui-text="Do not create output path(s) (cosmetic style only)">false</param> <option value="in">in</option>
<param name="breakapart" type="bool" gui-text="Break apart output path(s) into segments" gui-description="Performs CTRL + SHIFT + K to break the new output path into it's parts">false</param> <option value="pt">pt</option>
<param name="show_info" type="bool" gui-text="Print some length, pattern and filtering information" gui-description="Warning: might freeze InkScape forever if you have a lot of nodes because we create too much print output. Use for debugging only!">false</param> <option value="px">px</option>
<option value="pc">pc</option>
</param>
<param name="keep_selected" type="bool" gui-text="Keep selected elements">false</param>
<param name="no_convert" type="bool" gui-text="Do not create output path(s) (cosmetic style only)">false</param>
<param name="breakapart" type="bool" gui-text="Break apart output path(s) into segments" gui-description="Performs CTRL + SHIFT + K to break the new output path into it's parts">false</param>
<param name="show_info" type="bool" gui-text="Print some length, pattern and filtering information" gui-description="Warning: might freeze InkScape forever if you have a lot of nodes because we create too much print output. Use for debugging only!">false</param>
</vbox>
</hbox>
</page> </page>
<page name="about" gui-text="About"> <page name="about" gui-text="About">
<label appearance="header">Create Links</label> <label appearance="header">Create Links</label>

View File

@ -46,10 +46,11 @@ class LinksCreator(inkex.EffectExtension):
self.arg_parser.add_argument("--creationunit", default="mm", help="Creation Units") self.arg_parser.add_argument("--creationunit", default="mm", help="Creation Units")
self.arg_parser.add_argument("--creationtype", default="entered_values", help="Creation") self.arg_parser.add_argument("--creationtype", default="entered_values", help="Creation")
self.arg_parser.add_argument("--link_count", type=int, default=1, help="Link count") self.arg_parser.add_argument("--link_count", type=int, default=1, help="Link count")
self.arg_parser.add_argument("--length_link", type=float, default=1.000, help="Link length")
self.arg_parser.add_argument("--link_multiplicator", type=int, default=1, help="If set, we create a set of multiple gaps of same size next to the main gap") self.arg_parser.add_argument("--link_multiplicator", type=int, default=1, help="If set, we create a set of multiple gaps of same size next to the main gap")
self.arg_parser.add_argument("--link_offset", type=float, default=0.000, help="Link offset (+/-).") self.arg_parser.add_argument("--length_link", type=float, default=1.000, help="Link length")
self.arg_parser.add_argument("--link_offset", type=float, default=0.000, help="Link offset (+/-)")
self.arg_parser.add_argument("--custom_dasharray_value", default="", help="A list of separated lengths that specify the lengths of alternating dashes and gaps. Input only accepts numbers. It ignores percentages or other characters.") self.arg_parser.add_argument("--custom_dasharray_value", default="", help="A list of separated lengths that specify the lengths of alternating dashes and gaps. Input only accepts numbers. It ignores percentages or other characters.")
self.arg_parser.add_argument("--custom_dashoffset_value", type=float, default=0.000, help="Link offset (+/-)")
self.arg_parser.add_argument("--length_filter", type=inkex.Boolean, default=False, help="Enable path length filtering") self.arg_parser.add_argument("--length_filter", type=inkex.Boolean, default=False, help="Enable path length filtering")
self.arg_parser.add_argument("--length_filter_value", type=float, default=0.000, help="Paths with length more than") self.arg_parser.add_argument("--length_filter_value", type=float, default=0.000, help="Paths with length more than")
self.arg_parser.add_argument("--length_filter_unit", default="mm", help="Length filter unit") self.arg_parser.add_argument("--length_filter_unit", default="mm", help="Length filter unit")
@ -131,6 +132,12 @@ class LinksCreator(inkex.EffectExtension):
inkex.errormsg("Nothing to do. Please select another creation method or disable cosmetic style output paths.") inkex.errormsg("Nothing to do. Please select another creation method or disable cosmetic style output paths.")
return return
if self.options.creationtype == "entered_values":
if self.options.creationunit == "percent":
stroke_dashoffset = self.options.link_offset / 100.0
else:
stroke_dashoffset = self.svg.unittouu(str(self.options.link_offset) + self.options.creationunit)
if self.options.creationtype == "use_existing": if self.options.creationtype == "use_existing":
stroke_dashoffset = 0 stroke_dashoffset = 0
style = node.style style = node.style
@ -146,7 +153,8 @@ class LinksCreator(inkex.EffectExtension):
inkex.errormsg("no dash style to continue with.") inkex.errormsg("no dash style to continue with.")
return return
if self.options.creationtype == "custom_dasharray": if self.options.creationtype == "custom_dashpattern":
stroke_dashoffset = self.options.custom_dashoffset_value
try: try:
floats = [float(dash) for dash in re.findall(r"[-+]?\d*\.\d+|\d+", self.options.custom_dasharray_value)] floats = [float(dash) for dash in re.findall(r"[-+]?\d*\.\d+|\d+", self.options.custom_dasharray_value)]
if len(floats) > 0: if len(floats) > 0:
@ -159,11 +167,6 @@ class LinksCreator(inkex.EffectExtension):
stroke_dasharray = ' '.join(format(dash, "1.3f") for dash in dashes) stroke_dasharray = ' '.join(format(dash, "1.3f") for dash in dashes)
if self.options.creationunit == "percent":
stroke_dashoffset = self.options.link_offset / 100.0
else:
stroke_dashoffset = self.svg.unittouu(str(self.options.link_offset) + self.options.creationunit)
# check if the node has a style attribute. If not we create a blank one with a black stroke and without fill # check if the node has a style attribute. If not we create a blank one with a black stroke and without fill
style = None style = None
if node.attrib.has_key('style'): if node.attrib.has_key('style'):