From 86af00f265ba75e1bdf51e6984bddd6351bb9fdf Mon Sep 17 00:00:00 2001 From: buliabyak Date: Tue, 10 Jul 2007 15:53:35 +0000 Subject: [PATCH] add color replacer --- share/extensions/Makefile.am | 2 ++ share/extensions/color_replace.inx | 18 ++++++++++++++++ share/extensions/color_replace.py | 34 ++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 share/extensions/color_replace.inx create mode 100644 share/extensions/color_replace.py diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index 7d3a00bb2..e15df2f38 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -30,6 +30,7 @@ extensions = \ color_removegreen.py\ color_removered.py\ color_rgbbarrel.py\ + color_replace.py\ cspsubdiv.py \ cubicsuperpath.py \ dia2svg.sh \ @@ -120,6 +121,7 @@ modules = \ color_removegreen.inx\ color_removered.inx\ color_rgbbarrel.inx\ + color_replace.inx\ dia.inx \ dots.inx \ dxf_input.inx \ diff --git a/share/extensions/color_replace.inx b/share/extensions/color_replace.inx new file mode 100644 index 000000000..d305ec329 --- /dev/null +++ b/share/extensions/color_replace.inx @@ -0,0 +1,18 @@ + + <_name>Replace color... + org.inkscape.color.replacecolor + coloreffect.py + color_replace.py + simplestyle.py + 000000 + 000000 + + all + + + + + + \ No newline at end of file diff --git a/share/extensions/color_replace.py b/share/extensions/color_replace.py new file mode 100644 index 000000000..adf6823c0 --- /dev/null +++ b/share/extensions/color_replace.py @@ -0,0 +1,34 @@ +import coloreffect + +import inkex + +class C(coloreffect.ColorEffect): + def __init__(self): + coloreffect.ColorEffect.__init__(self) + self.OptionParser.add_option("-f", "--from_color", action="store", type="string", dest="from_color", default="000000", help="Replace color") + self.OptionParser.add_option("-t", "--to_color", action="store", type="string", dest="to_color", default="000000", help="By color") + + def colmod(self,r,g,b): + this_color = '%02x%02x%02x' % (r, g, b) + + if self.options.from_color[0] == '"': + self.options.from_color = self.options.from_color[1:] + if self.options.from_color[0] == '#': + self.options.from_color = self.options.from_color[1:] + if self.options.from_color[-1] == '"': + self.options.from_color = self.options.from_color[:-1] + if self.options.to_color[0] == '"': + self.options.to_color = self.options.to_color[1:] + if self.options.to_color[0] == '#': + self.options.to_color = self.options.to_color[1:] + if self.options.to_color[-1] == '"': + self.options.to_color = self.options.to_color[:-1] + + #inkex.debug(this_color+"|"+self.options.from_color) + if this_color == self.options.from_color: + return self.options.to_color + else: + return this_color + +c = C() +c.affect() \ No newline at end of file -- 2.30.2