kopia lustrzana https://github.com/inkstitch/inkstitch
Merge pull request #2479 from inkstitch/lexelby/unelectron-preferences
convert Preferences to wxPythonpull/2489/head
commit
a311774cbc
|
@ -1,229 +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.
|
||||
|
||||
-->
|
||||
|
||||
<template>
|
||||
<v-card elevation="8" rounded="lg" class="preferences-card">
|
||||
<v-card-title class="text-center justify-center py-6">
|
||||
<h1 class="font-weight-bold text-h2 text-basil">
|
||||
Ink/Stitch Settings
|
||||
</h1>
|
||||
</v-card-title>
|
||||
|
||||
<v-card-text>
|
||||
<v-tabs v-model="tab" bg-color="transparent" class="text-primary" grow>
|
||||
<v-tab key="this_svg_settings">
|
||||
This SVG
|
||||
</v-tab>
|
||||
<v-tab key="global_settings">
|
||||
Global
|
||||
</v-tab>
|
||||
</v-tabs>
|
||||
|
||||
<v-window v-model="tab">
|
||||
<v-window-item key="this_svg_settings">
|
||||
<v-card flat>
|
||||
<v-card-text>
|
||||
<table>
|
||||
<tr>
|
||||
<td class="label">
|
||||
<v-tooltip bottom>
|
||||
<template v-slot:activator="{ props }">
|
||||
<label for="collapse_len_mm" v-bind="props"><translate>Minimum jump stitch length</translate></label>
|
||||
</template>
|
||||
<label for="collapse_len_mm"><translate>Jump stitches smaller than this will be treated as normal stitches.</translate></label>
|
||||
</v-tooltip>
|
||||
</td>
|
||||
<td class="preference">
|
||||
<v-text-field hide-details id="collapse_len_mm" @change="updateSettings" v-model.number="this_svg_settings.collapse_len_mm" type="number"></v-text-field>
|
||||
</td>
|
||||
<td class="unit">
|
||||
mm
|
||||
</td>
|
||||
<td class="button">
|
||||
<v-btn small @click="setDefault('collapse_len_mm')">
|
||||
<translate>set as default</translate>
|
||||
</v-btn>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label">
|
||||
<v-tooltip bottom>
|
||||
<template v-slot:activator="{ props }">
|
||||
<label for="min_stitch_len_mm" v-bind="props"><translate>Minimum stitch length</translate></label>
|
||||
</template>
|
||||
<label for="min_stitch_len_mm"><translate>Drop stitches smaller than this value.</translate></label>
|
||||
</v-tooltip>
|
||||
</td>
|
||||
<td class="preference">
|
||||
<v-text-field hide-details id="min_stitch_len_mm" @change="updateSettings" v-model.number="this_svg_settings.min_stitch_len_mm" type="number"></v-text-field>
|
||||
</td>
|
||||
<td class="unit">
|
||||
mm
|
||||
</td>
|
||||
<td class="button">
|
||||
<v-btn small @click="setDefault('min_stitch_len_mm')">
|
||||
<translate>set as default</translate>
|
||||
</v-btn>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-window-item>
|
||||
<v-window-item key="global_settings">
|
||||
<v-card flat>
|
||||
<v-card-text>
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<v-tooltip bottom>
|
||||
<template v-slot:activator="{ props }">
|
||||
<label for="default_collapse_len_mm" v-bind="props"><translate>Default minimum jump stitch length</translate></label>
|
||||
</template>
|
||||
<label for="default_collapse_len_mm"><translate>Used for new SVGs.</translate></label>
|
||||
</v-tooltip>
|
||||
</td>
|
||||
<td class="preference">
|
||||
<v-text-field hide-details id="default_min_stitch_len_mm" @change="updateSettings" v-model.number="global_settings.default_collapse_len_mm" type="number"></v-text-field>
|
||||
</td>
|
||||
<td class="unit">
|
||||
mm
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<v-tooltip bottom>
|
||||
<template v-slot:activator="{ props }">
|
||||
<label for="default_min_stitch_len_mm" v-bind="props"><translate>Default minimum stitch length</translate></label>
|
||||
</template>
|
||||
<label for="default_min_stitch_len_mm"><translate>Used for new SVGs.</translate></label>
|
||||
</v-tooltip>
|
||||
</td>
|
||||
<td class="preference">
|
||||
<v-text-field hide-details id="default_min_stitch_len_mm" @change="updateSettings" v-model.number="global_settings.default_min_stitch_len_mm" type="number"></v-text-field>
|
||||
</td>
|
||||
<td class="unit">
|
||||
mm
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<v-tooltip bottom>
|
||||
<template v-slot:activator="{ props }">
|
||||
<label for="cache_size" v-bind="props"><translate>Stitch plan cache size</translate></label>
|
||||
</template>
|
||||
<label for="default_min_stitch_len_mm"><translate>The greater the number, the more stitch plans can be cached, speeding up stitch plan calculation. Default: 100</translate></label>
|
||||
</v-tooltip>
|
||||
</td>
|
||||
<td class="preference">
|
||||
<v-text-field hide-details id="cache_size" @change="updateSettings" v-model.number="global_settings.cache_size" type="number"></v-text-field>
|
||||
</td>
|
||||
<td class="unit">
|
||||
MB
|
||||
</td>
|
||||
<td class="button">
|
||||
<v-btn small @click="clearCache"><translate>clear stitch plan cache</translate></v-btn>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-window-item>
|
||||
</v-window>
|
||||
</v-card-text>
|
||||
<v-card-actions>
|
||||
<v-btn text color="primary" @click="close"><translate>done</translate></v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { inkStitch } from '../../lib/api.js'
|
||||
export default {
|
||||
name: "Preferences",
|
||||
data: function () {
|
||||
return {
|
||||
tab: "this_svg_settings",
|
||||
this_svg_settings: {
|
||||
collapse_len_mm: null,
|
||||
min_stitch_len_mm: null,
|
||||
},
|
||||
global_settings: {
|
||||
default_min_stitch_len_mm: null,
|
||||
default_collapse_len_mm: null,
|
||||
cache_size: null
|
||||
}
|
||||
}
|
||||
},
|
||||
created: function () {
|
||||
inkStitch.get("preferences/").then(response => {
|
||||
Object.assign(this.this_svg_settings, response.data.this_svg_settings)
|
||||
Object.assign(this.global_settings, response.data.global_settings)
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
setDefault(preference_name) {
|
||||
console.log(`set default: ${preference_name}`)
|
||||
this.global_settings[`default_${preference_name}`] = this.this_svg_settings[preference_name]
|
||||
this.updateSettings()
|
||||
},
|
||||
updateSettings() {
|
||||
console.log(this.this_svg_settings)
|
||||
console.log(this.global_settings)
|
||||
inkStitch.post("preferences/", {
|
||||
this_svg_settings: this.this_svg_settings,
|
||||
global_settings: this.global_settings
|
||||
}).then(response => {
|
||||
console.log(response)
|
||||
})
|
||||
},
|
||||
clearCache() {
|
||||
inkStitch.post("preferences/clear_cache").then(response => {
|
||||
console.log(response)
|
||||
})
|
||||
},
|
||||
close() {
|
||||
window.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.preferences-card {
|
||||
margin-left: 20%;
|
||||
margin-right: 20%;
|
||||
margin-top: 5%;
|
||||
}
|
||||
|
||||
td.label {
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
td.preference {
|
||||
padding-right: 4px;
|
||||
padding-left: 16px;
|
||||
max-width: 15em;
|
||||
min-width: 8em;
|
||||
}
|
||||
|
||||
td.preference :deep(input) {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
td.unit {
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
td.button {
|
||||
vertical-align: bottom;
|
||||
padding-left: 12px;
|
||||
}
|
||||
</style>
|
|
@ -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',
|
||||
|
|
|
@ -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"})
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
|
@ -0,0 +1,305 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- generated by wxGlade 1.0.5 on Tue Aug 15 00:11:05 2023 -->
|
||||
|
||||
<application class="PreferencesApp" encoding="UTF-8" for_version="3.0" header_extension=".h" indent_amount="4" indent_symbol="space" is_template="0" language="python" mark_blocks="1" name="app" option="0" overwrite="1" path="/home/lex/repos/inkstitch/lib/gui/preferences.py" source_extension=".cpp" top_window="frame" use_gettext="1" use_new_namespace="1">
|
||||
<object class="PreferencesFrame" name="frame" base="EditFrame">
|
||||
<extracode_post>self.SetSizeHints(main_sizer.CalcMin())</extracode_post>
|
||||
<title>frame</title>
|
||||
<style>wxDEFAULT_FRAME_STYLE</style>
|
||||
<object class="wxPanel" name="panel_1" base="EditPanel">
|
||||
<object class="wxBoxSizer" name="main_sizer" base="EditBoxSizer">
|
||||
<orient>wxVERTICAL</orient>
|
||||
<object class="sizeritem">
|
||||
<option>1</option>
|
||||
<border>10</border>
|
||||
<flag>wxALL|wxEXPAND</flag>
|
||||
<object class="wxNotebook" name="notebook" base="EditNotebook">
|
||||
<style>wxNB_TOP</style>
|
||||
<tabs>
|
||||
<tab window="this_svg_page">This SVG</tab>
|
||||
<tab window="global_page">Global</tab>
|
||||
</tabs>
|
||||
<object class="wxPanel" name="this_svg_page" base="EditPanel">
|
||||
<style>wxTAB_TRAVERSAL</style>
|
||||
<object class="wxBoxSizer" name="sizer_1" base="EditBoxSizer">
|
||||
<orient>wxVERTICAL</orient>
|
||||
<object class="sizeritem">
|
||||
<option>1</option>
|
||||
<border>0</border>
|
||||
<flag>wxEXPAND</flag>
|
||||
<object class="spacer" name="spacer" base="EditSpacer">
|
||||
<extracode_pre># add space above and below to center sizer_2 vertically</extracode_pre>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>20</border>
|
||||
<flag>wxLEFT|wxRIGHT|wxEXPAND</flag>
|
||||
<object class="wxFlexGridSizer" name="sizer_2" base="EditFlexGridSizer">
|
||||
<rows>2</rows>
|
||||
<cols>4</cols>
|
||||
<vgap>15</vgap>
|
||||
<hgap>10</hgap>
|
||||
<growable_cols>0</growable_cols>
|
||||
<object class="sizeritem">
|
||||
<option>1</option>
|
||||
<border>15</border>
|
||||
<flag>wxRIGHT|wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxStaticText" name="label_1" base="EditStaticText">
|
||||
<tooltip>Jump stitches smaller than this will be treated as normal stitches.</tooltip>
|
||||
<style>wxALIGN_LEFT</style>
|
||||
<label>Minimum jump stitch length</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxSpinCtrlDouble" name="minimum_jump_stitch_length" base="EditSpinCtrlDouble">
|
||||
<style>wxSP_ARROW_KEYS|wxALIGN_RIGHT</style>
|
||||
<value>0.0</value>
|
||||
<digits>1</digits>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>15</border>
|
||||
<flag>wxRIGHT|wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxStaticText" name="label_2" base="EditStaticText">
|
||||
<label>mm</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxButton" name="button_1" base="EditButton">
|
||||
<events>
|
||||
<handler event="EVT_BUTTON">set_as_default_minimum_jump_stitch_length</handler>
|
||||
</events>
|
||||
<label>Set As Default</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<object class="wxStaticText" name="label_3" base="EditStaticText">
|
||||
<label>Minimum stitch length</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxSpinCtrlDouble" name="minimum_stitch_length" base="EditSpinCtrlDouble">
|
||||
<style>wxSP_ARROW_KEYS|wxALIGN_RIGHT</style>
|
||||
<range>0.0, 100.0</range>
|
||||
<value>0.0</value>
|
||||
<digits>1</digits>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxStaticText" name="label_4" base="EditStaticText">
|
||||
<label>mm</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxButton" name="button_2" base="EditButton">
|
||||
<events>
|
||||
<handler event="EVT_BUTTON">set_as_default_minimum_stitch_length</handler>
|
||||
</events>
|
||||
<label>Set As Default</label>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>1</option>
|
||||
<border>0</border>
|
||||
<flag>wxEXPAND</flag>
|
||||
<object class="spacer" name="spacer" base="EditSpacer">
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="wxPanel" name="global_page" base="EditPanel">
|
||||
<style>wxTAB_TRAVERSAL</style>
|
||||
<object class="wxBoxSizer" name="sizer_3" base="EditBoxSizer">
|
||||
<orient>wxVERTICAL</orient>
|
||||
<object class="sizeritem">
|
||||
<option>1</option>
|
||||
<border>0</border>
|
||||
<flag>wxEXPAND</flag>
|
||||
<object class="spacer" name="spacer" base="EditSpacer">
|
||||
<extracode_pre># add space above and below to center sizer_4 vertically</extracode_pre>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>20</border>
|
||||
<flag>wxLEFT|wxRIGHT|wxEXPAND</flag>
|
||||
<object class="wxFlexGridSizer" name="sizer_4" base="EditFlexGridSizer">
|
||||
<rows>3</rows>
|
||||
<cols>4</cols>
|
||||
<vgap>15</vgap>
|
||||
<hgap>10</hgap>
|
||||
<growable_cols>0</growable_cols>
|
||||
<object class="sizeritem">
|
||||
<option>1</option>
|
||||
<border>15</border>
|
||||
<flag>wxRIGHT|wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxStaticText" name="label_5" base="EditStaticText">
|
||||
<tooltip>Jump stitches smaller than this will be treated as normal stitches.</tooltip>
|
||||
<style>wxALIGN_LEFT</style>
|
||||
<label>Default minimum jump stitch length</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxSpinCtrlDouble" name="default_minimum_jump_stitch_length_copy" base="EditSpinCtrlDouble">
|
||||
<style>wxSP_ARROW_KEYS|wxALIGN_RIGHT</style>
|
||||
<range>0.0, 100.0</range>
|
||||
<value>0.0</value>
|
||||
<digits>1</digits>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>15</border>
|
||||
<flag>wxRIGHT|wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxStaticText" name="label_6" base="EditStaticText">
|
||||
<label>mm</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizerslot" />
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxStaticText" name="label_7" base="EditStaticText">
|
||||
<label>Minimum stitch length</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxSpinCtrlDouble" name="default_minimum_stitch_length" base="EditSpinCtrlDouble">
|
||||
<style>wxSP_ARROW_KEYS|wxALIGN_RIGHT</style>
|
||||
<range>0.0, 100.0</range>
|
||||
<value>0.0</value>
|
||||
<digits>1</digits>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxStaticText" name="label_8" base="EditStaticText">
|
||||
<label>mm</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizerslot" />
|
||||
<object class="sizeritem">
|
||||
<option>1</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxStaticText" name="label_9" base="EditStaticText">
|
||||
<tooltip>Jump stitches smaller than this will be treated as normal stitches.</tooltip>
|
||||
<style>wxALIGN_LEFT</style>
|
||||
<label>Stitch plan cache size</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxSpinCtrlDouble" name="stitch_plan_cache_size" base="EditSpinCtrlDouble">
|
||||
<style>wxSP_ARROW_KEYS|wxALIGN_RIGHT</style>
|
||||
<range>0.0, 100.0</range>
|
||||
<value>0.0</value>
|
||||
<digits>1</digits>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxStaticText" name="label_10" base="EditStaticText">
|
||||
<label>MB</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<flag>wxALIGN_CENTER_VERTICAL</flag>
|
||||
<object class="wxButton" name="button_3" base="EditButton">
|
||||
<label>Clear Stitch Plan Cache</label>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>1</option>
|
||||
<border>0</border>
|
||||
<flag>wxEXPAND</flag>
|
||||
<object class="spacer" name="spacer" base="EditSpacer">
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>10</border>
|
||||
<flag>wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND</flag>
|
||||
<object class="wxBoxSizer" name="button_sizer" base="EditBoxSizer">
|
||||
<orient>wxHORIZONTAL</orient>
|
||||
<object class="sizeritem">
|
||||
<option>1</option>
|
||||
<border>0</border>
|
||||
<object class="spacer" name="spacer" base="EditSpacer">
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>10</border>
|
||||
<flag>wxRIGHT</flag>
|
||||
<object class="wxButton" name="button_4" base="EditButton">
|
||||
<label>button_4</label>
|
||||
<stockitem>CANCEL</stockitem>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<option>0</option>
|
||||
<border>0</border>
|
||||
<object class="wxButton" name="button_5" base="EditButton">
|
||||
<label>button_5</label>
|
||||
<stockitem>OK</stockitem>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</application>
|
Ładowanie…
Reference in New Issue