]>
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, 'CHECK_LIST') | |
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 | def SetValue(self, value): | |
678 | self.freeze = True | |
679 | if not value: value = [] | |
680 | self.value = value | |
681 | if value: | |
682 | if len(value) == 1: repr_ = str(value) | |
683 | else: repr_ = reduce(lambda a,b: '%s|%s' % (a,b), value) | |
684 | else: | |
685 | repr_ = '' | |
686 | self.text.SetValue(repr_) # update text ctrl | |
687 | self.freeze = False | |
688 | ||
689 | class IntListDialog(wx.Dialog): | |
690 | def __init__(self, parent, value): | |
691 | pre = wx.PreDialog() | |
692 | g.frame.res.LoadOnDialog(pre, parent, 'DIALOG_INTLIST') | |
693 | self.PostCreate(pre) | |
694 | self.list = xrc.XRCCTRL(self, 'LIST') | |
695 | # Set list items | |
696 | value.sort() | |
697 | for v in value: | |
698 | if type(v) != IntType: | |
699 | wx.LogError('Invalid item type') | |
700 | else: | |
701 | self.list.Append(str(v)) | |
702 | self.SetAutoLayout(True) | |
703 | self.GetSizer().Fit(self) | |
704 | # Callbacks | |
705 | self.spinCtrl = xrc.XRCCTRL(self, 'SPIN') | |
706 | wx.EVT_BUTTON(self, xrc.XRCID('BUTTON_ADD'), self.OnButtonAdd) | |
707 | self.ID_BUTTON_REMOVE = xrc.XRCID('BUTTON_REMOVE') | |
708 | wx.EVT_BUTTON(self, self.ID_BUTTON_REMOVE, self.OnButtonRemove) | |
709 | wx.EVT_BUTTON(self, xrc.XRCID('BUTTON_CLEAR'), self.OnButtonClear) | |
710 | wx.EVT_UPDATE_UI(self, self.ID_BUTTON_REMOVE, self.OnUpdateUI) | |
711 | def OnButtonAdd(self, evt): | |
712 | # Check that it's unique | |
713 | try: | |
714 | v = self.spinCtrl.GetValue() | |
715 | s = str(v) # to be sure | |
716 | i = self.list.FindString(s) | |
717 | if i == -1: # ignore non-unique | |
718 | # Find place to insert | |
719 | found = False | |
720 | for i in range(self.list.GetCount()): | |
721 | if int(self.list.GetString(i)) > v: | |
722 | found = True | |
723 | break | |
724 | if found: self.list.InsertItems([s], i) | |
725 | else: self.list.Append(s) | |
726 | except ValueError: | |
727 | wx.LogError('List item is not an int!') | |
728 | def OnButtonRemove(self, evt): | |
729 | self.list.Delete(self.list.GetSelection()) | |
730 | def OnButtonClear(self, evt): | |
731 | self.list.Clear() | |
732 | def OnUpdateUI(self, evt): | |
733 | if evt.GetId() == self.ID_BUTTON_REMOVE: | |
734 | evt.Enable(self.list.GetSelection() != -1) | |
735 | ||
736 | # For growable list | |
737 | class ParamIntList(ParamContent): | |
738 | def __init__(self, parent, name): | |
739 | ParamContent.__init__(self, parent, name) | |
740 | def OnButtonEdit(self, evt): | |
741 | if self.textModified: # text has newer value | |
742 | try: | |
743 | self.value = eval(self.text.GetValue()) | |
744 | except SyntaxError: | |
745 | wx.LogError('Syntax error in parameter value: ' + self.GetName()) | |
746 | self.value = [] | |
747 | dlg = IntListDialog(self, self.value) | |
748 | if dlg.ShowModal() == wx.ID_OK: | |
749 | value = [] | |
750 | for i in range(dlg.list.GetCount()): | |
751 | value.append(int(dlg.list.GetString(i))) | |
752 | self.SetValue(value) | |
753 | self.SetModified() | |
754 | self.textModified = False | |
755 | dlg.Destroy() | |
756 | ||
757 | # Boxless radiobox | |
758 | class RadioBox(PPanel): | |
759 | def __init__(self, parent, id, choices, | |
760 | pos=wx.DefaultPosition, name='radiobox'): | |
761 | PPanel.__init__(self, parent, name) | |
762 | self.choices = choices | |
763 | topSizer = wx.BoxSizer() | |
764 | for i in choices: | |
765 | button = wx.RadioButton(self, -1, i, size=(-1,buttonSize[1]), name=i) | |
766 | topSizer.Add(button, 0, wx.RIGHT, 5) | |
767 | wx.EVT_RADIOBUTTON(self, button.GetId(), self.OnRadioChoice) | |
768 | self.SetAutoLayout(True) | |
769 | self.SetSizer(topSizer) | |
770 | topSizer.Fit(self) | |
771 | def SetStringSelection(self, value): | |
772 | self.freeze = True | |
773 | for i in self.choices: | |
774 | self.FindWindowByName(i).SetValue(i == value) | |
775 | self.value = value | |
776 | self.freeze = False | |
777 | def OnRadioChoice(self, evt): | |
778 | if self.freeze: return | |
779 | if evt.GetSelection(): | |
780 | self.value = evt.GetEventObject().GetName() | |
781 | self.SetModified() | |
782 | def GetStringSelection(self): | |
783 | return self.value | |
784 | ||
785 | class ParamBool(RadioBox): | |
786 | values = {'yes': '1', 'no': '0'} | |
787 | seulav = {'1': 'yes', '0': 'no'} | |
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 = '1' | |
794 | self.SetStringSelection(self.seulav[value]) | |
795 | ||
796 | class ParamOrient(RadioBox): | |
797 | values = {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'} | |
798 | seulav = {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': '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 = 'wxHORIZONTAL' | |
805 | self.SetStringSelection(self.seulav[value]) | |
806 | ||
807 | class ParamOrientation(RadioBox): | |
808 | values = {'horizontal': 'horizontal', 'vertical': 'vertical'} | |
809 | seulav = {'horizontal': 'horizontal', 'vertical': 'vertical'} | |
810 | def __init__(self, parent, name): | |
811 | RadioBox.__init__(self, parent, -1, choices=self.values.keys(), name=name) | |
812 | def GetValue(self): | |
813 | return self.values[self.GetStringSelection()] | |
814 | def SetValue(self, value): | |
815 | if not value: value = 'vertical' | |
816 | self.SetStringSelection(self.seulav[value]) | |
817 | ||
818 | class ParamFile(PPanel): | |
819 | def __init__(self, parent, name): | |
820 | PPanel.__init__(self, parent, name) | |
821 | self.ID_TEXT_CTRL = wx.NewId() | |
822 | self.ID_BUTTON_BROWSE = wx.NewId() | |
823 | sizer = wx.BoxSizer() | |
824 | self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=wx.Size(200,-1)) | |
825 | sizer.Add(self.text, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5) | |
826 | self.button = wx.Button(self, self.ID_BUTTON_BROWSE, 'Browse...',size=buttonSize) | |
827 | sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL) | |
828 | self.SetAutoLayout(True) | |
829 | self.SetSizer(sizer) | |
830 | sizer.Fit(self) | |
831 | self.textModified = False | |
832 | wx.EVT_BUTTON(self, self.ID_BUTTON_BROWSE, self.OnButtonBrowse) | |
833 | wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
834 | def OnChange(self, evt): | |
835 | PPanel.OnChange(self, evt) | |
836 | self.textModified = True | |
837 | def GetValue(self): | |
838 | if self.textModified: # text has newer value | |
839 | return self.text.GetValue() | |
840 | return self.value | |
841 | def SetValue(self, value): | |
842 | self.freeze = True | |
843 | self.value = value | |
844 | self.text.SetValue(value) # update text ctrl | |
845 | self.freeze = False | |
846 | def OnButtonBrowse(self, evt): | |
847 | if self.textModified: # text has newer value | |
848 | self.value = self.text.GetValue() | |
849 | dlg = wx.FileDialog(self, | |
850 | defaultDir = os.path.abspath(os.path.dirname(self.value)), | |
851 | defaultFile = os.path.basename(self.value)) | |
852 | if dlg.ShowModal() == wx.ID_OK: | |
853 | # Get common part of selected path and current | |
854 | if g.frame.dataFile: | |
855 | curpath = os.path.abspath(g.frame.dataFile) | |
856 | else: | |
857 | curpath = os.path.join(os.getcwd(), '') | |
858 | common = os.path.commonprefix([curpath, dlg.GetPath()]) | |
859 | self.SetValue(dlg.GetPath()[len(common):]) | |
860 | self.SetModified() | |
861 | self.textModified = False | |
862 | dlg.Destroy() | |
863 | ||
864 | class ParamBitmap(PPanel): | |
865 | def __init__(self, parent, name): | |
866 | pre = wx.PrePanel() | |
867 | g.frame.res.LoadOnPanel(pre, parent, 'PANEL_BITMAP') | |
868 | self.PostCreate(pre) | |
869 | self.modified = self.freeze = False | |
870 | self.radio_std = xrc.XRCCTRL(self, 'RADIO_STD') | |
871 | self.radio_file = xrc.XRCCTRL(self, 'RADIO_FILE') | |
872 | self.combo = xrc.XRCCTRL(self, 'COMBO_STD') | |
873 | self.text = xrc.XRCCTRL(self, 'TEXT_FILE') | |
874 | self.button = xrc.XRCCTRL(self, 'BUTTON_BROWSE') | |
875 | self.textModified = False | |
876 | self.SetAutoLayout(True) | |
877 | self.GetSizer().SetMinSize((260, -1)) | |
878 | self.GetSizer().Fit(self) | |
879 | wx.EVT_RADIOBUTTON(self, xrc.XRCID('RADIO_STD'), self.OnRadioStd) | |
880 | wx.EVT_RADIOBUTTON(self, xrc.XRCID('RADIO_FILE'), self.OnRadioFile) | |
881 | wx.EVT_BUTTON(self, xrc.XRCID('BUTTON_BROWSE'), self.OnButtonBrowse) | |
882 | wx.EVT_COMBOBOX(self, xrc.XRCID('COMBO_STD'), self.OnCombo) | |
883 | wx.EVT_TEXT(self, xrc.XRCID('COMBO_STD'), self.OnChange) | |
884 | wx.EVT_TEXT(self, xrc.XRCID('TEXT_FILE'), self.OnChange) | |
885 | def OnRadioStd(self, evt): | |
886 | self.SetModified() | |
887 | self.SetValue(['wxART_MISSING_IMAGE','']) | |
888 | def OnRadioFile(self, evt): | |
889 | self.SetModified() | |
890 | self.SetValue(['','']) | |
891 | def updateRadios(self): | |
892 | if self.value[0]: | |
893 | self.radio_std.SetValue(True) | |
894 | self.radio_file.SetValue(False) | |
895 | self.text.Enable(False) | |
896 | self.button.Enable(False) | |
897 | self.combo.Enable(True) | |
898 | else: | |
899 | self.radio_std.SetValue(False) | |
900 | self.radio_file.SetValue(True) | |
901 | self.text.Enable(True) | |
902 | self.button.Enable(True) | |
903 | self.combo.Enable(False) | |
904 | def OnChange(self, evt): | |
905 | PPanel.OnChange(self, evt) | |
906 | self.textModified = True | |
907 | def OnCombo(self, evt): | |
908 | PPanel.OnChange(self, evt) | |
909 | self.value[0] = self.combo.GetValue() | |
910 | def GetValue(self): | |
911 | if self.textModified: # text has newer value | |
912 | return [self.combo.GetValue(), self.text.GetValue()] | |
913 | return self.value | |
914 | def SetValue(self, value): | |
915 | self.freeze = True | |
916 | if not value: | |
917 | self.value = ['', ''] | |
918 | else: | |
919 | self.value = value | |
920 | self.combo.SetValue(self.value[0]) | |
921 | self.text.SetValue(self.value[1]) # update text ctrl | |
922 | self.updateRadios() | |
923 | self.freeze = False | |
924 | def OnButtonBrowse(self, evt): | |
925 | if self.textModified: # text has newer value | |
926 | self.value[1] = self.text.GetValue() | |
927 | dlg = wx.FileDialog(self, | |
928 | defaultDir = os.path.abspath(os.path.dirname(self.value[1])), | |
929 | defaultFile = os.path.basename(self.value[1])) | |
930 | if dlg.ShowModal() == wx.ID_OK: | |
931 | # Get common part of selected path and current | |
932 | if g.frame.dataFile: | |
933 | curpath = os.path.abspath(g.frame.dataFile) | |
934 | else: | |
935 | curpath = os.path.join(os.getcwd(), '') | |
936 | common = os.path.commonprefix([curpath, dlg.GetPath()]) | |
937 | self.SetValue(['', dlg.GetPath()[len(common):]]) | |
938 | self.SetModified() | |
939 | self.textModified = False | |
940 | dlg.Destroy() | |
941 | ||
942 | paramDict = { | |
943 | 'flag': ParamFlag, | |
944 | 'style': ParamStyle, 'exstyle': ParamExStyle, | |
945 | 'pos': ParamPosSize, 'size': ParamPosSize, | |
946 | 'cellpos': ParamPosSize, 'cellspan': ParamPosSize, | |
947 | 'border': ParamUnit, 'cols': ParamIntNN, 'rows': ParamIntNN, | |
948 | 'vgap': ParamUnit, 'hgap': ParamUnit, | |
949 | 'checkable': ParamBool, 'checked': ParamBool, 'radio': ParamBool, | |
950 | 'accel': ParamAccel, | |
951 | 'label': ParamMultilineText, 'title': ParamText, 'value': ParamText, | |
952 | 'content': ParamContent, 'selection': ParamIntNN, | |
953 | 'min': ParamInt, 'max': ParamInt, | |
954 | 'fg': ParamColour, 'bg': ParamColour, 'font': ParamFont, | |
955 | 'enabled': ParamBool, 'focused': ParamBool, 'hidden': ParamBool, | |
956 | 'tooltip': ParamText, 'bitmap': ParamBitmap, 'icon': ParamBitmap, | |
957 | 'encoding': ParamEncoding, 'borders': ParamUnit | |
958 | } |