printrun-src/printrun/settings.py

Tue, 26 Sep 2017 19:08:02 +0200

author
mdd
date
Tue, 26 Sep 2017 19:08:02 +0200
changeset 36
f4730ef55ca8
parent 15
0bbb006204fc
child 46
cce0af6351f0
permissions
-rw-r--r--

SVG options: offset, original scale
SVG Bugfix: "scale" does now really fit to dimensions

15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1 # This file is part of the Printrun suite.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
3 # Printrun is free software: you can redistribute it and/or modify
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
6 # (at your option) any later version.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
7 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
8 # Printrun is distributed in the hope that it will be useful,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
11 # GNU General Public License for more details.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
12 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
14 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
16 import logging
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
17 import traceback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
18
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
19 from functools import wraps
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
20
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
21 from .utils import parse_build_dimensions
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23 def setting_add_tooltip(func):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24 @wraps(func)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
25 def decorator(self, *args, **kwargs):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26 widget = func(self, *args, **kwargs)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27 helptxt = self.help or ""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28 sep, deftxt = "", ""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 if len(helptxt):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 sep = "\n"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31 if helptxt.find("\n") >= 0:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32 sep = "\n\n"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33 if self.default is not "":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34 deftxt = _("Default: ")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35 resethelp = _("(Control-doubleclick to reset to default value)")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
36 if len(repr(self.default)) > 10:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
37 deftxt += "\n " + repr(self.default).strip("'") + "\n" + resethelp
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
38 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
39 deftxt += repr(self.default) + " " + resethelp
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40 helptxt += sep + deftxt
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
41 if len(helptxt):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
42 widget.SetToolTipString(helptxt)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
43 return widget
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
44 return decorator
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
45
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
46 class Setting(object):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
47
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
48 DEFAULT_GROUP = "Printer"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
49
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
50 hidden = False
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
51
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52 def __init__(self, name, default, label = None, help = None, group = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53 self.name = name
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54 self.default = default
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
55 self._value = default
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56 self.label = label
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57 self.help = help
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58 self.group = group if group else Setting.DEFAULT_GROUP
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60 def _get_value(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 return self._value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63 def _set_value(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64 raise NotImplementedError
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65 value = property(_get_value, _set_value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67 def set_default(self, e):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69 if e.CmdDown() and e.ButtonDClick() and self.default is not "":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
70 confirmation = wx.MessageDialog(None, _("Are you sure you want to reset the setting to the default value: {0!r} ?").format(self.default), _("Confirm set default"), wx.ICON_EXCLAMATION | wx.YES_NO | wx.NO_DEFAULT)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
71 if confirmation.ShowModal() == wx.ID_YES:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
72 self._set_value(self.default)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
73 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
74 e.Skip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
75
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
76 @setting_add_tooltip
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77 def get_label(self, parent):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
78 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79 widget = wx.StaticText(parent, -1, self.label or self.name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80 widget.set_default = self.set_default
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
81 return widget
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 @setting_add_tooltip
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
84 def get_widget(self, parent):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
85 return self.get_specific_widget(parent)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 def get_specific_widget(self, parent):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
88 raise NotImplementedError
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90 def update(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91 raise NotImplementedError
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93 def __str__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94 return self.name
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
95
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96 def __repr__(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97 return self.name
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
98
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
99 class HiddenSetting(Setting):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
100
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
101 hidden = True
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
102
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
103 def _set_value(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
104 self._value = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
105 value = property(Setting._get_value, _set_value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
106
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
107 class wxSetting(Setting):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
108
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
109 widget = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
110
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
111 def _set_value(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
112 self._value = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
113 if self.widget:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
114 self.widget.SetValue(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
115 value = property(Setting._get_value, _set_value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
116
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
117 def update(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
118 self.value = self.widget.GetValue()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
119
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
120 class StringSetting(wxSetting):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
121
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
122 def get_specific_widget(self, parent):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
123 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
124 self.widget = wx.TextCtrl(parent, -1, str(self.value))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
125 return self.widget
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
126
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
127 class ComboSetting(wxSetting):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
128
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
129 def __init__(self, name, default, choices, label = None, help = None, group = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
130 super(ComboSetting, self).__init__(name, default, label, help, group)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
131 self.choices = choices
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
132
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
133 def get_specific_widget(self, parent):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
134 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
135 self.widget = wx.ComboBox(parent, -1, str(self.value), choices = self.choices, style = wx.CB_DROPDOWN)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
136 return self.widget
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
137
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
138 class SpinSetting(wxSetting):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
139
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
140 def __init__(self, name, default, min, max, label = None, help = None, group = None, increment = 0.1):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
141 super(SpinSetting, self).__init__(name, default, label, help, group)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
142 self.min = min
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
143 self.max = max
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
144 self.increment = increment
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
145
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
146 def get_specific_widget(self, parent):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
147 from wx.lib.agw.floatspin import FloatSpin
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
148 self.widget = FloatSpin(parent, -1, min_val = self.min, max_val = self.max, digits = 0)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
149 self.widget.SetValue(self.value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
150 orig = self.widget.GetValue
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
151 self.widget.GetValue = lambda: int(orig())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
152 return self.widget
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
153
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
154 class FloatSpinSetting(SpinSetting):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
155
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
156 def get_specific_widget(self, parent):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
157 from wx.lib.agw.floatspin import FloatSpin
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
158 self.widget = FloatSpin(parent, -1, value = self.value, min_val = self.min, max_val = self.max, increment = self.increment, digits = 2)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
159 return self.widget
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
160
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
161 class BooleanSetting(wxSetting):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
162
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
163 def _get_value(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
164 return bool(self._value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
165
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
166 def _set_value(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
167 self._value = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
168 if self.widget:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
169 self.widget.SetValue(bool(value))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
170
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
171 value = property(_get_value, _set_value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
172
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
173 def get_specific_widget(self, parent):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
174 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
175 self.widget = wx.CheckBox(parent, -1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
176 self.widget.SetValue(bool(self.value))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
177 return self.widget
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
178
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
179 class StaticTextSetting(wxSetting):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
180
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
181 def __init__(self, name, label = " ", text = "", help = None, group = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
182 super(StaticTextSetting, self).__init__(name, "", label, help, group)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
183 self.text = text
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
184
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
185 def update(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
186 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
187
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
188 def _get_value(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
189 return ""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
190
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
191 def _set_value(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
192 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
193
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
194 def get_specific_widget(self, parent):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
195 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
196 self.widget = wx.StaticText(parent, -1, self.text)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
197 return self.widget
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
198
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
199 class BuildDimensionsSetting(wxSetting):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
200
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
201 widgets = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
202
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
203 def _set_value(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
204 self._value = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
205 if self.widgets:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
206 self._set_widgets_values(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
207 value = property(wxSetting._get_value, _set_value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
208
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
209 def _set_widgets_values(self, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
210 build_dimensions_list = parse_build_dimensions(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
211 for i in range(len(self.widgets)):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
212 self.widgets[i].SetValue(build_dimensions_list[i])
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
213
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
214 def get_widget(self, parent):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
215 from wx.lib.agw.floatspin import FloatSpin
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
216 import wx
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
217 build_dimensions = parse_build_dimensions(self.value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
218 self.widgets = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
219 w = lambda val, m, M: self.widgets.append(FloatSpin(parent, -1, value = val, min_val = m, max_val = M, digits = 2))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
220 addlabel = lambda name, pos: self.widget.Add(wx.StaticText(parent, -1, name), pos = pos, flag = wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border = 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
221 addwidget = lambda *pos: self.widget.Add(self.widgets[-1], pos = pos, flag = wx.RIGHT, border = 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
222 self.widget = wx.GridBagSizer()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
223 addlabel(_("Width"), (0, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
224 w(build_dimensions[0], 0, 2000)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
225 addwidget(0, 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
226 addlabel(_("Depth"), (0, 2))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
227 w(build_dimensions[1], 0, 2000)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
228 addwidget(0, 3)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
229 addlabel(_("Height"), (0, 4))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
230 w(build_dimensions[2], 0, 2000)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
231 addwidget(0, 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
232 addlabel(_("X offset"), (1, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
233 w(build_dimensions[3], -2000, 2000)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
234 addwidget(1, 1)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
235 addlabel(_("Y offset"), (1, 2))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
236 w(build_dimensions[4], -2000, 2000)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
237 addwidget(1, 3)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
238 addlabel(_("Z offset"), (1, 4))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
239 w(build_dimensions[5], -2000, 2000)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
240 addwidget(1, 5)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
241 addlabel(_("X home pos."), (2, 0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
242 w(build_dimensions[6], -2000, 2000)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
243 self.widget.Add(self.widgets[-1], pos = (2, 1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
244 addlabel(_("Y home pos."), (2, 2))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
245 w(build_dimensions[7], -2000, 2000)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
246 self.widget.Add(self.widgets[-1], pos = (2, 3))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
247 addlabel(_("Z home pos."), (2, 4))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
248 w(build_dimensions[8], -2000, 2000)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
249 self.widget.Add(self.widgets[-1], pos = (2, 5))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
250 return self.widget
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
251
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
252 def update(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
253 values = [float(w.GetValue()) for w in self.widgets]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
254 self.value = "%.02fx%.02fx%.02f%+.02f%+.02f%+.02f%+.02f%+.02f%+.02f" % tuple(values)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
255
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
256 class Settings(object):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
257 def __baudrate_list(self): return ["2400", "9600", "19200", "38400", "57600", "115200", "250000"]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
258
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
259 def __init__(self, root):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
260 # defaults here.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
261 # the initial value determines the type
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
262 self._add(StringSetting("port", "", _("Serial port"), _("Port used to communicate with printer")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
263 self._add(ComboSetting("baudrate", 115200, self.__baudrate_list(), _("Baud rate"), _("Communications Speed")))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
264 self._add(BooleanSetting("tcp_streaming_mode", False, _("TCP streaming mode"), _("When using a TCP connection to the printer, the streaming mode will not wait for acks from the printer to send new commands. This will break things such as ETA prediction, but can result in smoother prints.")), root.update_tcp_streaming_mode)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
265 self._add(BooleanSetting("rpc_server", True, _("RPC server"), _("Enable RPC server to allow remotely querying print status")), root.update_rpc_server)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
266 self._add(BooleanSetting("dtr", True, _("DTR"), _("Disabling DTR would prevent Arduino (RAMPS) from resetting upon connection"), "Printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
267 self._add(SpinSetting("bedtemp_abs", 110, 0, 400, _("Bed temperature for ABS"), _("Heated Build Platform temp for ABS (deg C)"), "Printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
268 self._add(SpinSetting("bedtemp_pla", 60, 0, 400, _("Bed temperature for PLA"), _("Heated Build Platform temp for PLA (deg C)"), "Printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
269 self._add(SpinSetting("temperature_abs", 230, 0, 400, _("Extruder temperature for ABS"), _("Extruder temp for ABS (deg C)"), "Printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
270 self._add(SpinSetting("temperature_pla", 185, 0, 400, _("Extruder temperature for PLA"), _("Extruder temp for PLA (deg C)"), "Printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
271 self._add(SpinSetting("xy_feedrate", 3000, 0, 50000, _("X && Y manual feedrate"), _("Feedrate for Control Panel Moves in X and Y (mm/min)"), "Printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
272 self._add(SpinSetting("z_feedrate", 100, 0, 50000, _("Z manual feedrate"), _("Feedrate for Control Panel Moves in Z (mm/min)"), "Printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
273 self._add(SpinSetting("e_feedrate", 100, 0, 1000, _("E manual feedrate"), _("Feedrate for Control Panel Moves in Extrusions (mm/min)"), "Printer"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
274 self._add(StringSetting("slicecommand", "python skeinforge/skeinforge_application/skeinforge_utilities/skeinforge_craft.py $s", _("Slice command"), _("Slice command"), "External"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
275 self._add(StringSetting("sliceoptscommand", "python skeinforge/skeinforge_application/skeinforge.py", _("Slicer options command"), _("Slice settings command"), "External"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
276 self._add(StringSetting("start_command", "", _("Start command"), _("Executable to run when the print is started"), "External"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
277 self._add(StringSetting("final_command", "", _("Final command"), _("Executable to run when the print is finished"), "External"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
278 self._add(StringSetting("error_command", "", _("Error command"), _("Executable to run when an error occurs"), "External"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
279 self._add(StringSetting("log_path", "", _("Log path"), _("Path to the log file. An empty path will log to the console."), "UI"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
280
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
281 self._add(HiddenSetting("project_offset_x", 0.0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
282 self._add(HiddenSetting("project_offset_y", 0.0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
283 self._add(HiddenSetting("project_interval", 2.0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
284 self._add(HiddenSetting("project_pause", 2.5))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
285 self._add(HiddenSetting("project_scale", 1.0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
286 self._add(HiddenSetting("project_x", 1024))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
287 self._add(HiddenSetting("project_y", 768))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
288 self._add(HiddenSetting("project_projected_x", 150.0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
289 self._add(HiddenSetting("project_direction", "Top Down"))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
290 self._add(HiddenSetting("project_overshoot", 3.0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
291 self._add(HiddenSetting("project_z_axis_rate", 200))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
292 self._add(HiddenSetting("project_layer", 0.1))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
293 self._add(HiddenSetting("project_prelift_gcode", ""))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
294 self._add(HiddenSetting("project_postlift_gcode", ""))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
295 self._add(HiddenSetting("pause_between_prints", True))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
296 self._add(HiddenSetting("default_extrusion", 5.0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
297 self._add(HiddenSetting("last_extrusion", 5.0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
298 self._add(HiddenSetting("total_filament_used", 0.0))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
299
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
300 _settings = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
301
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
302 def __setattr__(self, name, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
303 if name.startswith("_"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
304 return object.__setattr__(self, name, value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
305 if isinstance(value, Setting):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
306 if not value.hidden:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
307 self._settings.append(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
308 object.__setattr__(self, "_" + name, value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
309 elif hasattr(self, "_" + name):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
310 getattr(self, "_" + name).value = value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
311 else:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
312 setattr(self, name, StringSetting(name = name, default = value))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
313
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
314 def __getattr__(self, name):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
315 if name.startswith("_"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
316 return object.__getattribute__(self, name)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
317 return getattr(self, "_" + name).value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
318
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
319 def _add(self, setting, callback = None, validate = None,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
320 alias = None, autocomplete_list = None):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
321 setattr(self, setting.name, setting)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
322 if callback:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
323 setattr(self, "__" + setting.name + "_cb", callback)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
324 if validate:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
325 setattr(self, "__" + setting.name + "_validate", validate)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
326 if alias:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
327 setattr(self, "__" + setting.name + "_alias", alias)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
328 if autocomplete_list:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
329 setattr(self, "__" + setting.name + "_list", autocomplete_list)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
330
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
331 def _set(self, key, value):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
332 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
333 value = getattr(self, "__%s_alias" % key)()[value]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
334 except KeyError:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
335 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
336 except AttributeError:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
337 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
338 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
339 getattr(self, "__%s_validate" % key)(value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
340 except AttributeError:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
341 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
342 t = type(getattr(self, key))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
343 if t == bool and value == "False": setattr(self, key, False)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
344 else: setattr(self, key, t(value))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
345 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
346 cb = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
347 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
348 cb = getattr(self, "__%s_cb" % key)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
349 except AttributeError:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
350 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
351 if cb is not None: cb(key, value)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
352 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
353 logging.warning((_("Failed to run callback after setting \"%s\":") % key) +
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
354 "\n" + traceback.format_exc())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
355 return value
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
356
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
357 def _tabcomplete(self, key):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
358 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
359 return getattr(self, "__%s_list" % key)()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
360 except AttributeError:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
361 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
362 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
363 return getattr(self, "__%s_alias" % key)().keys()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
364 except AttributeError:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
365 pass
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
366 return []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
367
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
368 def _all_settings(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
369 return self._settings

mercurial