diff --git a/Makefile b/Makefile index eef8c2d36..03a341096 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -EXTENSIONS:=embroider embroider_params embroider_simulate embroider_print embroider_input +EXTENSIONS:=embroider embroider_params embroider_simulate embroider_print embroider_input embroider_install_palettes # This gets the branch name or the name of the tag VERSION:=$(TRAVIS_BRANCH) @@ -9,7 +9,7 @@ dist: distclean locales bin/build-dist $(EXTENSIONS) cp inx/*.inx dist cp -a images/examples dist/inkstitch - cp -a palettes dist/inkstitch + cp -a palettes dist/inkstitch mkdir -p dist/inkstitch/bin/locales cp -a locales/* dist/inkstitch/bin/locales cp -a print dist/inkstitch/bin/ diff --git a/embroider_install_palettes.py b/embroider_install_palettes.py new file mode 100644 index 000000000..ba23fb2ca --- /dev/null +++ b/embroider_install_palettes.py @@ -0,0 +1,111 @@ +#!/usr/bin/python +# + +import sys +import traceback +import os +from os.path import realpath, dirname +from threading import Thread +import socket +import errno +import time +import logging +import wx +import inkex +import shutil +from inkstitch.utils import guess_inkscape_config_path + + +class InstallPalettesFrame(wx.Frame): + def __init__(self, *args, **kwargs): + wx.Frame.__init__(self, *args, **kwargs) + + default_path = os.path.join(guess_inkscape_config_path(), "palettes") + + panel = wx.Panel(self) + sizer = wx.BoxSizer(wx.VERTICAL) + + text = wx.StaticText(panel, label=_("Directory in which to install palettes:")) + font = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL) + text.SetFont(font) + sizer.Add(text, proportion=0, flag=wx.ALL|wx.EXPAND, border=10) + + path_sizer = wx.BoxSizer(wx.HORIZONTAL) + self.path_input = wx.TextCtrl(panel, wx.ID_ANY, value=default_path) + path_sizer.Add(self.path_input, proportion=3, flag=wx.RIGHT|wx.EXPAND, border=20) + chooser_button = wx.Button(panel, wx.ID_OPEN, _('Choose another directory...')) + path_sizer.Add(chooser_button, proportion=1, flag=wx.EXPAND) + sizer.Add(path_sizer, proportion=0, flag=wx.ALL|wx.EXPAND, border=10) + + buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) + install_button = wx.Button(panel, wx.ID_ANY, _("Install")) + install_button.SetBitmap(wx.ArtProvider.GetBitmap(wx.ART_TICK_MARK)) + buttons_sizer.Add(install_button, proportion=0, flag=wx.ALIGN_RIGHT|wx.ALL, border=5) + cancel_button = wx.Button(panel, wx.ID_CANCEL, _("Cancel")) + buttons_sizer.Add(cancel_button, proportion=0, flag=wx.ALIGN_RIGHT|wx.ALL, border=5) + sizer.Add(buttons_sizer, proportion=0, flag=wx.ALIGN_RIGHT) + + outer_sizer = wx.BoxSizer(wx.HORIZONTAL) + outer_sizer.Add(sizer, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) + + panel.SetSizer(outer_sizer) + panel.Layout() + + chooser_button.Bind(wx.EVT_BUTTON, self.chooser_button_clicked) + cancel_button.Bind(wx.EVT_BUTTON, self.cancel_button_clicked) + install_button.Bind(wx.EVT_BUTTON, self.install_button_clicked) + + def cancel_button_clicked(self, event): + self.Destroy() + + def chooser_button_clicked(self, event): + dialog = wx.DirDialog(self, _("Choose Inkscape palettes directory")) + if dialog.ShowModal() != wx.ID_CANCEL: + self.path_input.SetValue(dialog.GetPath()) + + def install_button_clicked(self, event): + try: + self.install_palettes() + except Exception, e: + wx.MessageDialog(self, + _('Thread palette installation failed: ' + str(e)), + _('Installation Failed'), + wx.OK).ShowModal() + else: + wx.MessageDialog(self, + _('Thread palette files have been installed. Please restart Inkscape to load the new palettes.'), + _('Installation Completed'), + wx.OK).ShowModal() + + self.Destroy() + + def install_palettes(self): + path = self.path_input.GetValue() + + if not os.path.exists(path): + os.makedirs(path) + + palettes_dir = self.get_bundled_palettes_dir() + + for palette_file in os.listdir(palettes_dir): + shutil.copy(os.path.join(palettes_dir, palette_file), path) + + def get_bundled_palettes_dir(self): + if getattr(sys, 'frozen', None) is not None: + return os.path.join(sys._MEIPASS, 'palettes') + else: + return os.path.join(dirname(realpath(__file__)), 'palettes') + +class InstallPalettes(inkex.Effect): + def effect(self): + app = wx.App() + installer_frame = InstallPalettesFrame(None, title=_("Ink/Stitch Thread Palette Installer"), size=(450, 200)) + installer_frame.Show() + app.MainLoop() + + +if __name__ == '__main__': + #save_stderr() + effect = InstallPalettes() + effect.affect() + #restore_stderr() diff --git a/inkstitch/utils/__init__.py b/inkstitch/utils/__init__.py index 94a95658c..ff06d4a9f 100644 --- a/inkstitch/utils/__init__.py +++ b/inkstitch/utils/__init__.py @@ -1,3 +1,4 @@ from geometry import * from cache import cache from io import * +from inkscape import * diff --git a/inkstitch/utils/inkscape.py b/inkstitch/utils/inkscape.py new file mode 100644 index 000000000..4aba1bad1 --- /dev/null +++ b/inkstitch/utils/inkscape.py @@ -0,0 +1,10 @@ +from os.path import realpath, expanduser, join as path_join +import sys + +def guess_inkscape_config_path(): + if getattr(sys, 'frozen', None): + path = realpath(path_join(sys._MEIPASS, "..")) + else: + path = expanduser("~/.config/inkscape") + + return path diff --git a/inx/embroider_install_palettes.inx b/inx/embroider_install_palettes.inx new file mode 100644 index 000000000..063d6670c --- /dev/null +++ b/inx/embroider_install_palettes.inx @@ -0,0 +1,16 @@ + + + <_name>Install thread manufacturer color palettes + org.inkstitch.palettes + embroider_install_palettes.py + inkex.py + + all + + + + + + diff --git a/messages.po b/messages.po index bce29caeb..192ff456f 100644 --- a/messages.po +++ b/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2018-04-28 13:36-0400\n" +"POT-Creation-Date: 2018-04-28 17:58-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -23,6 +23,38 @@ msgid "" "Seeing a 'no such option' message? Please restart Inkscape to fix." msgstr "" +msgid "Directory in which to install palettes:" +msgstr "" + +msgid "Choose another directory..." +msgstr "" + +msgid "Install" +msgstr "" + +msgid "Cancel" +msgstr "" + +msgid "Choose Inkscape palettes directory" +msgstr "" + +msgid "Thread palette installation failed: " +msgstr "" + +msgid "Installation Failed" +msgstr "" + +msgid "" +"Thread palette files have been installed. Please restart Inkscape to " +"load the new palettes." +msgstr "" + +msgid "Installation Completed" +msgstr "" + +msgid "Ink/Stitch Thread Palette Installer" +msgstr "" + msgid "These settings will be applied to 1 object." msgstr "" @@ -67,9 +99,6 @@ msgstr "" msgid "Delete" msgstr "" -msgid "Cancel" -msgstr "" - msgid "Use Last Settings" msgstr ""