]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | # Name: params.py |
2 | # Purpose: Classes for parameter introduction | |
3 | # Author: Roman Rolinsky <rolinsky@mema.ucl.ac.be> | |
4 | # Created: 22.08.2001 | |
5 | # RCS-ID: $Id$ | |
6 | ||
7 | import string | |
8 | import os.path | |
9 | from globals import * | |
10 | from types import * | |
d14a1e28 | 11 | |
b2371711 | 12 | genericStyles = [ |
306b6fe9 | 13 | 'wxSIMPLE_BORDER', 'wxSUNKEN_BORDER', 'wxDOUBLE_BORDER', |
64bce500 | 14 | 'wxRAISED_BORDER', 'wxSTATIC_BORDER', 'wxNO_BORDER', |
306b6fe9 RR |
15 | 'wxCLIP_CHILDREN', 'wxTRANSPARENT_WINDOW', 'wxWANTS_CHARS', |
16 | 'wxNO_FULL_REPAINT_ON_RESIZE', 'wxFULL_REPAINT_ON_RESIZE' | |
64bce500 RR |
17 | ] |
18 | ||
19 | genericExStyles = [ | |
20 | 'wxWS_EX_VALIDATE_RECURSIVELY', | |
b2371711 | 21 | 'wxWS_EX_BLOCK_EVENTS', |
64bce500 RR |
22 | 'wxWS_EX_TRANSIENT', |
23 | 'wxFRAME_EX_CONTEXTHELP', | |
24 | 'wxWS_EX_PROCESS_IDLE', | |
25 | 'wxWS_EX_PROCESS_UI_UPDATES' | |
26 | ] | |
d14a1e28 RD |
27 | |
28 | buttonSize = (35,-1) # in dialog units, transformed to pixels in panel ctor | |
29 | ||
30 | # Class that can properly disable children | |
29a41103 | 31 | class PPanel(wx.Panel): |
d14a1e28 | 32 | def __init__(self, parent, name): |
29a41103 | 33 | wx.Panel.__init__(self, parent, -1, name=name) |
d14a1e28 RD |
34 | self.modified = self.freeze = False |
35 | def Enable(self, value): | |
36 | # Something strange is going on with enable so we make sure... | |
37 | for w in self.GetChildren(): | |
38 | w.Enable(value) | |
29a41103 | 39 | #wx.Panel.Enable(self, value) |
d14a1e28 RD |
40 | def SetModified(self): |
41 | self.modified = True | |
42 | g.panel.SetModified(True) | |
43 | # Common method to set modified state | |
44 | def OnChange(self, evt): | |
45 | if self.freeze: return | |
46 | self.SetModified() | |
47 | evt.Skip() | |
48 | ||
49 | class ParamBinaryOr(PPanel): | |
50 | def __init__(self, parent, name): | |
51 | PPanel.__init__(self, parent, name) | |
29a41103 RD |
52 | self.ID_TEXT_CTRL = wx.NewId() |
53 | self.ID_BUTTON_CHOICES = wx.NewId() | |
54 | sizer = wx.BoxSizer() | |
55 | self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=wx.Size(200,-1)) | |
56 | sizer.Add(self.text, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5) | |
57 | self.button = wx.Button(self, self.ID_BUTTON_CHOICES, 'Edit...', size=buttonSize) | |
58 | sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL) | |
d14a1e28 RD |
59 | self.SetAutoLayout(True) |
60 | self.SetSizer(sizer) | |
61 | sizer.Fit(self) | |
29a41103 RD |
62 | wx.EVT_BUTTON(self, self.ID_BUTTON_CHOICES, self.OnButtonChoices) |
63 | wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
d14a1e28 RD |
64 | def GetValue(self): |
65 | return self.text.GetValue() | |
66 | def SetValue(self, value): | |
67 | self.freeze = True | |
68 | self.text.SetValue(value) | |
69 | self.freeze = False | |
70 | def OnButtonChoices(self, evt): | |
a4c013b2 | 71 | dlg = g.frame.res.LoadDialog(self, 'DIALOG_CHOICES') |
c032d94e RR |
72 | if self.GetName() == 'flag': dlg.SetTitle('Sizer item flags') |
73 | elif self.GetName() == 'style': dlg.SetTitle('Window styles') | |
74 | elif self.GetName() == 'exstyle': dlg.SetTitle('Extended window styles') | |
29a41103 | 75 | listBox = xrc.XRCCTRL(dlg, 'CHECKLIST') |
a4c013b2 | 76 | listBox.InsertItems(self.values, 0) |
d14a1e28 RD |
77 | value = map(string.strip, self.text.GetValue().split('|')) |
78 | if value == ['']: value = [] | |
79 | ignored = [] | |
80 | for i in value: | |
81 | try: | |
82 | listBox.Check(self.values.index(i)) | |
83 | except ValueError: | |
84 | # Try to find equal | |
85 | if self.equal.has_key(i): | |
86 | listBox.Check(self.values.index(self.equal[i])) | |
87 | else: | |
88 | print 'WARNING: unknown flag: %s: ignored.' % i | |
89 | ignored.append(i) | |
29a41103 | 90 | if dlg.ShowModal() == wx.ID_OK: |
d14a1e28 | 91 | value = [] |
31f04352 | 92 | for i in range(listBox.GetCount()): |
d14a1e28 RD |
93 | if listBox.IsChecked(i): |
94 | value.append(self.values[i]) | |
95 | # Add ignored flags | |
96 | value.extend(ignored) | |
c37cba89 | 97 | self.SetValue('|'.join(value)) |
d14a1e28 RD |
98 | self.SetModified() |
99 | dlg.Destroy() | |
100 | ||
101 | class ParamFlag(ParamBinaryOr): | |
102 | values = ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL', | |
306b6fe9 RR |
103 | 'wxEXPAND', 'wxGROW', 'wxSHAPED', 'wxSTRETCH_NOT', |
104 | 'wxALIGN_CENTRE', 'wxALIGN_LEFT', 'wxALIGN_RIGHT', | |
105 | 'wxALIGN_TOP', 'wxALIGN_BOTTOM', | |
106 | 'wxALIGN_CENTRE_VERTICAL', 'wxALIGN_CENTRE_HORIZONTAL', | |
107 | 'wxADJUST_MINSIZE', 'wxFIXED_MINSIZE' | |
9abdd2cb | 108 | ] |
d14a1e28 RD |
109 | equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE', |
110 | 'wxALIGN_CENTER_VERTICAL': 'wxALIGN_CENTRE_VERTICAL', | |
306b6fe9 RR |
111 | 'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL', |
112 | 'wxUP': 'wxTOP', 'wxDOWN': 'wxBOTTOM', 'wxNORTH': 'wxTOP', | |
113 | 'wxSOUTH': 'wxBOTTOM', 'wxWEST': 'wxLEFT', 'wxEAST': 'wxRIGHT'} | |
d14a1e28 RD |
114 | def __init__(self, parent, name): |
115 | ParamBinaryOr.__init__(self, parent, name) | |
116 | ||
c032d94e | 117 | class ParamNonGenericStyle(ParamBinaryOr): |
d14a1e28 | 118 | def __init__(self, parent, name): |
c032d94e | 119 | self.values = g.currentXXX.winStyles |
d14a1e28 RD |
120 | ParamBinaryOr.__init__(self, parent, name) |
121 | ||
c032d94e RR |
122 | class ParamStyle(ParamBinaryOr): |
123 | equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE'} | |
d14a1e28 | 124 | def __init__(self, parent, name): |
d14a1e28 | 125 | ParamBinaryOr.__init__(self, parent, name) |
c032d94e RR |
126 | self.valuesSpecific = g.currentXXX.winStyles |
127 | if self.valuesSpecific: # override if using specific styles | |
128 | # Remove duplicates | |
129 | self.valuesGeneric = [s for s in genericStyles | |
130 | if s not in self.valuesSpecific] | |
29a41103 | 131 | wx.EVT_BUTTON(self, self.ID_BUTTON_CHOICES, self.OnButtonChoicesBoth) |
c032d94e RR |
132 | else: |
133 | self.values = genericStyles | |
134 | def OnButtonChoicesBoth(self, evt): | |
135 | dlg = g.frame.res.LoadDialog(self, 'DIALOG_STYLES') | |
29a41103 | 136 | listBoxSpecific = xrc.XRCCTRL(dlg, 'CHECKLIST_SPECIFIC') |
c032d94e | 137 | listBoxSpecific.InsertItems(self.valuesSpecific, 0) |
29a41103 | 138 | listBoxGeneric = xrc.XRCCTRL(dlg, 'CHECKLIST_GENERIC') |
c032d94e RR |
139 | listBoxGeneric.InsertItems(self.valuesGeneric, 0) |
140 | value = map(string.strip, self.text.GetValue().split('|')) | |
141 | if value == ['']: value = [] | |
142 | # Set specific styles | |
143 | value2 = [] # collect generic and ignored here | |
144 | for i in value: | |
145 | try: | |
146 | listBoxSpecific.Check(self.valuesSpecific.index(i)) | |
147 | except ValueError: | |
148 | # Try to find equal | |
149 | if self.equal.has_key(i): | |
150 | listBoxSpecific.Check(self.valuesSpecific.index(self.equal[i])) | |
151 | else: | |
152 | value2.append(i) | |
153 | ignored = [] | |
154 | # Set generic styles, collect non-standart values | |
155 | for i in value2: | |
156 | try: | |
157 | listBoxGeneric.Check(self.valuesGeneric.index(i)) | |
158 | except ValueError: | |
159 | # Try to find equal | |
160 | if self.equal.has_key(i): | |
161 | listBoxGeneric.Check(self.valuesGeneric.index(self.equal[i])) | |
162 | else: | |
163 | print 'WARNING: unknown flag: %s: ignored.' % i | |
164 | ignored.append(i) | |
29a41103 | 165 | if dlg.ShowModal() == wx.ID_OK: |
c032d94e RR |
166 | value = [self.valuesSpecific[i] |
167 | for i in range(listBoxSpecific.GetCount()) | |
168 | if listBoxSpecific.IsChecked(i)] + \ | |
169 | [self.valuesGeneric[i] | |
170 | for i in range(listBoxGeneric.GetCount()) | |
171 | if listBoxGeneric.IsChecked(i)] + ignored | |
c37cba89 | 172 | self.SetValue('|'.join(value)) |
c032d94e RR |
173 | self.SetModified() |
174 | dlg.Destroy() | |
d14a1e28 RD |
175 | |
176 | class ParamExStyle(ParamBinaryOr): | |
177 | def __init__(self, parent, name): | |
178 | if g.currentXXX: | |
64bce500 | 179 | self.values = g.currentXXX.exStyles + genericExStyles |
d14a1e28 RD |
180 | else: |
181 | self.values = [] | |
182 | ParamBinaryOr.__init__(self, parent, name) | |
183 | ||
184 | class ParamColour(PPanel): | |
185 | def __init__(self, parent, name): | |
186 | PPanel.__init__(self, parent, name) | |
29a41103 RD |
187 | self.ID_TEXT_CTRL = wx.NewId() |
188 | self.ID_BUTTON = wx.NewId() | |
189 | sizer = wx.BoxSizer() | |
190 | self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=(80,-1)) | |
191 | sizer.Add(self.text, 0, wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.BOTTOM, 2) | |
192 | self.button = wx.Panel(self, self.ID_BUTTON, wx.DefaultPosition, wx.Size(20, 20)) | |
193 | sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 5) | |
d14a1e28 RD |
194 | self.SetAutoLayout(True) |
195 | self.SetSizer(sizer) | |
196 | sizer.Fit(self) | |
197 | self.textModified = False | |
29a41103 RD |
198 | wx.EVT_PAINT(self.button, self.OnPaintButton) |
199 | wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
200 | wx.EVT_LEFT_DOWN(self.button, self.OnLeftDown) | |
d14a1e28 RD |
201 | def GetValue(self): |
202 | return self.text.GetValue() | |
203 | def SetValue(self, value): | |
204 | self.freeze = True | |
205 | if not value: value = '#FFFFFF' | |
206 | self.text.SetValue(str(value)) # update text ctrl | |
99328372 | 207 | try: |
29a41103 | 208 | colour = wx.Colour(int(value[1:3], 16), int(value[3:5], 16), int(value[5:7], 16)) |
99328372 RR |
209 | self.button.SetBackgroundColour(colour) |
210 | except: # ignore errors | |
211 | pass | |
d14a1e28 RD |
212 | self.button.Refresh() |
213 | self.freeze = False | |
214 | def OnPaintButton(self, evt): | |
29a41103 RD |
215 | dc = wx.PaintDC(self.button) |
216 | dc.SetBrush(wx.TRANSPARENT_BRUSH) | |
217 | if self.IsEnabled(): dc.SetPen(wx.BLACK_PEN) | |
218 | else: dc.SetPen(wx.GREY_PEN) | |
d14a1e28 | 219 | size = self.button.GetSize() |
b09afc93 | 220 | dc.DrawRectangle(0, 0, size.width, size.height) |
d14a1e28 | 221 | def OnLeftDown(self, evt): |
29a41103 | 222 | data = wx.ColourData() |
d14a1e28 | 223 | data.SetColour(self.GetValue()) |
29a41103 RD |
224 | dlg = wx.ColourDialog(self, data) |
225 | if dlg.ShowModal() == wx.ID_OK: | |
d14a1e28 RD |
226 | self.SetValue('#%02X%02X%02X' % dlg.GetColourData().GetColour().Get()) |
227 | self.SetModified() | |
228 | dlg.Destroy() | |
229 | ||
230 | ################################################################################ | |
231 | ||
f65bb0f8 | 232 | # Mapping from wx constants to XML strings |
29a41103 RD |
233 | fontFamiliesWx2Xml = {wx.DEFAULT: 'default', wx.DECORATIVE: 'decorative', |
234 | wx.ROMAN: 'roman', wx.SCRIPT: 'script', wx.SWISS: 'swiss', | |
235 | wx.MODERN: 'modern'} | |
236 | fontStylesWx2Xml = {wx.NORMAL: 'normal', wx.SLANT: 'slant', wx.ITALIC: 'italic'} | |
237 | fontWeightsWx2Xml = {wx.NORMAL: 'normal', wx.LIGHT: 'light', wx.BOLD: 'bold'} | |
d14a1e28 RD |
238 | def ReverseMap(m): |
239 | rm = {} | |
240 | for k,v in m.items(): rm[v] = k | |
241 | return rm | |
242 | fontFamiliesXml2wx = ReverseMap(fontFamiliesWx2Xml) | |
243 | fontStylesXml2wx = ReverseMap(fontStylesWx2Xml) | |
244 | fontWeightsXml2wx = ReverseMap(fontWeightsWx2Xml) | |
245 | ||
246 | class ParamFont(PPanel): | |
247 | def __init__(self, parent, name): | |
248 | PPanel.__init__(self, parent, name) | |
29a41103 RD |
249 | self.ID_TEXT_CTRL = wx.NewId() |
250 | self.ID_BUTTON_SELECT = wx.NewId() | |
251 | sizer = wx.BoxSizer() | |
252 | self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=(200,-1)) | |
253 | sizer.Add(self.text, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5) | |
254 | self.button = wx.Button(self, self.ID_BUTTON_SELECT, 'Select...', size=buttonSize) | |
255 | sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL) | |
d14a1e28 RD |
256 | self.SetAutoLayout(True) |
257 | self.SetSizer(sizer) | |
258 | sizer.Fit(self) | |
259 | self.textModified = False | |
29a41103 RD |
260 | wx.EVT_BUTTON(self, self.ID_BUTTON_SELECT, self.OnButtonSelect) |
261 | wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
d14a1e28 RD |
262 | def OnChange(self, evt): |
263 | PPanel.OnChange(self, evt) | |
264 | self.textModified = True | |
265 | def _defaultValue(self): | |
306b6fe9 | 266 | return [`g._sysFont.GetPointSize()`, 'default', 'normal', 'normal', '0', '', ''] |
d14a1e28 RD |
267 | def GetValue(self): |
268 | if self.textModified: # text has newer value | |
269 | try: | |
270 | return eval(self.text.GetValue()) | |
271 | except SyntaxError: | |
29a41103 | 272 | wx.LogError('Syntax error in parameter value: ' + self.GetName()) |
d14a1e28 RD |
273 | return self._defaultValue() |
274 | return self.value | |
275 | def SetValue(self, value): | |
276 | self.freeze = True # disable other handlers | |
277 | if not value: value = self._defaultValue() | |
278 | self.value = value | |
279 | self.text.SetValue(str(value)) # update text ctrl | |
280 | self.freeze = False | |
281 | def OnButtonSelect(self, evt): | |
282 | if self.textModified: # text has newer value | |
283 | try: | |
284 | self.value = eval(self.text.GetValue()) | |
285 | except SyntaxError: | |
29a41103 | 286 | wx.LogError('Syntax error in parameter value: ' + self.GetName()) |
d14a1e28 RD |
287 | self.value = self._defaultValue() |
288 | # Make initial font | |
289 | # Default values | |
306b6fe9 | 290 | size = g._sysFont.GetPointSize() |
29a41103 RD |
291 | family = wx.DEFAULT |
292 | style = weight = wx.NORMAL | |
d14a1e28 RD |
293 | underlined = 0 |
294 | face = '' | |
29a41103 | 295 | enc = wx.FONTENCODING_DEFAULT |
d14a1e28 RD |
296 | # Fall back to default if exceptions |
297 | error = False | |
298 | try: | |
299 | try: size = int(self.value[0]) | |
29a41103 | 300 | except ValueError: error = True; wx.LogError('Invalid size specification') |
d14a1e28 | 301 | try: family = fontFamiliesXml2wx[self.value[1]] |
29a41103 | 302 | except KeyError: error = True; wx.LogError('Invalid family specification') |
d14a1e28 | 303 | try: style = fontStylesXml2wx[self.value[2]] |
29a41103 | 304 | except KeyError: error = True; wx.LogError('Invalid style specification') |
d14a1e28 | 305 | try: weight = fontWeightsXml2wx[self.value[3]] |
29a41103 | 306 | except KeyError: error = True; wx.LogError('Invalid weight specification') |
016f67ba | 307 | try: underlined = bool(self.value[4]) |
29a41103 | 308 | except ValueError: error = True; wx.LogError('Invalid underlined flag specification') |
d14a1e28 | 309 | face = self.value[5] |
d14a1e28 RD |
310 | except IndexError: |
311 | error = True | |
29a41103 | 312 | mapper = wx.FontMapper() |
016f67ba RR |
313 | if not self.value[6]: enc = mapper.CharsetToEncoding(self.value[6]) |
314 | ||
29a41103 RD |
315 | if error: wx.LogError('Invalid font specification') |
316 | if enc == wx.FONTENCODING_DEFAULT: enc = wx.FONTENCODING_SYSTEM | |
317 | font = wx.Font(size, family, style, weight, underlined, face, enc) | |
318 | data = wx.FontData() | |
d14a1e28 | 319 | data.SetInitialFont(font) |
29a41103 RD |
320 | dlg = wx.FontDialog(self, data) |
321 | if dlg.ShowModal() == wx.ID_OK: | |
d14a1e28 | 322 | font = dlg.GetFontData().GetChosenFont() |
016f67ba | 323 | print font.GetEncoding() |
29a41103 | 324 | if font.GetEncoding() == wx.FONTENCODING_SYSTEM: |
016f67ba RR |
325 | encName = '' |
326 | else: | |
29a41103 | 327 | encName = wx.FontMapper.GetEncodingName(font.GetEncoding()).encode() |
d14a1e28 RD |
328 | value = [str(font.GetPointSize()), |
329 | fontFamiliesWx2Xml.get(font.GetFamily(), "default"), | |
330 | fontStylesWx2Xml.get(font.GetStyle(), "normal"), | |
331 | fontWeightsWx2Xml.get(font.GetWeight(), "normal"), | |
0d9b8891 | 332 | str(int(font.GetUnderlined())), |
d14a1e28 | 333 | font.GetFaceName().encode(), |
016f67ba | 334 | encName |
d14a1e28 | 335 | ] |
d14a1e28 RD |
336 | self.SetValue(value) |
337 | self.SetModified() | |
338 | self.textModified = False | |
339 | dlg.Destroy() | |
340 | ||
341 | ################################################################################ | |
342 | ||
343 | class ParamInt(PPanel): | |
344 | def __init__(self, parent, name): | |
345 | PPanel.__init__(self, parent, name) | |
29a41103 RD |
346 | self.ID_SPIN_CTRL = wx.NewId() |
347 | sizer = wx.BoxSizer() | |
348 | self.spin = wx.SpinCtrl(self, self.ID_SPIN_CTRL, size=(60,-1)) | |
c032d94e RR |
349 | self.spin.SetRange(-2147483648, 2147483647) # min/max integers |
350 | sizer.Add(self.spin) | |
351 | self.SetAutoLayout(True) | |
352 | self.SetSizer(sizer) | |
353 | sizer.Fit(self) | |
29a41103 | 354 | wx.EVT_SPINCTRL(self, self.ID_SPIN_CTRL, self.OnChange) |
c032d94e RR |
355 | def GetValue(self): |
356 | return str(self.spin.GetValue()) | |
357 | def SetValue(self, value): | |
358 | self.freeze = True | |
359 | if not value: value = 0 | |
360 | self.spin.SetValue(int(value)) | |
361 | self.freeze = False | |
362 | ||
363 | # Non-negative number | |
364 | class ParamIntNN(PPanel): | |
365 | def __init__(self, parent, name): | |
366 | PPanel.__init__(self, parent, name) | |
29a41103 RD |
367 | self.ID_SPIN_CTRL = wx.NewId() |
368 | sizer = wx.BoxSizer() | |
369 | self.spin = wx.SpinCtrl(self, self.ID_SPIN_CTRL, size=(60,-1)) | |
c032d94e | 370 | self.spin.SetRange(0, 10000) # min/max integers |
d14a1e28 RD |
371 | sizer.Add(self.spin) |
372 | self.SetAutoLayout(True) | |
373 | self.SetSizer(sizer) | |
374 | sizer.Fit(self) | |
29a41103 | 375 | wx.EVT_SPINCTRL(self, self.ID_SPIN_CTRL, self.OnChange) |
d14a1e28 RD |
376 | def GetValue(self): |
377 | return str(self.spin.GetValue()) | |
378 | def SetValue(self, value): | |
379 | self.freeze = True | |
380 | if not value: value = 0 | |
381 | self.spin.SetValue(int(value)) | |
382 | self.freeze = False | |
383 | ||
384 | # Same as int but allows dialog units (XXXd) | |
385 | class ParamUnit(PPanel): | |
386 | def __init__(self, parent, name): | |
387 | PPanel.__init__(self, parent, name) | |
29a41103 RD |
388 | self.ID_TEXT_CTRL = wx.NewId() |
389 | self.ID_SPIN_BUTTON = wx.NewId() | |
390 | sizer = wx.BoxSizer(wx.HORIZONTAL) | |
391 | self.spin = wx.SpinButton(self, self.ID_SPIN_BUTTON, style = wx.SP_VERTICAL, size=(-1,1)) | |
c032d94e | 392 | textW = 60 - self.spin.GetSize()[0] |
29a41103 | 393 | self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=(textW,-1)) |
d14a1e28 | 394 | self.spin.SetRange(-10000, 10000) |
29a41103 RD |
395 | sizer.Add(self.text, 0, wx.EXPAND) |
396 | sizer.Add(self.spin, 0, wx.EXPAND) | |
c032d94e | 397 | #sizer.SetMinSize((50,-1)) |
d14a1e28 RD |
398 | self.SetAutoLayout(True) |
399 | self.SetSizer(sizer) | |
400 | sizer.Fit(self) | |
29a41103 RD |
401 | wx.EVT_SPIN_UP(self, self.ID_SPIN_BUTTON, self.OnSpinUp) |
402 | wx.EVT_SPIN_DOWN(self, self.ID_SPIN_BUTTON, self.OnSpinDown) | |
d14a1e28 RD |
403 | def GetValue(self): |
404 | return self.text.GetValue() | |
405 | def SetValue(self, value): | |
406 | self.freeze = True | |
407 | if not value: value = '0' | |
408 | self.text.SetValue(value) | |
409 | self.freeze = False | |
410 | def Change(self, x): | |
411 | # Check if we are working with dialog units | |
412 | value = self.text.GetValue() | |
413 | units = '' | |
414 | if value[-1].upper() == 'D': | |
415 | units = value[-1] | |
416 | value = value[:-1] | |
417 | try: | |
418 | intValue = int(value) + x | |
419 | self.spin.SetValue(intValue) | |
420 | self.text.SetValue(str(intValue) + units) | |
421 | self.SetModified() | |
422 | except: | |
29a41103 | 423 | # !!! Strange, if I use wx.LogWarning, event is re-generated |
d14a1e28 RD |
424 | print 'incorrect unit format' |
425 | def OnSpinUp(self, evt): | |
426 | self.Change(1) | |
427 | def OnSpinDown(self, evt): | |
428 | self.Change(-1) | |
429 | ||
d14a1e28 RD |
430 | class ParamMultilineText(PPanel): |
431 | def __init__(self, parent, name, textWidth=-1): | |
432 | PPanel.__init__(self, parent, name) | |
29a41103 RD |
433 | self.ID_TEXT_CTRL = wx.NewId() |
434 | self.ID_BUTTON_EDIT = wx.NewId() | |
435 | sizer = wx.BoxSizer() | |
436 | self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=wx.Size(200,-1)) | |
437 | sizer.Add(self.text, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5) | |
438 | self.button = wx.Button(self, self.ID_BUTTON_EDIT, 'Edit...', size=buttonSize) | |
439 | sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL) | |
d14a1e28 RD |
440 | self.SetAutoLayout(True) |
441 | self.SetSizer(sizer) | |
442 | sizer.Fit(self) | |
29a41103 RD |
443 | wx.EVT_BUTTON(self, self.ID_BUTTON_EDIT, self.OnButtonEdit) |
444 | wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
d14a1e28 RD |
445 | def GetValue(self): |
446 | return self.text.GetValue() | |
447 | def SetValue(self, value): | |
448 | self.freeze = True # disable other handlers | |
449 | self.text.SetValue(value) | |
450 | self.freeze = False # disable other handlers | |
451 | def OnButtonEdit(self, evt): | |
a4c013b2 | 452 | dlg = g.frame.res.LoadDialog(self, 'DIALOG_TEXT') |
29a41103 | 453 | textCtrl = xrc.XRCCTRL(dlg, 'TEXT') |
a4c013b2 | 454 | textCtrl.SetValue(self.text.GetValue()) |
29a41103 | 455 | if dlg.ShowModal() == wx.ID_OK: |
a4c013b2 | 456 | self.text.SetValue(textCtrl.GetValue()) |
d14a1e28 RD |
457 | self.SetModified() |
458 | dlg.Destroy() | |
459 | ||
460 | class ParamText(PPanel): | |
461 | def __init__(self, parent, name, textWidth=-1): | |
462 | PPanel.__init__(self, parent, name) | |
29a41103 | 463 | self.ID_TEXT_CTRL = wx.NewId() |
d14a1e28 | 464 | # We use sizer even here to have the same size of text control |
29a41103 RD |
465 | sizer = wx.BoxSizer() |
466 | self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=wx.Size(textWidth,-1)) | |
d14a1e28 RD |
467 | if textWidth == -1: option = 1 |
468 | else: option = 0 | |
29a41103 | 469 | sizer.Add(self.text, option, wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.BOTTOM, 2) |
d14a1e28 RD |
470 | self.SetAutoLayout(True) |
471 | self.SetSizer(sizer) | |
472 | sizer.Fit(self) | |
29a41103 | 473 | wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) |
d14a1e28 RD |
474 | def GetValue(self): |
475 | return self.text.GetValue() | |
476 | def SetValue(self, value): | |
477 | self.freeze = True # disable other handlers | |
478 | self.text.SetValue(value) | |
479 | self.freeze = False # disable other handlers | |
480 | ||
481 | class ParamAccel(ParamText): | |
482 | def __init__(self, parent, name): | |
483 | ParamText.__init__(self, parent, name, 100) | |
484 | ||
485 | class ParamPosSize(ParamText): | |
486 | def __init__(self, parent, name): | |
487 | ParamText.__init__(self, parent, name, 80) | |
488 | ||
489 | class ParamLabel(ParamText): | |
490 | def __init__(self, parent, name): | |
491 | ParamText.__init__(self, parent, name, 200) | |
492 | ||
493 | class ParamEncoding(ParamText): | |
494 | def __init__(self, parent, name): | |
495 | ParamText.__init__(self, parent, name, 100) | |
496 | ||
29a41103 | 497 | class ContentDialog(wx.Dialog): |
d14a1e28 RD |
498 | def __init__(self, parent, value): |
499 | # Load from resource | |
29a41103 | 500 | pre = wx.PreDialog() |
d14a1e28 | 501 | g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_CONTENT') |
29a41103 RD |
502 | self.PostCreate(pre) |
503 | self.list = xrc.XRCCTRL(self, 'LIST') | |
d14a1e28 RD |
504 | # Set list items |
505 | for v in value: | |
506 | self.list.Append(v) | |
507 | self.SetAutoLayout(True) | |
508 | self.GetSizer().Fit(self) | |
509 | # Callbacks | |
29a41103 RD |
510 | self.ID_BUTTON_APPEND = xrc.XRCID('BUTTON_APPEND') |
511 | self.ID_BUTTON_REMOVE = xrc.XRCID('BUTTON_REMOVE') | |
512 | self.ID_BUTTON_UP = xrc.XRCID('BUTTON_UP') | |
513 | self.ID_BUTTON_DOWN = xrc.XRCID('BUTTON_DOWN') | |
514 | wx.EVT_BUTTON(self, self.ID_BUTTON_UP, self.OnButtonUp) | |
515 | wx.EVT_BUTTON(self, self.ID_BUTTON_DOWN, self.OnButtonDown) | |
516 | wx.EVT_BUTTON(self, self.ID_BUTTON_APPEND, self.OnButtonAppend) | |
517 | wx.EVT_BUTTON(self, self.ID_BUTTON_REMOVE, self.OnButtonRemove) | |
518 | wx.EVT_UPDATE_UI(self, self.ID_BUTTON_UP, self.OnUpdateUI) | |
519 | wx.EVT_UPDATE_UI(self, self.ID_BUTTON_DOWN, self.OnUpdateUI) | |
520 | wx.EVT_UPDATE_UI(self, self.ID_BUTTON_REMOVE, self.OnUpdateUI) | |
d14a1e28 RD |
521 | def OnButtonUp(self, evt): |
522 | i = self.list.GetSelection() | |
523 | str = self.list.GetString(i) | |
524 | self.list.Delete(i) | |
525 | self.list.InsertItems([str], i-1) | |
526 | self.list.SetSelection(i-1) | |
527 | def OnButtonDown(self, evt): | |
528 | i = self.list.GetSelection() | |
529 | str = self.list.GetString(i) | |
530 | self.list.Delete(i) | |
531 | self.list.InsertItems([str], i+1) | |
532 | self.list.SetSelection(i+1) | |
533 | def OnButtonAppend(self, evt): | |
29a41103 | 534 | str = wx.GetTextFromUser('Enter new item:', 'Append', '', self) |
d14a1e28 RD |
535 | self.list.Append(str) |
536 | def OnButtonRemove(self, evt): | |
537 | self.list.Delete(self.list.GetSelection()) | |
538 | def OnUpdateUI(self, evt): | |
539 | if evt.GetId() == self.ID_BUTTON_REMOVE: | |
540 | evt.Enable(self.list.GetSelection() != -1) | |
541 | elif evt.GetId() == self.ID_BUTTON_UP: | |
542 | evt.Enable(self.list.GetSelection() > 0) | |
543 | elif evt.GetId() == self.ID_BUTTON_DOWN: | |
544 | evt.Enable(self.list.GetSelection() != -1 and \ | |
31f04352 | 545 | self.list.GetSelection() < self.list.GetCount() - 1) |
d14a1e28 | 546 | |
29a41103 | 547 | class ContentCheckListDialog(wx.Dialog): |
d14a1e28 | 548 | def __init__(self, parent, value): |
29a41103 | 549 | pre = wx.PreDialog() |
c032d94e | 550 | g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_CONTENT_CHECKLIST') |
29a41103 | 551 | self.PostCreate(pre) |
75aa1946 | 552 | self.list = xrc.XRCCTRL(self, 'CHECK_LIST') |
d14a1e28 RD |
553 | # Set list items |
554 | i = 0 | |
555 | for v,ch in value: | |
556 | self.list.Append(v) | |
557 | self.list.Check(i, ch) | |
558 | i += 1 | |
559 | self.SetAutoLayout(True) | |
560 | self.GetSizer().Fit(self) | |
561 | # Callbacks | |
29a41103 RD |
562 | self.ID_BUTTON_APPEND = xrc.XRCID('BUTTON_APPEND') |
563 | self.ID_BUTTON_REMOVE = xrc.XRCID('BUTTON_REMOVE') | |
564 | self.ID_BUTTON_UP = xrc.XRCID('BUTTON_UP') | |
565 | self.ID_BUTTON_DOWN = xrc.XRCID('BUTTON_DOWN') | |
566 | wx.EVT_CHECKLISTBOX(self, self.list.GetId(), self.OnCheck) | |
567 | wx.EVT_BUTTON(self, self.ID_BUTTON_UP, self.OnButtonUp) | |
568 | wx.EVT_BUTTON(self, self.ID_BUTTON_DOWN, self.OnButtonDown) | |
569 | wx.EVT_BUTTON(self, self.ID_BUTTON_APPEND, self.OnButtonAppend) | |
570 | wx.EVT_BUTTON(self, self.ID_BUTTON_REMOVE, self.OnButtonRemove) | |
571 | wx.EVT_UPDATE_UI(self, self.ID_BUTTON_UP, self.OnUpdateUI) | |
572 | wx.EVT_UPDATE_UI(self, self.ID_BUTTON_DOWN, self.OnUpdateUI) | |
573 | wx.EVT_UPDATE_UI(self, self.ID_BUTTON_REMOVE, self.OnUpdateUI) | |
d14a1e28 RD |
574 | def OnCheck(self, evt): |
575 | # !!! Wrong wxGTK (wxMSW?) behavior: toggling selection if checking | |
576 | self.list.Deselect(evt.GetSelection()) | |
577 | def OnButtonUp(self, evt): | |
578 | i = self.list.GetSelection() | |
579 | str, ch = self.list.GetString(i), self.list.IsChecked(i) | |
580 | self.list.Delete(i) | |
581 | self.list.InsertItems([str], i-1) | |
582 | self.list.Check(i-1, ch) | |
583 | self.list.SetSelection(i-1) | |
584 | def OnButtonDown(self, evt): | |
585 | i = self.list.GetSelection() | |
586 | str, ch = self.list.GetString(i), self.list.IsChecked(i) | |
587 | self.list.Delete(i) | |
588 | self.list.InsertItems([str], i+1) | |
589 | self.list.Check(i+1, ch) | |
590 | self.list.SetSelection(i+1) | |
591 | def OnButtonAppend(self, evt): | |
29a41103 | 592 | str = wx.GetTextFromUser('Enter new item:', 'Append', '', self) |
d14a1e28 RD |
593 | self.list.Append(str) |
594 | def OnButtonRemove(self, evt): | |
595 | self.list.Delete(self.list.GetSelection()) | |
596 | def OnUpdateUI(self, evt): | |
597 | if evt.GetId() == self.ID_BUTTON_REMOVE: | |
598 | evt.Enable(self.list.GetSelection() != -1) | |
599 | elif evt.GetId() == self.ID_BUTTON_UP: | |
600 | evt.Enable(self.list.GetSelection() > 0) | |
601 | elif evt.GetId() == self.ID_BUTTON_DOWN: | |
602 | evt.Enable(self.list.GetSelection() != -1 and \ | |
31f04352 | 603 | self.list.GetSelection() < self.list.GetCount() - 1) |
d14a1e28 RD |
604 | |
605 | class ParamContent(PPanel): | |
606 | def __init__(self, parent, name): | |
607 | PPanel.__init__(self, parent, name) | |
29a41103 RD |
608 | self.ID_TEXT_CTRL = wx.NewId() |
609 | self.ID_BUTTON_EDIT = wx.NewId() | |
610 | sizer = wx.BoxSizer() | |
611 | self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=wx.Size(200,-1)) | |
612 | sizer.Add(self.text, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5) | |
613 | self.button = wx.Button(self, self.ID_BUTTON_EDIT, 'Edit...', size=buttonSize) | |
614 | sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL) | |
d14a1e28 RD |
615 | self.SetAutoLayout(True) |
616 | self.SetSizer(sizer) | |
617 | sizer.Fit(self) | |
618 | self.textModified = False | |
29a41103 RD |
619 | wx.EVT_BUTTON(self, self.ID_BUTTON_EDIT, self.OnButtonEdit) |
620 | wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
d14a1e28 RD |
621 | def OnChange(self, evt): |
622 | PPanel.OnChange(self, evt) | |
623 | self.textModified = True | |
624 | def GetValue(self): | |
625 | if self.textModified: # text has newer value | |
626 | try: | |
e484fddf | 627 | return self.text.GetValue().split('|') |
d14a1e28 | 628 | except SyntaxError: |
29a41103 | 629 | wx.LogError('Syntax error in parameter value: ' + self.GetName()) |
d14a1e28 RD |
630 | return [] |
631 | return self.value | |
632 | def SetValue(self, value): | |
633 | self.freeze = True | |
634 | if not value: value = [] | |
635 | self.value = value | |
c37cba89 | 636 | repr_ = '|'.join(map(str, value)) |
e484fddf | 637 | self.text.SetValue(repr_) # update text ctrl |
d14a1e28 RD |
638 | self.freeze = False |
639 | def OnButtonEdit(self, evt): | |
640 | if self.textModified: # text has newer value | |
e484fddf | 641 | self.value = self.GetValue() |
d14a1e28 | 642 | dlg = ContentDialog(self, self.value) |
29a41103 | 643 | if dlg.ShowModal() == wx.ID_OK: |
d14a1e28 | 644 | value = [] |
31f04352 | 645 | for i in range(dlg.list.GetCount()): |
d14a1e28 | 646 | value.append(dlg.list.GetString(i)) |
d14a1e28 RD |
647 | self.SetValue(value) |
648 | self.SetModified() | |
649 | self.textModified = False | |
650 | dlg.Destroy() | |
651 | ||
652 | # CheckList content | |
653 | class ParamContentCheckList(ParamContent): | |
654 | def __init__(self, parent, name): | |
655 | ParamContent.__init__(self, parent, name) | |
656 | def OnButtonEdit(self, evt): | |
657 | if self.textModified: # text has newer value | |
e484fddf | 658 | self.value = self.GetValue() |
d14a1e28 | 659 | dlg = ContentCheckListDialog(self, self.value) |
29a41103 | 660 | if dlg.ShowModal() == wx.ID_OK: |
d14a1e28 | 661 | value = [] |
31f04352 | 662 | for i in range(dlg.list.GetCount()): |
efa5f709 | 663 | value.append((dlg.list.GetString(i), int(dlg.list.IsChecked(i)))) |
d14a1e28 RD |
664 | self.SetValue(value) |
665 | self.SetModified() | |
666 | self.textModified = False | |
667 | dlg.Destroy() | |
75aa1946 RR |
668 | def SetValue(self, value): |
669 | self.freeze = True | |
670 | if not value: value = [] | |
671 | self.value = value | |
c37cba89 | 672 | repr_ = '|'.join(map(str,value)) |
75aa1946 RR |
673 | self.text.SetValue(repr_) # update text ctrl |
674 | self.freeze = False | |
d14a1e28 | 675 | |
29a41103 | 676 | class IntListDialog(wx.Dialog): |
d14a1e28 | 677 | def __init__(self, parent, value): |
29a41103 | 678 | pre = wx.PreDialog() |
d14a1e28 | 679 | g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_INTLIST') |
29a41103 RD |
680 | self.PostCreate(pre) |
681 | self.list = xrc.XRCCTRL(self, 'LIST') | |
d14a1e28 RD |
682 | # Set list items |
683 | value.sort() | |
684 | for v in value: | |
685 | if type(v) != IntType: | |
29a41103 | 686 | wx.LogError('Invalid item type') |
d14a1e28 RD |
687 | else: |
688 | self.list.Append(str(v)) | |
689 | self.SetAutoLayout(True) | |
690 | self.GetSizer().Fit(self) | |
691 | # Callbacks | |
29a41103 RD |
692 | self.spinCtrl = xrc.XRCCTRL(self, 'SPIN') |
693 | wx.EVT_BUTTON(self, xrc.XRCID('BUTTON_ADD'), self.OnButtonAdd) | |
694 | self.ID_BUTTON_REMOVE = xrc.XRCID('BUTTON_REMOVE') | |
695 | wx.EVT_BUTTON(self, self.ID_BUTTON_REMOVE, self.OnButtonRemove) | |
696 | wx.EVT_BUTTON(self, xrc.XRCID('BUTTON_CLEAR'), self.OnButtonClear) | |
697 | wx.EVT_UPDATE_UI(self, self.ID_BUTTON_REMOVE, self.OnUpdateUI) | |
c032d94e | 698 | def OnButtonAdd(self, evt): |
d14a1e28 RD |
699 | # Check that it's unique |
700 | try: | |
c032d94e | 701 | v = self.spinCtrl.GetValue() |
d14a1e28 RD |
702 | s = str(v) # to be sure |
703 | i = self.list.FindString(s) | |
704 | if i == -1: # ignore non-unique | |
705 | # Find place to insert | |
706 | found = False | |
31f04352 | 707 | for i in range(self.list.GetCount()): |
d14a1e28 RD |
708 | if int(self.list.GetString(i)) > v: |
709 | found = True | |
710 | break | |
711 | if found: self.list.InsertItems([s], i) | |
712 | else: self.list.Append(s) | |
713 | except ValueError: | |
29a41103 | 714 | wx.LogError('List item is not an int!') |
d14a1e28 RD |
715 | def OnButtonRemove(self, evt): |
716 | self.list.Delete(self.list.GetSelection()) | |
c032d94e RR |
717 | def OnButtonClear(self, evt): |
718 | self.list.Clear() | |
d14a1e28 RD |
719 | def OnUpdateUI(self, evt): |
720 | if evt.GetId() == self.ID_BUTTON_REMOVE: | |
721 | evt.Enable(self.list.GetSelection() != -1) | |
722 | ||
723 | # For growable list | |
724 | class ParamIntList(ParamContent): | |
725 | def __init__(self, parent, name): | |
726 | ParamContent.__init__(self, parent, name) | |
727 | def OnButtonEdit(self, evt): | |
728 | if self.textModified: # text has newer value | |
729 | try: | |
c37cba89 | 730 | self.value = map(int, self.text.GetValue().split('|')) |
d14a1e28 | 731 | except SyntaxError: |
29a41103 | 732 | wx.LogError('Syntax error in parameter value: ' + self.GetName()) |
d14a1e28 RD |
733 | self.value = [] |
734 | dlg = IntListDialog(self, self.value) | |
29a41103 | 735 | if dlg.ShowModal() == wx.ID_OK: |
d14a1e28 | 736 | value = [] |
31f04352 | 737 | for i in range(dlg.list.GetCount()): |
d14a1e28 | 738 | value.append(int(dlg.list.GetString(i))) |
d14a1e28 RD |
739 | self.SetValue(value) |
740 | self.SetModified() | |
741 | self.textModified = False | |
742 | dlg.Destroy() | |
743 | ||
744 | # Boxless radiobox | |
745 | class RadioBox(PPanel): | |
746 | def __init__(self, parent, id, choices, | |
29a41103 | 747 | pos=wx.DefaultPosition, name='radiobox'): |
d14a1e28 | 748 | PPanel.__init__(self, parent, name) |
d14a1e28 | 749 | self.choices = choices |
29a41103 | 750 | topSizer = wx.BoxSizer() |
d14a1e28 | 751 | for i in choices: |
29a41103 RD |
752 | button = wx.RadioButton(self, -1, i, size=(-1,buttonSize[1]), name=i) |
753 | topSizer.Add(button, 0, wx.RIGHT, 5) | |
754 | wx.EVT_RADIOBUTTON(self, button.GetId(), self.OnRadioChoice) | |
d14a1e28 RD |
755 | self.SetAutoLayout(True) |
756 | self.SetSizer(topSizer) | |
757 | topSizer.Fit(self) | |
758 | def SetStringSelection(self, value): | |
759 | self.freeze = True | |
760 | for i in self.choices: | |
761 | self.FindWindowByName(i).SetValue(i == value) | |
762 | self.value = value | |
763 | self.freeze = False | |
764 | def OnRadioChoice(self, evt): | |
765 | if self.freeze: return | |
766 | if evt.GetSelection(): | |
767 | self.value = evt.GetEventObject().GetName() | |
768 | self.SetModified() | |
769 | def GetStringSelection(self): | |
770 | return self.value | |
771 | ||
772 | class ParamBool(RadioBox): | |
773 | values = {'yes': '1', 'no': '0'} | |
774 | seulav = {'1': 'yes', '0': 'no'} | |
775 | def __init__(self, parent, name): | |
a4c013b2 | 776 | RadioBox.__init__(self, parent, -1, choices=self.values.keys(), name=name) |
d14a1e28 RD |
777 | def GetValue(self): |
778 | return self.values[self.GetStringSelection()] | |
779 | def SetValue(self, value): | |
780 | if not value: value = '1' | |
781 | self.SetStringSelection(self.seulav[value]) | |
782 | ||
783 | class ParamOrient(RadioBox): | |
784 | values = {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'} | |
785 | seulav = {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'} | |
786 | def __init__(self, parent, name): | |
a4c013b2 | 787 | RadioBox.__init__(self, parent, -1, choices=self.values.keys(), name=name) |
d14a1e28 RD |
788 | def GetValue(self): |
789 | return self.values[self.GetStringSelection()] | |
790 | def SetValue(self, value): | |
791 | if not value: value = 'wxHORIZONTAL' | |
792 | self.SetStringSelection(self.seulav[value]) | |
793 | ||
68ae5821 RD |
794 | class ParamOrientation(RadioBox): |
795 | values = {'horizontal': 'horizontal', 'vertical': 'vertical'} | |
796 | seulav = {'horizontal': 'horizontal', 'vertical': 'vertical'} | |
797 | def __init__(self, parent, name): | |
798 | RadioBox.__init__(self, parent, -1, choices=self.values.keys(), name=name) | |
799 | def GetValue(self): | |
800 | return self.values[self.GetStringSelection()] | |
801 | def SetValue(self, value): | |
802 | if not value: value = 'vertical' | |
803 | self.SetStringSelection(self.seulav[value]) | |
804 | ||
d14a1e28 RD |
805 | class ParamFile(PPanel): |
806 | def __init__(self, parent, name): | |
807 | PPanel.__init__(self, parent, name) | |
29a41103 RD |
808 | self.ID_TEXT_CTRL = wx.NewId() |
809 | self.ID_BUTTON_BROWSE = wx.NewId() | |
810 | sizer = wx.BoxSizer() | |
811 | self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=wx.Size(200,-1)) | |
812 | sizer.Add(self.text, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5) | |
813 | self.button = wx.Button(self, self.ID_BUTTON_BROWSE, 'Browse...',size=buttonSize) | |
814 | sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL) | |
d14a1e28 RD |
815 | self.SetAutoLayout(True) |
816 | self.SetSizer(sizer) | |
817 | sizer.Fit(self) | |
818 | self.textModified = False | |
29a41103 RD |
819 | wx.EVT_BUTTON(self, self.ID_BUTTON_BROWSE, self.OnButtonBrowse) |
820 | wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
d14a1e28 RD |
821 | def OnChange(self, evt): |
822 | PPanel.OnChange(self, evt) | |
823 | self.textModified = True | |
824 | def GetValue(self): | |
825 | if self.textModified: # text has newer value | |
826 | return self.text.GetValue() | |
827 | return self.value | |
828 | def SetValue(self, value): | |
829 | self.freeze = True | |
830 | self.value = value | |
831 | self.text.SetValue(value) # update text ctrl | |
832 | self.freeze = False | |
833 | def OnButtonBrowse(self, evt): | |
834 | if self.textModified: # text has newer value | |
835 | self.value = self.text.GetValue() | |
29a41103 | 836 | dlg = wx.FileDialog(self, |
d14a1e28 RD |
837 | defaultDir = os.path.abspath(os.path.dirname(self.value)), |
838 | defaultFile = os.path.basename(self.value)) | |
29a41103 | 839 | if dlg.ShowModal() == wx.ID_OK: |
d14a1e28 RD |
840 | # Get common part of selected path and current |
841 | if g.frame.dataFile: | |
842 | curpath = os.path.abspath(g.frame.dataFile) | |
843 | else: | |
844 | curpath = os.path.join(os.getcwd(), '') | |
845 | common = os.path.commonprefix([curpath, dlg.GetPath()]) | |
846 | self.SetValue(dlg.GetPath()[len(common):]) | |
847 | self.SetModified() | |
848 | self.textModified = False | |
849 | dlg.Destroy() | |
850 | ||
851 | class ParamBitmap(PPanel): | |
852 | def __init__(self, parent, name): | |
29a41103 | 853 | pre = wx.PrePanel() |
d14a1e28 | 854 | g.frame.res.LoadOnPanel(pre, parent, 'PANEL_BITMAP') |
29a41103 | 855 | self.PostCreate(pre) |
d14a1e28 | 856 | self.modified = self.freeze = False |
29a41103 RD |
857 | self.radio_std = xrc.XRCCTRL(self, 'RADIO_STD') |
858 | self.radio_file = xrc.XRCCTRL(self, 'RADIO_FILE') | |
859 | self.combo = xrc.XRCCTRL(self, 'COMBO_STD') | |
860 | self.text = xrc.XRCCTRL(self, 'TEXT_FILE') | |
861 | self.button = xrc.XRCCTRL(self, 'BUTTON_BROWSE') | |
d14a1e28 RD |
862 | self.textModified = False |
863 | self.SetAutoLayout(True) | |
864 | self.GetSizer().SetMinSize((260, -1)) | |
865 | self.GetSizer().Fit(self) | |
29a41103 RD |
866 | wx.EVT_RADIOBUTTON(self, xrc.XRCID('RADIO_STD'), self.OnRadioStd) |
867 | wx.EVT_RADIOBUTTON(self, xrc.XRCID('RADIO_FILE'), self.OnRadioFile) | |
868 | wx.EVT_BUTTON(self, xrc.XRCID('BUTTON_BROWSE'), self.OnButtonBrowse) | |
869 | wx.EVT_COMBOBOX(self, xrc.XRCID('COMBO_STD'), self.OnCombo) | |
870 | wx.EVT_TEXT(self, xrc.XRCID('COMBO_STD'), self.OnChange) | |
871 | wx.EVT_TEXT(self, xrc.XRCID('TEXT_FILE'), self.OnChange) | |
d14a1e28 RD |
872 | def OnRadioStd(self, evt): |
873 | self.SetModified() | |
874 | self.SetValue(['wxART_MISSING_IMAGE','']) | |
875 | def OnRadioFile(self, evt): | |
876 | self.SetModified() | |
877 | self.SetValue(['','']) | |
878 | def updateRadios(self): | |
879 | if self.value[0]: | |
880 | self.radio_std.SetValue(True) | |
881 | self.radio_file.SetValue(False) | |
882 | self.text.Enable(False) | |
883 | self.button.Enable(False) | |
884 | self.combo.Enable(True) | |
885 | else: | |
886 | self.radio_std.SetValue(False) | |
887 | self.radio_file.SetValue(True) | |
888 | self.text.Enable(True) | |
889 | self.button.Enable(True) | |
890 | self.combo.Enable(False) | |
891 | def OnChange(self, evt): | |
892 | PPanel.OnChange(self, evt) | |
893 | self.textModified = True | |
894 | def OnCombo(self, evt): | |
895 | PPanel.OnChange(self, evt) | |
896 | self.value[0] = self.combo.GetValue() | |
897 | def GetValue(self): | |
898 | if self.textModified: # text has newer value | |
899 | return [self.combo.GetValue(), self.text.GetValue()] | |
900 | return self.value | |
901 | def SetValue(self, value): | |
902 | self.freeze = True | |
903 | if not value: | |
904 | self.value = ['', ''] | |
905 | else: | |
906 | self.value = value | |
907 | self.combo.SetValue(self.value[0]) | |
908 | self.text.SetValue(self.value[1]) # update text ctrl | |
909 | self.updateRadios() | |
910 | self.freeze = False | |
911 | def OnButtonBrowse(self, evt): | |
912 | if self.textModified: # text has newer value | |
913 | self.value[1] = self.text.GetValue() | |
29a41103 | 914 | dlg = wx.FileDialog(self, |
d14a1e28 RD |
915 | defaultDir = os.path.abspath(os.path.dirname(self.value[1])), |
916 | defaultFile = os.path.basename(self.value[1])) | |
29a41103 | 917 | if dlg.ShowModal() == wx.ID_OK: |
d14a1e28 RD |
918 | # Get common part of selected path and current |
919 | if g.frame.dataFile: | |
920 | curpath = os.path.abspath(g.frame.dataFile) | |
921 | else: | |
922 | curpath = os.path.join(os.getcwd(), '') | |
923 | common = os.path.commonprefix([curpath, dlg.GetPath()]) | |
924 | self.SetValue(['', dlg.GetPath()[len(common):]]) | |
925 | self.SetModified() | |
926 | self.textModified = False | |
927 | dlg.Destroy() | |
928 | ||
929 | paramDict = { | |
930 | 'flag': ParamFlag, | |
931 | 'style': ParamStyle, 'exstyle': ParamExStyle, | |
932 | 'pos': ParamPosSize, 'size': ParamPosSize, | |
80389ff7 | 933 | 'cellpos': ParamPosSize, 'cellspan': ParamPosSize, |
c032d94e | 934 | 'border': ParamUnit, 'cols': ParamIntNN, 'rows': ParamIntNN, |
d14a1e28 RD |
935 | 'vgap': ParamUnit, 'hgap': ParamUnit, |
936 | 'checkable': ParamBool, 'checked': ParamBool, 'radio': ParamBool, | |
937 | 'accel': ParamAccel, | |
938 | 'label': ParamMultilineText, 'title': ParamText, 'value': ParamText, | |
c032d94e | 939 | 'content': ParamContent, 'selection': ParamIntNN, |
d14a1e28 RD |
940 | 'min': ParamInt, 'max': ParamInt, |
941 | 'fg': ParamColour, 'bg': ParamColour, 'font': ParamFont, | |
942 | 'enabled': ParamBool, 'focused': ParamBool, 'hidden': ParamBool, | |
943 | 'tooltip': ParamText, 'bitmap': ParamBitmap, 'icon': ParamBitmap, | |
306b6fe9 | 944 | 'encoding': ParamEncoding, 'borders': ParamUnit |
d14a1e28 | 945 | } |