1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
# 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(_("Preferences"))
self.SetWindowStyle(wx.FRAME_FLOAT_ON_PARENT | wx.DEFAULT_FRAME_STYLE)
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"))
this_svg_margin = wx.BoxSizer(wx.VERTICAL)
# add space above and below to center sizer_2 vertically
this_svg_margin.Add((0, 20), 1, wx.EXPAND, 0)
this_svg_grid = wx.FlexGridSizer(3, 4, 15, 10)
this_svg_margin.Add(this_svg_grid, 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."))
this_svg_grid.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 str(global_settings['default_collapse_len_mm']),
style=wx.ALIGN_RIGHT | wx.SP_ARROW_KEYS
)
self.minimum_jump_stitch_length.SetDigits(2)
this_svg_grid.Add(self.minimum_jump_stitch_length, 0, wx.ALIGN_CENTER_VERTICAL, 0)
label_2 = wx.StaticText(self.this_svg_page, wx.ID_ANY, _("mm"))
this_svg_grid.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"))
this_svg_grid.Add(self.button_1, 0, wx.ALIGN_CENTER_VERTICAL, 0)
label_3 = wx.StaticText(self.this_svg_page, wx.ID_ANY, _("Minimum stitch length"))
this_svg_grid.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 str(global_settings['default_min_stitch_len_mm']),
style=wx.ALIGN_RIGHT | wx.SP_ARROW_KEYS
)
self.minimum_stitch_length.SetDigits(2)
this_svg_grid.Add(self.minimum_stitch_length, 0, wx.ALIGN_CENTER_VERTICAL, 0)
label_4 = wx.StaticText(self.this_svg_page, wx.ID_ANY, _("mm"))
this_svg_grid.Add(label_4, 0, wx.ALIGN_CENTER_VERTICAL, 0)
self.button_2 = wx.Button(self.this_svg_page, wx.ID_ANY, _("Set As Default"))
this_svg_grid.Add(self.button_2, 0, wx.ALIGN_CENTER_VERTICAL, 0)
label_rotate = wx.StaticText(self.this_svg_page, label=_("Rotate on export"))
label_rotate.SetToolTip(_(
"Some embroidery machines don't automatically rotate files to fit into the hoop. "
"You could also rotate the design in the SVG but Inkscape does not save view rotation so this setting is more convenient."
))
this_svg_grid.Add(label_rotate)
self.rotate_on_export = wx.ComboBox(self.this_svg_page)
self.rotate_on_export_choices = (
(_("Don't rotate"), 0),
(_("Rotate left"), -90),
(_("Rotate right"), 90),
)
for idx, (label, degrees) in enumerate(self.rotate_on_export_choices):
self.rotate_on_export.Append(label, degrees)
for idx, (_label, degrees) in enumerate(self.rotate_on_export_choices):
if metadata.get('rotate_on_export', 0) == degrees:
self.rotate_on_export.SetSelection(idx)
break
else:
self.rotate_on_export.SetSelection(0)
this_svg_grid.Add(self.rotate_on_export, flag=wx.ALIGN_CENTER_VERTICAL)
this_svg_margin.Add((0, 20), 1, wx.EXPAND, 0)
self.global_page = wx.Panel(self.notebook, wx.ID_ANY)
self.notebook.AddPage(self.global_page, _("Global"))
global_margin = wx.BoxSizer(wx.VERTICAL)
# add space above and below to center sizer_4 vertically
global_margin.Add((0, 20), 1, wx.EXPAND, 0)
global_grid_sizer = wx.FlexGridSizer(3, 4, 15, 10)
global_margin.Add(global_grid_sizer, 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."))
global_grid_sizer.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(2)
global_grid_sizer.Add(self.default_minimum_jump_stitch_length, 0, wx.ALIGN_CENTER_VERTICAL, 0)
label_6 = wx.StaticText(self.global_page, wx.ID_ANY, _("mm"))
global_grid_sizer.Add(label_6, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 15)
global_grid_sizer.Add((0, 0), 0, 0, 0)
label_7 = wx.StaticText(self.global_page, wx.ID_ANY, _("Minimum stitch length"))
global_grid_sizer.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(2)
global_grid_sizer.Add(self.default_minimum_stitch_length, 0, wx.ALIGN_CENTER_VERTICAL, 0)
label_8 = wx.StaticText(self.global_page, wx.ID_ANY, _("mm"))
global_grid_sizer.Add(label_8, 0, wx.ALIGN_CENTER_VERTICAL, 0)
global_grid_sizer.Add((0, 20), 0, 0, 0)
label_9 = wx.StaticText(self.global_page, wx.ID_ANY, _("Stitch plan cache size (0 to disable cache)"), style=wx.ALIGN_LEFT)
global_grid_sizer.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)
global_grid_sizer.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"))
global_grid_sizer.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"))
global_grid_sizer.Add(self.clear_cache_button, 0, wx.ALIGN_CENTER_VERTICAL, 0)
global_margin.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)
global_grid_sizer.AddGrowableCol(0)
self.global_page.SetSizer(global_margin)
this_svg_grid.AddGrowableCol(0)
self.this_svg_page.SetSizer(this_svg_margin)
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()
_, metadata['rotate_on_export'] = self.rotate_on_export_choices[self.rotate_on_export.GetCurrentSelection()]
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()
if not global_settings['cache_size']:
stitch_plan_cache.clear(retry=True)
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()
|