From 9358db2a9b1234d36096bfc6f2c6d59610f248b6 Mon Sep 17 00:00:00 2001 From: Olibia Tsati Date: Sat, 13 Jun 2020 11:30:42 +0300 Subject: [PATCH] update to support inkscape 1.0 --- generate_palette.inx | 46 +++++++++++++++++++++++---------------- generate_palette.py | 52 +++++++++++++++++++++++++++++--------------- info.svg | 1 + 3 files changed, 63 insertions(+), 36 deletions(-) create mode 100644 info.svg diff --git a/generate_palette.inx b/generate_palette.inx index 0e6f406..5527bdb 100644 --- a/generate_palette.inx +++ b/generate_palette.inx @@ -1,25 +1,33 @@ - + Generate hardpixel.eu.generate_palette - generate_palette.py - simplestyle.py - - Select a set of objects and create a custom color palette. - Palette Properties - Palette Name - - Color Property - - Fill Color - Stroke Color - Both - - Options - false - false - ℹ️ Don't forget to restart Inkscape + + + + + + + + + + + + + + + + + false + false + + + + + info.svg + + all @@ -29,6 +37,6 @@ diff --git a/generate_palette.py b/generate_palette.py index daf60f7..efc7d4b 100644 --- a/generate_palette.py +++ b/generate_palette.py @@ -8,29 +8,46 @@ import os import sys import inkex -import simplestyle - -__version__ = '2.0' - -inkex.localize() def log(text): - inkex.debug(text) + inkex.utils.debug(text) def abort(text): inkex.errormsg(_(text)) exit() - class GeneratePalette(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) - self.OptionParser.add_option('-n', '--name', action='store', type='string', dest='name', help='Palette name') - self.OptionParser.add_option('-p', '--property', action='store', type='string', dest='property', help='Color property') - self.OptionParser.add_option('-d', '--default', action='store', type='inkbool', dest='default', help='Default grays') - self.OptionParser.add_option('-r', '--replace', action='store', type='inkbool', dest='replace', help='Replace existing') + self.arg_parser.add_argument( + '-n', '--name', + type=str, + dest='name', + help='Palette name' + ) + + self.arg_parser.add_argument( + '-p', '--property', + type=str, + dest='property', + help='Color property' + ) + + self.arg_parser.add_argument( + '-d', '--default', + type=inkex.Boolean, + dest='default', + help='Default grays' + ) + + self.arg_parser.add_argument( + '-r', '--replace', + type=inkex.Boolean, + dest='replace', + help='Replace existing' + ) def get_palettes_path(self): if sys.platform.startswith('win'): @@ -66,22 +83,24 @@ def get_default_colors(self): return colors if self.options.default else [] def get_node_prop(self, node, property): - style = simplestyle.parseStyle(node.attrib['style']) - return style[property] + attr = node.attrib.get('style') + style = dict(inkex.Style.parse_str(attr)) + + return style.get(property, 'none') def get_node_index(self, args): id, node = args return self.options.ids.index(id) def get_formatted_color(self, color): - rgb = simplestyle.parseColor(color) + rgb = inkex.Color(color).to_rgb() rgb = "{:3d} {:3d} {:3d}".format(*rgb) return "%s %s" % (rgb, color) def get_selected_colors(self): colors = [] - selected = list(self.selected.items()) + selected = list(self.svg.selected.items()) selected.sort(key=self.get_node_index) @@ -133,7 +152,6 @@ def effect(self): self.write_palette() - if __name__ == '__main__': palette = GeneratePalette() - palette.affect() + palette.run() diff --git a/info.svg b/info.svg new file mode 100644 index 0000000..2fafe0a --- /dev/null +++ b/info.svg @@ -0,0 +1 @@ + \ No newline at end of file