From 0e4fab06c4bec76d90e7f18580b0272ce74af439 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sun, 24 Jun 2018 15:55:13 -0400 Subject: installer now installs symbols too --- inx/inkstitch_install.inx | 17 +++++++ inx/inkstitch_palettes.inx | 17 ------- lib/extensions/__init__.py | 2 +- lib/extensions/install.py | 123 +++++++++++++++++++++++++++++++++++++++++++++ lib/extensions/palettes.py | 112 ----------------------------------------- messages.po | 26 +++++++--- 6 files changed, 160 insertions(+), 137 deletions(-) create mode 100644 inx/inkstitch_install.inx delete mode 100644 inx/inkstitch_palettes.inx create mode 100644 lib/extensions/install.py delete mode 100644 lib/extensions/palettes.py diff --git a/inx/inkstitch_install.inx b/inx/inkstitch_install.inx new file mode 100644 index 00000000..7275e13a --- /dev/null +++ b/inx/inkstitch_install.inx @@ -0,0 +1,17 @@ + + + <_name>Install add-ons for Inkscape + org.inkstitch.install + inkstitch.py + inkex.py + install + + all + + + + + + diff --git a/inx/inkstitch_palettes.inx b/inx/inkstitch_palettes.inx deleted file mode 100644 index 5daa3196..00000000 --- a/inx/inkstitch_palettes.inx +++ /dev/null @@ -1,17 +0,0 @@ - - - <_name>Install thread manufacturer color palettes - org.inkstitch.palettes - inkstitch.py - inkex.py - palettes - - all - - - - - - diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index 6d3e00d8..b8951e12 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -1,5 +1,5 @@ from embroider import Embroider -from palettes import Palettes +from install import Install from params import Params from print_pdf import Print from simulate import Simulate diff --git a/lib/extensions/install.py b/lib/extensions/install.py new file mode 100644 index 00000000..5ce511e7 --- /dev/null +++ b/lib/extensions/install.py @@ -0,0 +1,123 @@ +# -*- coding: UTF-8 -*- + +import sys +import traceback +import os +from os.path import realpath, dirname +from glob import glob +from threading import Thread +import socket +import errno +import time +import logging +import wx +import inkex + +from ..utils import guess_inkscape_config_path + + +class InstallerFrame(wx.Frame): + def __init__(self, *args, **kwargs): + wx.Frame.__init__(self, *args, **kwargs) + + default_path = guess_inkscape_config_path() + + panel = wx.Panel(self) + sizer = wx.BoxSizer(wx.VERTICAL) + + text_sizer = wx.BoxSizer(wx.HORIZONTAL) + + text = _('Ink/Stitch can install files ("add-ons") that make it easier to use Inkscape to create machine embroidery designs. These add-ons will be installed:') + \ + "\n\n • " + _("thread manufacturer color palettes") + \ + "\n • " + _("Ink/Stitch visual commands (Object -> Symbols...)") + \ + "\n\n" + _("Directory in which to install add-ons:") + + static_text = wx.StaticText(panel, label=text) + font = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL) + static_text.SetFont(font) + text_sizer.Add(static_text, proportion=0, flag=wx.ALL|wx.EXPAND, border=10) + sizer.Add(text_sizer, proportion=3, flag=wx.ALL|wx.EXPAND, border=0) + + 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, border=20) + chooser_button = wx.Button(panel, wx.ID_OPEN, _('Choose another directory...')) + path_sizer.Add(chooser_button, proportion=1, flag=0) + sizer.Add(path_sizer, proportion=1, flag=wx.ALL|wx.ALIGN_BOTTOM, 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=1, flag=wx.ALIGN_RIGHT|wx.ALIGN_BOTTOM) + + #outer_sizer = wx.BoxSizer(wx.HORIZONTAL) + #outer_sizer.Add(sizer, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) + + panel.SetSizer(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 directory")) + if dialog.ShowModal() != wx.ID_CANCEL: + self.path_input.SetValue(dialog.GetPath()) + + def install_button_clicked(self, event): + try: + self.install_addons('palettes') + self.install_addons('symbols') + except Exception, e: + wx.MessageDialog(self, + _('Inkscape add-on installation failed') + ': \n' + traceback.format_exc(), + _('Installation Failed'), + wx.OK).ShowModal() + else: + wx.MessageDialog(self, + _('Inkscape add-on files have been installed. Please restart Inkscape to load the new add-ons.'), + _('Installation Completed'), + wx.OK).ShowModal() + + self.Destroy() + + def install_addons(self, type): + path = os.path.join(self.path_input.GetValue(), type) + src_dir = self.get_bundled_dir(type) + self.copy_files(glob(os.path.join(src_dir, "*")), path) + + def get_bundled_dir(self, name): + if getattr(sys, 'frozen', None) is not None: + return realpath(os.path.join(sys._MEIPASS, '..', name)) + else: + return realpath(os.path.join(dirname(realpath(__file__)), '..', '..', name)) + + if (sys.platform == "win32"): + # If we try to just use shutil.copy it says the operation requires elevation. + def copy_files(self, files, dest): + import winutils + + winutils.copy(files, dest) + else: + def copy_files(self, files, dest): + import shutil + + if not os.path.exists(dest): + os.makedirs(dest) + + for palette_file in files: + shutil.copy(palette_file, dest) + +class Install(inkex.Effect): + def effect(self): + app = wx.App() + installer_frame = InstallerFrame(None, title=_("Ink/Stitch Add-ons Installer"), size=(550, 350)) + installer_frame.Show() + app.MainLoop() diff --git a/lib/extensions/palettes.py b/lib/extensions/palettes.py deleted file mode 100644 index f7a6c7a5..00000000 --- a/lib/extensions/palettes.py +++ /dev/null @@ -1,112 +0,0 @@ -import sys -import traceback -import os -from os.path import realpath, dirname -from glob import glob -from threading import Thread -import socket -import errno -import time -import logging -import wx -import inkex - -from ..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') + ': \n' + traceback.format_exc(), - _('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() - palettes_dir = self.get_bundled_palettes_dir() - self.copy_files(glob(os.path.join(palettes_dir, "*")), path) - - def get_bundled_palettes_dir(self): - if getattr(sys, 'frozen', None) is not None: - return realpath(os.path.join(sys._MEIPASS, '..', 'palettes')) - else: - return os.path.join(dirname(realpath(__file__)), 'palettes') - - if (sys.platform == "win32"): - # If we try to just use shutil.copy it says the operation requires elevation. - def copy_files(self, files, dest): - import winutils - - winutils.copy(files, dest) - else: - def copy_files(self, files, dest): - import shutil - - if not os.path.exists(dest): - os.makedirs(dest) - - for palette_file in files: - shutil.copy(palette_file, dest) - -class Palettes(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() diff --git a/messages.po b/messages.po index e6bfed43..89ce2de5 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-06-22 22:19-0400\n" +"POT-Creation-Date: 2018-06-24 15:55-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -198,7 +198,19 @@ msgid "" "Seeing a 'no such option' message? Please restart Inkscape to fix." msgstr "" -msgid "Directory in which to install palettes:" +msgid "" +"Ink/Stitch can install files (\"add-ons\") that make it easier to use " +"Inkscape to create machine embroidery designs. These add-ons will be " +"installed:" +msgstr "" + +msgid "thread manufacturer color palettes" +msgstr "" + +msgid "Ink/Stitch visual commands (Object -> Symbols...)" +msgstr "" + +msgid "Directory in which to install add-ons:" msgstr "" msgid "Choose another directory..." @@ -210,24 +222,24 @@ msgstr "" msgid "Cancel" msgstr "" -msgid "Choose Inkscape palettes directory" +msgid "Choose Inkscape directory" msgstr "" -msgid "Thread palette installation failed" +msgid "Inkscape add-on installation failed" msgstr "" msgid "Installation Failed" msgstr "" msgid "" -"Thread palette files have been installed. Please restart Inkscape to " -"load the new palettes." +"Inkscape add-on files have been installed. Please restart Inkscape to " +"load the new add-ons." msgstr "" msgid "Installation Completed" msgstr "" -msgid "Ink/Stitch Thread Palette Installer" +msgid "Ink/Stitch Add-ons Installer" msgstr "" msgid "These settings will be applied to 1 object." -- cgit v1.2.3