summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2020-08-19 14:53:01 -0400
committerLex Neva <github.com@lexneva.name>2020-08-19 14:53:01 -0400
commit690ee0c416635f8d6d3dc07048be90bd0da7748f (patch)
tree8351dd7ffa0aee40e6409d29fda7577bf1f04a95
parent1631428ae44465ee96b7a283d7fec8cde1a68d73 (diff)
wip: move install extension to electron
-rw-r--r--electron/src/renderer/components/InstallPalettes.vue49
-rw-r--r--electron/src/renderer/main.js2
-rw-r--r--electron/src/renderer/router/index.js23
-rw-r--r--lib/api/install.py42
-rw-r--r--lib/api/server.py8
-rw-r--r--lib/extensions/install.py124
6 files changed, 124 insertions, 124 deletions
diff --git a/electron/src/renderer/components/InstallPalettes.vue b/electron/src/renderer/components/InstallPalettes.vue
new file mode 100644
index 00000000..73fd2865
--- /dev/null
+++ b/electron/src/renderer/components/InstallPalettes.vue
@@ -0,0 +1,49 @@
+<template>
+ <div>
+ <font-awesome-icon icon="palette" class="info-icon"/>
+ <p>
+ <translate>Ink/Stitch can install palettes for Inkscape matching the thread colors from popular machine embroidery thread manufacturers.
+ </translate>
+ </p>
+ <p>
+ <translate>Choose Inkscape directory</translate>
+ <input v-bind:value="path"/>
+ </p>
+ <button v-on:click="install">
+ <translate>Install</translate>
+ </button>
+ <button v-on:click="cancel">
+ <translate>Cancel</translate>
+ </button>
+ </div>
+</template>
+
+<script>
+const inkStitch = require("../../lib/api")
+
+export default {
+ name: "InstallPalettes",
+ data: function () {
+ return {
+ path: "",
+ }
+ },
+ methods: {
+ install() {
+ alert("install button clicked")
+ },
+ cancel() {
+ alert("cancel button clicked")
+ }
+ },
+ created: function () {
+ inkStitch.get("/install/default-path").then(response => {
+ this.path = response.data
+ })
+ }
+}
+</script>
+
+<style scoped>
+
+</style>
diff --git a/electron/src/renderer/main.js b/electron/src/renderer/main.js
index 3502ed6a..c5f39948 100644
--- a/electron/src/renderer/main.js
+++ b/electron/src/renderer/main.js
@@ -20,6 +20,7 @@ import {
faHorse,
faInfo,
faMinus,
+ faPalette,
faPause,
faPlay,
faPlus,
@@ -52,6 +53,7 @@ library.add(
faHorse,
faInfo,
faMinus,
+ faPalette,
faPause,
faPlay,
faPlus,
diff --git a/electron/src/renderer/router/index.js b/electron/src/renderer/router/index.js
index 3a27c4bc..63e2f415 100644
--- a/electron/src/renderer/router/index.js
+++ b/electron/src/renderer/router/index.js
@@ -5,14 +5,19 @@ Vue.use(Router)
export default new Router({
routes: [
- {
- path: '/simulator',
- name: 'simulator',
- component: require('@/components/Simulator').default
- },
- {
- path: '*',
- redirect: '/'
- }
+ {
+ path: '/simulator',
+ name: 'simulator',
+ component: require('@/components/Simulator').default
+ },
+ {
+ path: '/install',
+ name: 'install',
+ component: require('@/components/InstallPalettes').default
+ },
+ {
+ path: '*',
+ redirect: '/'
+ }
]
})
diff --git a/lib/api/install.py b/lib/api/install.py
new file mode 100644
index 00000000..f379f142
--- /dev/null
+++ b/lib/api/install.py
@@ -0,0 +1,42 @@
+import os
+import sys
+from glob import glob
+
+from flask import Blueprint, request
+
+from ..utils import get_bundled_dir, guess_inkscape_config_path
+
+install = Blueprint('install', __name__)
+
+
+@install.route('/palettes')
+def palettes():
+ base_path = request.json.get('path') or guess_inkscape_config_path()
+ path = os.path.join(base_path, 'palettes')
+ src_dir = get_bundled_dir('palettes')
+ copy_files(glob(os.path.join(src_dir, "*")), path)
+
+
+if sys.platform == "win32":
+ # If we try to just use shutil.copy it says the operation requires elevation.
+ def copy_files(files, dest):
+ import winutils
+
+ 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)
+
+
+@install.route('/default-path')
+def default_path():
+ return guess_inkscape_config_path()
diff --git a/lib/api/server.py b/lib/api/server.py
index c57a1785..bdfa4573 100644
--- a/lib/api/server.py
+++ b/lib/api/server.py
@@ -1,15 +1,16 @@
import errno
import logging
import socket
-from threading import Thread
import time
+from threading import Thread
-from flask import Flask, request, g
import requests
+from flask import Flask, g, request
-from ..utils.json import InkStitchJSONEncoder
+from .install import install
from .simulator import simulator
from .stitch_plan import stitch_plan
+from ..utils.json import InkStitchJSONEncoder
class APIServer(Thread):
@@ -31,6 +32,7 @@ class APIServer(Thread):
self.app.register_blueprint(simulator, url_prefix="/simulator")
self.app.register_blueprint(stitch_plan, url_prefix="/stitch_plan")
+ self.app.register_blueprint(install, url_prefix="/install")
@self.app.before_request
def store_extension():
diff --git a/lib/extensions/install.py b/lib/extensions/install.py
index f9ffe958..9756fb83 100644
--- a/lib/extensions/install.py
+++ b/lib/extensions/install.py
@@ -1,116 +1,16 @@
-# -*- coding: UTF-8 -*-
+from .base import InkstitchExtension
+from ..api import APIServer
+from ..gui import open_url
-import sys
-import traceback
-import os
-from glob import glob
-import wx
-import inkex
-from ..utils import guess_inkscape_config_path, get_bundled_dir
-from ..i18n import _
-
-
-class InstallerFrame(wx.Frame):
- def __init__(self, *args, **kwargs):
- wx.Frame.__init__(self, *args, **kwargs)
-
- self.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:') +
- u"\n\n • " + _("thread manufacturer color palettes") +
- u"\n • " + _("Ink/Stitch visual commands (Object -> Symbols...)"))
-
- 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)
-
- 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)
-
- panel.SetSizer(sizer)
- panel.Layout()
-
- 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):
- if sys.platform == "win32":
- # On windows, the default icon shows as a broken image. No idea
- # why. Workaround: don't show an icon.
- style = wx.ICON_NONE
- else:
- style = 0
-
- try:
- self.install_addons('palettes')
- self.install_addons('symbols')
- except Exception:
- wx.MessageDialog(self,
- _('Inkscape add-on installation failed') + ': \n' + traceback.format_exc(),
- _('Installation Failed'),
- wx.OK | style).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 | style).ShowModal()
-
- self.Destroy()
-
- def install_addons(self, type):
- path = os.path.join(self.path, type)
- src_dir = get_bundled_dir(type)
- self.copy_files(glob(os.path.join(src_dir, "*")), path)
-
- 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
-
- if not os.path.exists(dest):
- os.makedirs(dest)
-
- 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):
- @classmethod
- def name(cls):
- return "install"
+class Install(InkstitchExtension):
+ def __init__(self):
+ InkstitchExtension.__init__(self)
def effect(self):
- app = wx.App()
- installer_frame = InstallerFrame(None, title=_("Ink/Stitch Add-ons Installer"), size=(550, 250))
- installer_frame.Show()
- app.MainLoop()
+ api_server = APIServer(self)
+ port = api_server.start_server()
+ electron = open_url("/install?port=%d" % port)
+ electron.wait()
+ api_server.stop()
+ api_server.join()