From 98bc2e2ff9c843a64c3db355290ed541e6708312 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Fri, 29 Jul 2022 18:17:50 -0400 Subject: add preferences UI including cache settings --- lib/extensions/__init__.py | 4 ++-- lib/extensions/base.py | 9 +++++++++ lib/extensions/embroider_settings.py | 27 -------------------------- lib/extensions/preferences.py | 37 ++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 29 deletions(-) delete mode 100644 lib/extensions/embroider_settings.py create mode 100644 lib/extensions/preferences.py (limited to 'lib/extensions') diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index 6f42a349..f9f6072b 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -17,7 +17,7 @@ from .cut_satin import CutSatin from .cutwork_segmentation import CutworkSegmentation from .density_map import DensityMap from .duplicate_params import DuplicateParams -from .embroider_settings import EmbroiderSettings +from .preferences import Preferences from .fill_to_stroke import FillToStroke from .flip import Flip from .generate_palette import GeneratePalette @@ -96,5 +96,5 @@ __all__ = extensions = [StitchPlanPreview, Simulator, Reorder, DuplicateParams, - EmbroiderSettings, + Preferences, CutworkSegmentation] diff --git a/lib/extensions/base.py b/lib/extensions/base.py index c2f76b27..7b3c6f1c 100644 --- a/lib/extensions/base.py +++ b/lib/extensions/base.py @@ -23,6 +23,7 @@ from ..svg import generate_unique_id from ..svg.tags import (CONNECTOR_TYPE, EMBROIDERABLE_TAGS, INKSCAPE_GROUPMODE, NOT_EMBROIDERABLE_TAGS, SVG_CLIPPATH_TAG, SVG_DEFS_TAG, SVG_GROUP_TAG, SVG_MASK_TAG) +from ..utils.settings import DEFAULT_METADATA, global_settings SVG_METADATA_TAG = inkex.addNS("metadata", "svg") @@ -52,9 +53,14 @@ class InkStitchMetadata(MutableMapping): """ def __init__(self, document): + super().__init__() self.document = document self.metadata = document.metadata + for setting in DEFAULT_METADATA: + if self[setting] is None: + self[setting] = global_settings[f'default_{setting}'] + # Because this class inherints from MutableMapping, all we have to do is # implement these five methods and we get a full dict-like interface. @@ -96,6 +102,9 @@ class InkStitchMetadata(MutableMapping): return i + 1 + def __json__(self): + return dict(self) + class InkstitchExtension(inkex.Effect): """Base class for Inkstitch extensions. Not intended for direct use.""" diff --git a/lib/extensions/embroider_settings.py b/lib/extensions/embroider_settings.py deleted file mode 100644 index cdf18991..00000000 --- a/lib/extensions/embroider_settings.py +++ /dev/null @@ -1,27 +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 .base import InkstitchExtension - - -class EmbroiderSettings(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): - 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 diff --git a/lib/extensions/preferences.py b/lib/extensions/preferences.py new file mode 100644 index 00000000..8a06f829 --- /dev/null +++ b/lib/extensions/preferences.py @@ -0,0 +1,37 @@ +# 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 .base import InkstitchExtension +from ..api import APIServer +from ..gui import open_url + + +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=%d" % 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 -- cgit v1.2.3