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