summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2022-04-10 10:10:50 +0200
committerGitHub <noreply@github.com>2022-04-10 10:10:50 +0200
commitc575aeda96d389de29389c9e6e46395e1b938244 (patch)
treee235d604bcbd7262c79a02dc255c667eb7ebe56e
parent3780791c26cb5a61855c14685837f5513958a1b1 (diff)
palette to text (#1619)
-rw-r--r--lib/extensions/__init__.py2
-rw-r--r--lib/extensions/generate_palette.py13
-rw-r--r--lib/extensions/palette_split_text.py2
-rw-r--r--lib/extensions/palette_to_text.py50
-rw-r--r--templates/generate_palette.xml2
-rw-r--r--templates/palette_to_text.xml30
6 files changed, 90 insertions, 9 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py
index 2a2af2ef..8a41c22c 100644
--- a/lib/extensions/__init__.py
+++ b/lib/extensions/__init__.py
@@ -31,6 +31,7 @@ from .letters_to_font import LettersToFont
from .object_commands import ObjectCommands
from .output import Output
from .palette_split_text import PaletteSplitText
+from .palette_to_text import PaletteToText
from .params import Params
from .print_pdf import Print
from .remove_embroidery_settings import RemoveEmbroiderySettings
@@ -70,6 +71,7 @@ __all__ = extensions = [StitchPlanPreview,
InstallCustomPalette,
GeneratePalette,
PaletteSplitText,
+ PaletteToText,
Simulator,
Reorder,
DuplicateParams,
diff --git a/lib/extensions/generate_palette.py b/lib/extensions/generate_palette.py
index 4255cfba..280be90f 100644
--- a/lib/extensions/generate_palette.py
+++ b/lib/extensions/generate_palette.py
@@ -4,7 +4,6 @@
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
import os
-import sys
import inkex
@@ -30,29 +29,29 @@ class GeneratePalette(InkstitchExtension):
if not brand:
inkex.errormsg(_("Please specify a name for your color palette."))
- sys.exit()
+ return
if path:
if not os.path.isdir(path):
inkex.errormsg(_("Unkown directory path."))
- sys.exit()
+ return
else:
path = os.path.join(guess_inkscape_config_path(), 'palettes')
if not os.path.isdir(path):
inkex.errormsg(_("Ink/Stitch cannot find your palette folder automatically. Please enter the path manually."))
- sys.exit()
+ return
- elements = self.svg.selected.rendering_order()
+ elements = self.svg.selection.rendering_order()
if not elements:
inkex.errormsg(_("No element selected.\n\nPlease select at least one text element with a fill color."))
- sys.exit()
+ return
colors = self._get_color_from_elements(elements)
if not colors:
inkex.errormsg(_("We couldn't find any fill colors on your text elements. Please read the instructions on our website."))
- sys.exit()
+ return
colors = ['GIMP Palette', color_palette_name, '\nColumns: 4', '\n# RGB Value\t Color Name Number'] + colors
diff --git a/lib/extensions/palette_split_text.py b/lib/extensions/palette_split_text.py
index 829425b4..6c024ced 100644
--- a/lib/extensions/palette_split_text.py
+++ b/lib/extensions/palette_split_text.py
@@ -16,7 +16,7 @@ class PaletteSplitText(InkstitchExtension):
self.arg_parser.add_argument("-l", "--line-height", type=int, default=6, dest="line_height")
def effect(self):
- if not self.svg.selected:
+ if not self.svg.selection:
inkex.errormsg(_("Please select one or more text elements to split lines."))
return
diff --git a/lib/extensions/palette_to_text.py b/lib/extensions/palette_to_text.py
new file mode 100644
index 00000000..0944c649
--- /dev/null
+++ b/lib/extensions/palette_to_text.py
@@ -0,0 +1,50 @@
+# Authors: see git history
+#
+# Copyright (c) 2022 Authors
+# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
+
+import os
+
+import inkex
+
+from ..i18n import _
+from ..threads.palette import ThreadPalette
+from .base import InkstitchExtension
+
+
+class PaletteToText(InkstitchExtension):
+ # Generate a custom color palette in object related order
+ def __init__(self, *args, **kwargs):
+ InkstitchExtension.__init__(self, *args, **kwargs)
+ self.arg_parser.add_argument("-f", "--file", type=str, default=None, dest="file")
+ self.arg_parser.add_argument("-o", "--notebook:options", type=str, default=None, dest="page_options")
+ self.arg_parser.add_argument("-i", "--info", type=str, default=None, dest="page_help")
+
+ def effect(self):
+ palette_file = self.options.file
+ if not os.path.isfile(palette_file):
+ inkex.errormsg(_("File does not exist."))
+ return
+
+ thread_palette = ThreadPalette(palette_file)
+ current_layer = self.svg.get_current_layer()
+
+ x = 0
+ y = 0
+ pos = 0
+ for color in thread_palette:
+ line = "%s %s" % (color.name, color.number)
+ element = inkex.TextElement()
+ element.text = line
+ element.style = "fill:%s;font-size:4px;" % color.to_hex_str()
+ element.set('x', x)
+ element.set('y', str(y))
+ current_layer.insert(pos, element)
+
+ y = float(y) + 5
+ pos += 1
+
+
+if __name__ == '__main__':
+ e = PaletteToText()
+ e.affect()
diff --git a/templates/generate_palette.xml b/templates/generate_palette.xml
index 3f876ead..cf5a18e4 100644
--- a/templates/generate_palette.xml
+++ b/templates/generate_palette.xml
@@ -27,7 +27,7 @@
With this extension you can export colors from text elements in their stacking order.
The text will be used as the color name and number.</label>
<separator />
- <label>On our website we describe all necessaty steps to generate a color palette for Ink/Stitch.</label>
+ <label>On our website we describe all necessary steps to generate a color palette for Ink/Stitch.</label>
<label appearance="url">https://inkstitch.org/docs/thread-color#generate-color-palette</label>
</page>
</param>
diff --git a/templates/palette_to_text.xml b/templates/palette_to_text.xml
new file mode 100644
index 00000000..42b2b6b7
--- /dev/null
+++ b/templates/palette_to_text.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<inkscape-extension translationdomain="inkstitch" xmlns="http://www.inkscape.org/namespace/inkscape/extension">
+ <name>Palette to text</name>
+ <id>org.inkstitch.palette_to_text</id>
+ <effect needs-live-preview="false">
+ <object-type>all</object-type>
+ <effects-menu>
+ <submenu name="Ink/Stitch" translatable="no">
+ <submenu name="Thread Color Management" />
+ </submenu>
+ </effects-menu>
+ </effect>
+ <param name="extension" type="string" gui-hidden="true">palette_to_text</param>
+ <param name="notebook" type="notebook">
+ <page name="options" gui-text="Options">
+ <label>Choose a .gpl color palette file to import colors as text elements.</label>
+ <param name="file" type="path" gui-text="Choose file" mode="file" filetypes="gpl"/>
+ </page>
+ <page name="info" gui-text="Help">
+ <label appearance="header">Palette to text</label>
+ <label>Import a .gpl palette into Inkscape as text elements to edit color entries.</label>
+ <separator />
+ <label>Read more on our webiste:</label>
+ <label appearance="url">https://inkstitch.org/docs/thread-color#palette-to-text</label>
+ </page>
+ </param>
+ <script>
+ {{ command_tag | safe }}
+ </script>
+</inkscape-extension>