diff options
Diffstat (limited to 'lib/extensions/install.py')
| -rw-r--r-- | lib/extensions/install.py | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/lib/extensions/install.py b/lib/extensions/install.py index 62cfde73..501694ed 100644 --- a/lib/extensions/install.py +++ b/lib/extensions/install.py @@ -4,18 +4,48 @@ # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. from .base import InkstitchExtension -from ..api import APIServer -from ..gui import open_url +import os +import sys +from glob import glob +from ..utils import get_bundled_dir, guess_inkscape_config_path +from inkex import errormsg +from ..i18n import _ class Install(InkstitchExtension): - def __init__(self): - InkstitchExtension.__init__(self) + def __init__(self, *args, **kwargs): + InkstitchExtension.__init__(self, *args, **kwargs) def effect(self): - api_server = APIServer(self) - port = api_server.start_server() - electron = open_url("/install?port=%d" % port) - electron.wait() - api_server.stop() - api_server.join() + path = os.path.join(guess_inkscape_config_path(), 'palettes') + src_dir = get_bundled_dir('palettes') + try: + copy_files(glob(os.path.join(src_dir, "*")), path) + errormsg(_("Successfully installed color palettes for Inkscape.\n\n" + "Please restart Inkscape.")) + except IOError: + errormsg(_("Could not install color palettes. Please file an issue on " + "https://github.com/inkstitch/inkstitch/issues")) + + +if sys.platform == "win32": + # If we try to just use shutil.copy it says the operation requires elevation. + def copy_files(files, dest): + import pythoncom + import winutils + + pythoncom.CoInitialize() + + if not os.path.exists(dest): + os.makedirs(dest) + + winutils.copy(files, dest) +else: + def copy_files(files, dest): + import shutil + + if not os.path.exists(dest): + os.makedirs(dest) + + for palette_file in files: + shutil.copy(palette_file, dest) |
