From e35cacc5ccd4830c82def2f6f4797bf971191a95 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 15 Aug 2023 22:59:04 -0400 Subject: convert Preferences to wxPython --- lib/extensions/preferences.py | 26 +--- lib/gui/preferences.py | 217 ++++++++++++++++++++++++++++++ lib/gui/preferences.wxg | 305 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 525 insertions(+), 23 deletions(-) create mode 100644 lib/gui/preferences.py create mode 100644 lib/gui/preferences.wxg diff --git a/lib/extensions/preferences.py b/lib/extensions/preferences.py index 44c1b5aa..b78537c8 100644 --- a/lib/extensions/preferences.py +++ b/lib/extensions/preferences.py @@ -4,8 +4,7 @@ # 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 +from ..gui.preferences import PreferencesApp class Preferences(InkstitchExtension): @@ -13,25 +12,6 @@ class Preferences(InkstitchExtension): This saves embroider settings into the metadata of the file ''' - def __init__(self, *args, **kwargs): - InkstitchExtension.__init__(self, *args, **kwargs) - self.arg_parser.add_argument("-c", "--collapse_len_mm", - action="store", type=float, - dest="collapse_length_mm", default=3.0, - help="max collapse length (mm)") - self.arg_parser.add_argument("-l", "--min_stitch_len_mm", - action="store", type=float, - dest="min_stitch_len_mm", default=0, - help="minimum stitch length (mm)") - def effect(self): - api_server = APIServer(self) - port = api_server.start_server() - electron = open_url("/preferences", port) - electron.wait() - api_server.stop() - api_server.join() - - # self.metadata = self.get_inkstitch_metadata() - # self.metadata['collapse_len_mm'] = self.options.collapse_length_mm - # self.metadata['min_stitch_len_mm'] = self.options.min_stitch_len_mm + app = PreferencesApp(self) + app.MainLoop() diff --git a/lib/gui/preferences.py b/lib/gui/preferences.py new file mode 100644 index 00000000..a93f0d6d --- /dev/null +++ b/lib/gui/preferences.py @@ -0,0 +1,217 @@ +# Authors: see git history +# +# Copyright (c) 2010 Authors +# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. + +import wx + +from ..i18n import _ +from ..utils.cache import get_stitch_plan_cache +from ..utils.settings import global_settings + + +class PreferencesFrame(wx.Frame): + def __init__(self, *args, **kwargs): + self.extension = kwargs.pop("extension") + wx.Frame.__init__(self, None, wx.ID_ANY, _("Preferences"), *args, **kwargs) + self.SetTitle(_("frame")) + + metadata = self.extension.get_inkstitch_metadata() + + self.panel_1 = wx.Panel(self, wx.ID_ANY) + + main_sizer = wx.BoxSizer(wx.VERTICAL) + + self.notebook = wx.Notebook(self.panel_1, wx.ID_ANY) + main_sizer.Add(self.notebook, 1, wx.ALL | wx.EXPAND, 10) + + self.this_svg_page = wx.Panel(self.notebook, wx.ID_ANY) + self.notebook.AddPage(self.this_svg_page, _("This SVG")) + + sizer_1 = wx.BoxSizer(wx.VERTICAL) + + # add space above and below to center sizer_2 vertically + sizer_1.Add((0, 20), 1, wx.EXPAND, 0) + + sizer_2 = wx.FlexGridSizer(2, 4, 15, 10) + sizer_1.Add(sizer_2, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 20) + + label_1 = wx.StaticText(self.this_svg_page, wx.ID_ANY, _("Minimum jump stitch length"), style=wx.ALIGN_LEFT) + label_1.SetToolTip(_("Jump stitches smaller than this will be treated as normal stitches.")) + sizer_2.Add(label_1, 1, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 15) + + self.minimum_jump_stitch_length = wx.SpinCtrlDouble( + self.this_svg_page, wx.ID_ANY, inc=0.1, + value=str(metadata['collapse_len_mm'] or global_settings['default_collapse_len_mm']), + style=wx.ALIGN_RIGHT | wx.SP_ARROW_KEYS + ) + self.minimum_jump_stitch_length.SetDigits(1) + sizer_2.Add(self.minimum_jump_stitch_length, 0, wx.ALIGN_CENTER_VERTICAL, 0) + + label_2 = wx.StaticText(self.this_svg_page, wx.ID_ANY, _("mm")) + sizer_2.Add(label_2, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 15) + + self.button_1 = wx.Button(self.this_svg_page, wx.ID_ANY, _("Set As Default")) + sizer_2.Add(self.button_1, 0, wx.ALIGN_CENTER_VERTICAL, 0) + + label_3 = wx.StaticText(self.this_svg_page, wx.ID_ANY, _("Minimum stitch length")) + sizer_2.Add(label_3, 0, 0, 0) + + self.minimum_stitch_length = wx.SpinCtrlDouble( + self.this_svg_page, wx.ID_ANY, inc=0.1, + value=str(metadata['min_stitch_len_mm'] or global_settings['default_min_stitch_len_mm']), + style=wx.ALIGN_RIGHT | wx.SP_ARROW_KEYS + ) + self.minimum_stitch_length.SetDigits(1) + sizer_2.Add(self.minimum_stitch_length, 0, wx.ALIGN_CENTER_VERTICAL, 0) + + label_4 = wx.StaticText(self.this_svg_page, wx.ID_ANY, _("mm")) + sizer_2.Add(label_4, 0, wx.ALIGN_CENTER_VERTICAL, 0) + + self.button_2 = wx.Button(self.this_svg_page, wx.ID_ANY, _("Set As Default")) + sizer_2.Add(self.button_2, 0, wx.ALIGN_CENTER_VERTICAL, 0) + + sizer_1.Add((0, 20), 1, wx.EXPAND, 0) + + self.global_page = wx.Panel(self.notebook, wx.ID_ANY) + self.notebook.AddPage(self.global_page, _("Global")) + + sizer_3 = wx.BoxSizer(wx.VERTICAL) + + # add space above and below to center sizer_4 vertically + sizer_3.Add((0, 20), 1, wx.EXPAND, 0) + + sizer_4 = wx.FlexGridSizer(3, 4, 15, 10) + sizer_3.Add(sizer_4, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 20) + + label_5 = wx.StaticText(self.global_page, wx.ID_ANY, _("Default minimum jump stitch length"), style=wx.ALIGN_LEFT) + label_5.SetToolTip(_("Jump stitches smaller than this will be treated as normal stitches.")) + sizer_4.Add(label_5, 1, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 15) + + self.default_minimum_jump_stitch_length = wx.SpinCtrlDouble( + self.global_page, wx.ID_ANY, inc=0.1, + value=str(global_settings['default_collapse_len_mm']), + style=wx.ALIGN_RIGHT | wx.SP_ARROW_KEYS + ) + self.default_minimum_jump_stitch_length.SetDigits(1) + sizer_4.Add(self.default_minimum_jump_stitch_length, 0, wx.ALIGN_CENTER_VERTICAL, 0) + + label_6 = wx.StaticText(self.global_page, wx.ID_ANY, _("mm")) + sizer_4.Add(label_6, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 15) + + sizer_4.Add((0, 0), 0, 0, 0) + + label_7 = wx.StaticText(self.global_page, wx.ID_ANY, _("Minimum stitch length")) + sizer_4.Add(label_7, 0, wx.ALIGN_CENTER_VERTICAL, 0) + + self.default_minimum_stitch_length = wx.SpinCtrlDouble( + self.global_page, wx.ID_ANY, inc=0.1, + value=str(global_settings['default_min_stitch_len_mm']), + style=wx.ALIGN_RIGHT | wx.SP_ARROW_KEYS + ) + self.default_minimum_stitch_length.SetDigits(1) + sizer_4.Add(self.default_minimum_stitch_length, 0, wx.ALIGN_CENTER_VERTICAL, 0) + + label_8 = wx.StaticText(self.global_page, wx.ID_ANY, _("mm")) + sizer_4.Add(label_8, 0, wx.ALIGN_CENTER_VERTICAL, 0) + + sizer_4.Add((0, 20), 0, 0, 0) + + label_9 = wx.StaticText(self.global_page, wx.ID_ANY, _("Stitch plan cache size"), style=wx.ALIGN_LEFT) + label_9.SetToolTip(_("Jump stitches smaller than this will be treated as normal stitches.")) + sizer_4.Add(label_9, 1, wx.ALIGN_CENTER_VERTICAL, 0) + + self.stitch_plan_cache_size = wx.SpinCtrl( + self.global_page, wx.ID_ANY, + value=str(global_settings['cache_size']), + style=wx.ALIGN_RIGHT | wx.SP_ARROW_KEYS + ) + self.stitch_plan_cache_size.SetIncrement(10) + sizer_4.Add(self.stitch_plan_cache_size, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT, 0) + + label_10 = wx.StaticText(self.global_page, wx.ID_ANY, _("MB")) + sizer_4.Add(label_10, 0, wx.ALIGN_CENTER_VERTICAL, 0) + + self.clear_cache_button = wx.Button(self.global_page, wx.ID_ANY, _("Clear Stitch Plan Cache")) + sizer_4.Add(self.clear_cache_button, 0, wx.ALIGN_CENTER_VERTICAL, 0) + + sizer_3.Add((0, 0), 1, wx.EXPAND, 0) + + button_sizer = wx.BoxSizer(wx.HORIZONTAL) + main_sizer.Add(button_sizer, 0, wx.BOTTOM | wx.EXPAND | wx.LEFT | wx.RIGHT, 10) + + button_sizer.Add((0, 0), 1, 0, 0) + + self.cancel_button = wx.Button(self.panel_1, wx.ID_CANCEL, "") + button_sizer.Add(self.cancel_button, 0, wx.RIGHT, 10) + + self.ok_button = wx.Button(self.panel_1, wx.ID_OK, "") + button_sizer.Add(self.ok_button, 0, 0, 0) + + sizer_4.AddGrowableCol(0) + + self.global_page.SetSizer(sizer_3) + + sizer_2.AddGrowableCol(0) + + self.this_svg_page.SetSizer(sizer_1) + + self.panel_1.SetSizer(main_sizer) + + main_sizer.Fit(self) + self.Layout() + self.SetSizeHints(main_sizer.CalcMin()) + + self.Bind(wx.EVT_BUTTON, self.set_as_default_minimum_jump_stitch_length, self.button_1) + self.Bind(wx.EVT_BUTTON, self.set_as_default_minimum_stitch_length, self.button_2) + self.Bind(wx.EVT_BUTTON, self.clear_cache, self.clear_cache_button) + self.Bind(wx.EVT_BUTTON, self.cancel_button_clicked, self.cancel_button) + self.Bind(wx.EVT_BUTTON, self.ok_button_clicked, self.ok_button) + + def set_as_default_minimum_jump_stitch_length(self, event): + self.default_minimum_jump_stitch_length.SetValue(self.minimum_jump_stitch_length.GetValue()) + + def set_as_default_minimum_stitch_length(self, event): + self.default_minimum_stitch_length.SetValue(self.minimum_stitch_length.GetValue()) + + def clear_cache(self, event): + stitch_plan_cache = get_stitch_plan_cache() + stitch_plan_cache.clear(retry=True) + + def apply(self): + metadata = self.extension.get_inkstitch_metadata() + metadata['min_stitch_len_mm'] = self.minimum_stitch_length.GetValue() + metadata['collapse_len_mm'] = self.minimum_jump_stitch_length.GetValue() + + global_settings['default_min_stitch_len_mm'] = self.default_minimum_stitch_length.GetValue() + global_settings['default_collapse_len_mm'] = self.default_minimum_jump_stitch_length.GetValue() + global_settings['cache_size'] = self.stitch_plan_cache_size.GetValue() + + # cache size may have changed + stitch_plan_cache = get_stitch_plan_cache() + stitch_plan_cache.size_limit = int(global_settings['cache_size'] * 1024 * 1024) + stitch_plan_cache.cull() + + def cancel_button_clicked(self, event): + self.Destroy() + + def ok_button_clicked(self, event): + self.apply() + self.Destroy() + + +class PreferencesApp(wx.App): + def __init__(self, extension): + self.extension = extension + super().__init__() + + def OnInit(self): + self.frame = PreferencesFrame(extension=self.extension) + self.SetTopWindow(self.frame) + self.frame.Show() + return True + + +if __name__ == "__main__": + app = PreferencesApp(None) + app.MainLoop() diff --git a/lib/gui/preferences.wxg b/lib/gui/preferences.wxg new file mode 100644 index 00000000..2ed89ad5 --- /dev/null +++ b/lib/gui/preferences.wxg @@ -0,0 +1,305 @@ + + + + + + self.SetSizeHints(main_sizer.CalcMin()) + frame + + + + wxVERTICAL + + + 10 + wxALL|wxEXPAND + + + + This SVG + Global + + + + + wxVERTICAL + + + 0 + wxEXPAND + + # add space above and below to center sizer_2 vertically + 0 + 0 + + + + + 20 + wxLEFT|wxRIGHT|wxEXPAND + + 2 + 4 + 15 + 10 + 0 + + + 15 + wxRIGHT|wxALIGN_CENTER_VERTICAL + + Jump stitches smaller than this will be treated as normal stitches. + + + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + 0.0 + 1 + + + + + 15 + wxRIGHT|wxALIGN_CENTER_VERTICAL + + + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + set_as_default_minimum_jump_stitch_length + + + + + + + 0 + + + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + 0.0, 100.0 + 0.0 + 1 + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + set_as_default_minimum_stitch_length + + + + + + + + + 0 + wxEXPAND + + 0 + 0 + + + + + + + + wxVERTICAL + + + 0 + wxEXPAND + + # add space above and below to center sizer_4 vertically + 0 + 0 + + + + + 20 + wxLEFT|wxRIGHT|wxEXPAND + + 3 + 4 + 15 + 10 + 0 + + + 15 + wxRIGHT|wxALIGN_CENTER_VERTICAL + + Jump stitches smaller than this will be treated as normal stitches. + + + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + 0.0, 100.0 + 0.0 + 1 + + + + + 15 + wxRIGHT|wxALIGN_CENTER_VERTICAL + + + + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + 0.0, 100.0 + 0.0 + 1 + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + + + + + + 0 + wxALIGN_CENTER_VERTICAL + + Jump stitches smaller than this will be treated as normal stitches. + + + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + 0.0, 100.0 + 0.0 + 1 + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + + + + + 0 + wxALIGN_CENTER_VERTICAL + + + + + + + + + 0 + wxEXPAND + + 0 + 0 + + + + + + + + + 10 + wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND + + wxHORIZONTAL + + + 0 + + 0 + 0 + + + + + 10 + wxRIGHT + + + CANCEL + + + + + 0 + + + OK + + + + + + + + -- cgit v1.2.3 From 09812b1e9e064778868a5019bbdd9580562b86f6 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Tue, 15 Aug 2023 23:00:48 -0400 Subject: remove electron Preferences --- electron/src/renderer/components/Preferences.vue | 229 ----------------------- electron/src/renderer/router/index.js | 5 - lib/api/preferences.py | 41 ---- lib/api/server.py | 2 - 4 files changed, 277 deletions(-) delete mode 100644 electron/src/renderer/components/Preferences.vue delete mode 100644 lib/api/preferences.py diff --git a/electron/src/renderer/components/Preferences.vue b/electron/src/renderer/components/Preferences.vue deleted file mode 100644 index 101f1b8a..00000000 --- a/electron/src/renderer/components/Preferences.vue +++ /dev/null @@ -1,229 +0,0 @@ - - - - - - - diff --git a/electron/src/renderer/router/index.js b/electron/src/renderer/router/index.js index e90a8fd5..a38404da 100644 --- a/electron/src/renderer/router/index.js +++ b/electron/src/renderer/router/index.js @@ -12,11 +12,6 @@ const routes = [ name: 'simulator', component: () => import('../components/Simulator.vue') }, - { - path: '/preferences', - name: 'preferences', - component: () => import('../components/Preferences.vue') - }, { path: '/:pathMatch(.*)*', name: 'NotFound', diff --git a/lib/api/preferences.py b/lib/api/preferences.py deleted file mode 100644 index bc8328b8..00000000 --- a/lib/api/preferences.py +++ /dev/null @@ -1,41 +0,0 @@ -# Authors: see git history -# -# Copyright (c) 2010 Authors -# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. - -from flask import Blueprint, g, jsonify, request - -from ..utils.cache import get_stitch_plan_cache -from ..utils.settings import global_settings - -preferences = Blueprint('preferences', __name__) - - -@preferences.route('/', methods=["POST"]) -def update_preferences(): - metadata = g.extension.get_inkstitch_metadata() - metadata.update(request.json['this_svg_settings']) - global_settings.update(request.json['global_settings']) - - # cache size may have changed - stitch_plan_cache = get_stitch_plan_cache() - stitch_plan_cache.size_limit = global_settings['cache_size'] * 1024 * 1024 - stitch_plan_cache.cull() - - return jsonify({"status": "success"}) - - -@preferences.route('/', methods=["GET"]) -def get_preferences(): - metadata = g.extension.get_inkstitch_metadata() - return jsonify({"status": "success", - "this_svg_settings": metadata, - "global_settings": global_settings - }) - - -@preferences.route('/clear_cache', methods=["POST"]) -def clear_cache(): - stitch_plan_cache = get_stitch_plan_cache() - stitch_plan_cache.clear(retry=True) - return jsonify({"status": "success"}) diff --git a/lib/api/server.py b/lib/api/server.py index 26efa521..5625d77d 100644 --- a/lib/api/server.py +++ b/lib/api/server.py @@ -18,7 +18,6 @@ from werkzeug.serving import make_server from ..utils.json import InkStitchJSONProvider from .simulator import simulator from .stitch_plan import stitch_plan -from .preferences import preferences from .page_specs import page_specs from .lang import languages # this for electron axios @@ -50,7 +49,6 @@ 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(preferences, url_prefix="/preferences") self.app.register_blueprint(page_specs, url_prefix="/page_specs") self.app.register_blueprint(languages, url_prefix="/languages") -- cgit v1.2.3