summaryrefslogtreecommitdiff
path: root/lib/extensions/install_custom_palette.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2021-08-07 10:58:02 -0400
committerLex Neva <github.com@lexneva.name>2021-08-07 10:58:02 -0400
commit12ef0c84aa732623b210fdce1a7b8301aa435217 (patch)
tree4c7fbb33c4840be4bf8d8fecfd7fe481d0e56895 /lib/extensions/install_custom_palette.py
parentc1e6558f7852def419adfbeb087b2194e6030a2c (diff)
parentd6e20fae8a03ac162ae0c863fff06b5bd8b77902 (diff)
Merge remote-tracking branch 'origin/main' into kaalleen/satin-patterns
Diffstat (limited to 'lib/extensions/install_custom_palette.py')
-rw-r--r--lib/extensions/install_custom_palette.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/extensions/install_custom_palette.py b/lib/extensions/install_custom_palette.py
new file mode 100644
index 00000000..da546cad
--- /dev/null
+++ b/lib/extensions/install_custom_palette.py
@@ -0,0 +1,42 @@
+# Authors: see git history
+#
+# Copyright (c) 2021 Authors
+# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
+
+import os
+import shutil
+
+import inkex
+
+from ..i18n import _
+from ..utils import guess_inkscape_config_path
+from .base import InkstitchExtension
+
+
+class InstallCustomPalette(InkstitchExtension):
+ def __init__(self, *args, **kwargs):
+ InkstitchExtension.__init__(self, *args, **kwargs)
+ self.arg_parser.add_argument("-f", "--filepath", type=str, default="", dest="filepath")
+
+ def effect(self):
+ gpl = self.options.filepath
+ if not os.path.isfile(gpl):
+ inkex.errormsg(_("File does not exist."))
+
+ palette_name = os.path.basename(gpl)
+ if not palette_name.endswith('.gpl'):
+ inkex.errormsg(_("Wrong file type. Ink/Stitch only accepts gpl color palettes."))
+
+ if not palette_name.startswith('InkStitch'):
+ palette_name = 'InkStitch %s' % palette_name
+
+ palette_path = os.path.join(guess_inkscape_config_path(), 'palettes')
+
+ if not os.path.isdir(palette_path):
+ inkex.errormsg(_("Ink/Stitch cannot find your palette folder automatically. Please install your palette manually."))
+ dest = os.path.join(palette_path, palette_name)
+ shutil.copyfile(gpl, dest)
+
+ if not os.path.isfile(dest):
+ inkex.errormsg("Something wwent wrong. Ink/Stitch wasn't able to copy your palette "
+ "file into the Inkscape palettes folder. Please do it manually.")