]>
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 | from wxPython.wx import * | |
8 | from wxPython.xrc import * | |
9 | import string | |
10 | import os.path | |
11 | ||
12 | # Object which is currently processed | |
13 | currentXXX = None | |
14 | def SetCurrentXXX(xxx): | |
15 | global currentXXX | |
16 | currentXXX = xxx | |
17 | ||
18 | genericStyles = ['wxSIMPLE_BORDER', 'wxDOUBLE_BORDER', | |
19 | 'wxSUNKEN_BORDER', 'wxRAISED_BORDER', | |
20 | 'wxSTATIC_BORDER', 'wxNO_BORDER', | |
21 | 'wxTRANSPARENT_WINDOW', 'wxWANTS_CHARS', | |
22 | 'wxNO_FULL_REPAINT_ON_RESIZE'] | |
23 | ||
24 | # Class that can properly disable children | |
25 | class PPanel(wxPanel): | |
26 | def __init__(self, parent, id, name): | |
27 | wxPanel.__init__(self, parent, id, name=name) | |
28 | self.modified = self.freeze = false | |
29 | def Enable(self, value): | |
30 | # Something strange is going on with enable so we make sure... | |
31 | for w in self.GetChildren(): | |
32 | w.Enable(value) | |
33 | wxPanel.Enable(self, value) | |
34 | def SetModified(self): | |
35 | self.modified = true | |
36 | panel.SetModified(true) | |
37 | ||
38 | class ParamBinaryOr(PPanel): | |
39 | def __init__(self, parent, id, size, name): | |
40 | PPanel.__init__(self, parent, id, name) | |
41 | self.ID_TEXT_CTRL = wxNewId() | |
42 | self.ID_BUTTON_CHOICES = wxNewId() | |
43 | self.SetBackgroundColour(panel.GetBackgroundColour()) | |
44 | sizer = wxBoxSizer() | |
45 | self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1)) | |
46 | sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 10) | |
47 | self.button = wxButton(self, self.ID_BUTTON_CHOICES, 'Edit...') | |
48 | sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL) | |
49 | self.SetAutoLayout(true) | |
50 | self.SetSizer(sizer) | |
51 | sizer.Fit(self) | |
52 | EVT_BUTTON(self, self.ID_BUTTON_CHOICES, self.OnButtonChoices) | |
53 | EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
54 | def OnChange(self, evt): | |
55 | if self.freeze: return | |
56 | self.SetModified() | |
57 | evt.Skip() | |
58 | def GetValue(self): | |
59 | return self.text.GetValue() | |
60 | def SetValue(self, value): | |
61 | self.freeze = true | |
62 | self.text.SetValue(value) | |
63 | self.freeze = false | |
64 | def OnButtonChoices(self, evt): | |
65 | dlg = wxDialog(self, -1, 'Choices') | |
66 | topSizer = wxBoxSizer(wxVERTICAL) | |
67 | listBox = wxCheckListBox(dlg, -1, choices=self.values, size=(250,200)) | |
68 | value = map(string.strip, string.split(self.text.GetValue(), '|')) | |
69 | if value == ['']: value = [] | |
70 | ignored = [] | |
71 | for i in value: | |
72 | try: | |
73 | listBox.Check(self.values.index(i)) | |
74 | except ValueError: | |
75 | # Try to find equal | |
76 | if self.equal.has_key(i): | |
77 | listBox.Check(self.values.index(self.equal[i])) | |
78 | else: | |
79 | print 'WARNING: unknown flag: %s: ignored.' % i | |
80 | ignored.append(i) | |
81 | topSizer.Add(listBox, 1, wxEXPAND) | |
82 | sizer = wxBoxSizer() | |
83 | buttonOk = wxButton(dlg, wxID_OK, 'OK') | |
84 | buttonOk.SetDefault() | |
85 | sizer.Add(buttonOk, 0, wxRIGHT, 10) | |
86 | sizer.Add(0, 0, 1) | |
87 | sizer.Add(wxButton(dlg, wxID_CANCEL, 'Cancel')) | |
88 | topSizer.Add(sizer, 0, wxALL | wxEXPAND, 10) | |
89 | dlg.SetAutoLayout(true) | |
90 | dlg.SetSizer(topSizer) | |
91 | topSizer.Fit(dlg) | |
92 | dlg.Center() | |
93 | if dlg.ShowModal() == wxID_OK: | |
94 | value = [] | |
95 | for i in range(listBox.Number()): | |
96 | if listBox.IsChecked(i): | |
97 | value.append(self.values[i]) | |
98 | # Add ignored flags | |
99 | value.extend(ignored) | |
100 | self.SetValue(reduce(lambda a,b: a+'|'+b, value)) | |
101 | self.SetModified() | |
102 | dlg.Destroy() | |
103 | ||
104 | class ParamFlag(ParamBinaryOr): | |
105 | values = ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL', | |
106 | 'wxEXPAND', 'wxSHAPED', 'wxALIGN_CENTRE', 'wxALIGN_RIGHT', | |
107 | 'wxALIGN_BOTTOM', 'wxALIGN_CENTRE_VERTICAL', | |
108 | 'wxALIGN_CENTRE_HORIZONTAL'] | |
109 | equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE', | |
110 | 'wxALIGN_CENTER_VERTICAL': 'wxALIGN_CENTRE_VERTICAL', | |
111 | 'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL'} | |
112 | def __init__(self, parent, id, size, name): | |
113 | ParamBinaryOr.__init__(self, parent, id, size, name) | |
114 | ||
115 | class ParamStyle(ParamBinaryOr): | |
116 | equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE'} | |
117 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
118 | self.values = currentXXX.winStyles + genericStyles | |
119 | ParamBinaryOr.__init__(self, parent, id, size, name) | |
120 | ||
121 | class ParamNonGenericStyle(ParamBinaryOr): | |
122 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
123 | self.values = currentXXX.winStyles | |
124 | ParamBinaryOr.__init__(self, parent, id, size, name) | |
125 | ||
126 | class ParamExStyle(ParamBinaryOr): | |
127 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
128 | if currentXXX: | |
129 | self.values = currentXXX.exStyles # constant at the moment | |
130 | else: | |
131 | self.values = [] | |
132 | ParamBinaryOr.__init__(self, parent, id, size, name) | |
133 | ||
134 | class ParamColour(PPanel): | |
135 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
136 | PPanel.__init__(self, parent, id, name) | |
137 | self.ID_TEXT_CTRL = wxNewId() | |
138 | self.ID_BUTTON = wxNewId() | |
139 | self.SetBackgroundColour(panel.GetBackgroundColour()) | |
140 | sizer = wxBoxSizer() | |
141 | self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(60,-1)) | |
142 | sizer.Add(self.text, 0, wxRIGHT, 10) | |
143 | self.button = wxPanel(self, self.ID_BUTTON, wxDefaultPosition, wxSize(40, -1)) | |
144 | sizer.Add(self.button, 0, wxGROW) | |
145 | self.SetAutoLayout(true) | |
146 | self.SetSizer(sizer) | |
147 | sizer.Fit(self) | |
148 | self.textModified = false | |
149 | EVT_PAINT(self.button, self.OnPaintButton) | |
150 | EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
151 | EVT_LEFT_DOWN(self.button, self.OnLeftDown) | |
152 | def GetValue(self): | |
153 | return self.value | |
154 | def SetValue(self, value): | |
155 | self.freeze = true | |
156 | if not value: value = '#FFFFFF' | |
157 | self.value = value | |
158 | self.text.SetValue(str(value)) # update text ctrl | |
159 | colour = wxColour(int(value[1:3], 16), int(value[3:5], 16), int(value[5:7], 16)) | |
160 | self.button.SetBackgroundColour(colour) | |
161 | self.button.Refresh() | |
162 | self.freeze = false | |
163 | def OnChange(self, evt): | |
164 | if self.freeze: return | |
165 | self.SetModified() | |
166 | self.textModified = true | |
167 | evt.Skip() | |
168 | def OnPaintButton(self, evt): | |
169 | dc = wxPaintDC(self.button) | |
170 | dc.SetBrush(wxTRANSPARENT_BRUSH) | |
171 | if self.IsEnabled(): dc.SetPen(wxBLACK_PEN) | |
172 | else: dc.SetPen(wxGREY_PEN) | |
173 | size = self.button.GetSize() | |
174 | dc.DrawRectangle(0, 0, size.x, size.y) | |
175 | def OnLeftDown(self, evt): | |
176 | dlg = wxColourDialog(self) | |
177 | if dlg.ShowModal() == wxID_OK: | |
178 | self.SetValue('#%02X%02X%02X' % dlg.GetColourData().GetColour().Get()) | |
179 | self.SetModified() | |
180 | self.textModified = false | |
181 | dlg.Destroy() | |
182 | ||
183 | ################################################################################ | |
184 | ||
185 | # Mapping from wx constants ro XML strings | |
186 | fontFamiliesWx2Xml = {wxDEFAULT: 'default', wxDECORATIVE: 'decorative', | |
187 | wxROMAN: 'roman', wxSCRIPT: 'script', wxSWISS: 'swiss', | |
188 | wxMODERN: 'modern'} | |
189 | fontStylesWx2Xml = {wxNORMAL: 'normal', wxSLANT: 'slant', wxITALIC: 'italic'} | |
190 | fontWeightsWx2Xml = {wxNORMAL: 'normal', wxLIGHT: 'light', wxBOLD: 'bold'} | |
191 | def ReverseMap(m): | |
192 | rm = {} | |
193 | for k,v in m.items(): rm[v] = k | |
194 | return rm | |
195 | fontFamiliesXml2wx = ReverseMap(fontFamiliesWx2Xml) | |
196 | fontStylesXml2wx = ReverseMap(fontStylesWx2Xml) | |
197 | fontWeightsXml2wx = ReverseMap(fontWeightsWx2Xml) | |
198 | ||
199 | class ParamFont(PPanel): | |
200 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
201 | PPanel.__init__(self, parent, id, name) | |
202 | self.ID_TEXT_CTRL = wxNewId() | |
203 | self.ID_BUTTON_SELECT = wxNewId() | |
204 | self.SetBackgroundColour(panel.GetBackgroundColour()) | |
205 | sizer = wxBoxSizer() | |
206 | self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1)) | |
207 | sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 10) | |
208 | self.button = wxButton(self, self.ID_BUTTON_SELECT, 'Select...') | |
209 | sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL) | |
210 | self.SetAutoLayout(true) | |
211 | self.SetSizer(sizer) | |
212 | sizer.Fit(self) | |
213 | self.textModified = false | |
214 | EVT_BUTTON(self, self.ID_BUTTON_SELECT, self.OnButtonSelect) | |
215 | EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
216 | def OnChange(self, evt): | |
217 | if self.freeze: return | |
218 | self.SetModified() | |
219 | self.textModified = true | |
220 | evt.Skip() | |
221 | def GetValue(self): | |
222 | if self.textModified: # text has newer value | |
223 | return eval(self.text.GetValue()) | |
224 | return self.value | |
225 | def SetValue(self, value): | |
226 | self.freeze = true # disable other handlers | |
227 | if not value: value = [''] * 7 | |
228 | self.value = value | |
229 | self.text.SetValue(str(value)) # update text ctrl | |
230 | self.freeze = false | |
231 | def OnButtonSelect(self, evt): | |
232 | if self.textModified: # text has newer value | |
233 | self.value = eval(self.text.GetValue()) | |
234 | # Make initial font | |
235 | try: size = int(self.value[0]) | |
236 | except ValueError: size = 12 | |
237 | try: family = fontFamiliesXml2wx[self.value[1]] | |
238 | except KeyError: family = wxDEFAULT | |
239 | try: style = fontStylesXml2wx[self.value[2]] | |
240 | except KeyError: style = wxNORMAL | |
241 | try: weight = fontWeightsXml2wx[self.value[3]] | |
242 | except KeyError: weight = wxNORMAL | |
243 | try: underlined = int(self.value[4]) | |
244 | except ValueError: underlined = 0 | |
245 | face = self.value[5] | |
246 | mapper = wxFontMapper() | |
247 | enc = wxFONTENCODING_DEFAULT | |
248 | if not self.value[6]: enc = mapper.CharsetToEncoding(self.value[6]) | |
249 | if enc == wxFONTENCODING_DEFAULT: enc = wxFONTENCODING_SYSTEM | |
250 | font = wxFont(size, family, style, weight, underlined, face, enc) | |
251 | data = wxFontData() | |
252 | data.SetInitialFont(font) | |
253 | dlg = wxFontDialog(self, data) | |
254 | if dlg.ShowModal() == wxID_OK: | |
255 | font = dlg.GetFontData().GetChosenFont() | |
256 | value = [str(font.GetPointSize()), fontFamiliesWx2Xml[font.GetFamily()], | |
257 | fontStylesWx2Xml[font.GetStyle()], | |
258 | fontWeightsWx2Xml[font.GetWeight()], | |
259 | str(font.GetUnderlined()), font.GetFaceName(), | |
260 | wxFontMapper_GetEncodingName(font.GetEncoding())] | |
261 | # Add ignored flags | |
262 | self.SetValue(value) | |
263 | self.SetModified() | |
264 | self.textModified = false | |
265 | dlg.Destroy() | |
266 | ||
267 | ################################################################################ | |
268 | ||
269 | class ParamInt(PPanel): | |
270 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
271 | PPanel.__init__(self, parent, id, name) | |
272 | self.ID_SPIN_CTRL = wxNewId() | |
273 | sizer = wxBoxSizer() | |
274 | self.spin = wxSpinCtrl(self, self.ID_SPIN_CTRL, size=wxSize(50,-1)) | |
275 | self.SetBackgroundColour(panel.GetBackgroundColour()) | |
276 | sizer.Add(self.spin) | |
277 | self.SetAutoLayout(true) | |
278 | self.SetSizer(sizer) | |
279 | sizer.Fit(self) | |
280 | EVT_SPINCTRL(self, self.ID_SPIN_CTRL, self.OnChange) | |
281 | def GetValue(self): | |
282 | return str(self.spin.GetValue()) | |
283 | def SetValue(self, value): | |
284 | self.freeze = true | |
285 | if not value: value = 0 | |
286 | self.spin.SetValue(int(value)) | |
287 | self.freeze = false | |
288 | def OnChange(self, evt): | |
289 | if self.freeze: return | |
290 | self.SetModified() | |
291 | evt.Skip() | |
292 | ||
293 | class ParamText(PPanel): | |
294 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = '', textWidth=200): | |
295 | PPanel.__init__(self, parent, id, name) | |
296 | self.ID_TEXT_CTRL = wxNewId() | |
297 | # We use sizer even here to have the same size of text control | |
298 | sizer = wxBoxSizer() | |
299 | self.SetBackgroundColour(panel.GetBackgroundColour()) | |
300 | self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(textWidth,-1)) | |
301 | sizer.Add(self.text, 0, wxALIGN_CENTER_VERTICAL) | |
302 | self.SetAutoLayout(true) | |
303 | self.SetSizer(sizer) | |
304 | sizer.Fit(self) | |
305 | EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
306 | def GetValue(self): | |
307 | return self.text.GetValue() | |
308 | def SetValue(self, value): | |
309 | self.freeze = true # disable other handlers | |
310 | self.text.SetValue(value) | |
311 | self.freeze = false # disable other handlers | |
312 | def OnChange(self, evt): | |
313 | if self.freeze: return | |
314 | self.SetModified() | |
315 | evt.Skip() | |
316 | ||
317 | class ParamAccel(ParamText): | |
318 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
319 | ParamText.__init__(self, parent, id, size, name, 50) | |
320 | ||
321 | class ParamPosSize(ParamText): | |
322 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
323 | ParamText.__init__(self, parent, id, size, name, 80) | |
324 | ||
325 | class ContentDialog(wxDialog): | |
326 | def __init__(self, parent, value): | |
327 | #wxPreDialog(self) | |
328 | # Use another constructor | |
329 | w = frame.res.LoadDialog(parent, 'ID_DIALOG_CONTENT') | |
330 | self.this = w.this | |
331 | w.thisown = 0 | |
332 | self.thisown = 1 | |
333 | #frame.res.LoadOnDialog(self, parent, 'ID_DIALOG_CONTENT') | |
334 | self.Center() | |
335 | self.list = self.FindWindowByName('ID_LIST') | |
336 | # Set list items | |
337 | for v in value: | |
338 | self.list.Append(v) | |
339 | self.SetAutoLayout(true) | |
340 | # !!! self.SetSizer(sizer) | |
341 | self.GetSizer().Fit(self) | |
342 | # Callbacks | |
343 | self.ID_BUTTON_APPEND = XMLID('ID_BUTTON_APPEND') | |
344 | self.ID_BUTTON_REMOVE = XMLID('ID_BUTTON_REMOVE') | |
345 | self.ID_BUTTON_UP = XMLID('ID_BUTTON_UP') | |
346 | self.ID_BUTTON_DOWN = XMLID('ID_BUTTON_DOWN') | |
347 | EVT_BUTTON(self, self.ID_BUTTON_UP, self.OnButtonUp) | |
348 | EVT_BUTTON(self, self.ID_BUTTON_DOWN, self.OnButtonDown) | |
349 | EVT_BUTTON(self, self.ID_BUTTON_APPEND, self.OnButtonAppend) | |
350 | EVT_BUTTON(self, self.ID_BUTTON_REMOVE, self.OnButtonRemove) | |
351 | EVT_UPDATE_UI(self, self.ID_BUTTON_UP, self.OnUpdateUI) | |
352 | EVT_UPDATE_UI(self, self.ID_BUTTON_DOWN, self.OnUpdateUI) | |
353 | EVT_UPDATE_UI(self, self.ID_BUTTON_REMOVE, self.OnUpdateUI) | |
354 | def OnButtonUp(self, evt): | |
355 | i = self.list.GetSelection() | |
356 | str = self.list.GetString(i) | |
357 | self.list.Delete(i) | |
358 | self.list.InsertItems([str], i-1) | |
359 | self.list.SetSelection(i-1) | |
360 | def OnButtonDown(self, evt): | |
361 | i = self.list.GetSelection() | |
362 | str = self.list.GetString(i) | |
363 | self.list.Delete(i) | |
364 | self.list.InsertItems([str], i+1) | |
365 | self.list.SetSelection(i+1) | |
366 | def OnButtonAppend(self, evt): | |
367 | str = wxGetTextFromUser('Enter new item:', 'Append', '', self) | |
368 | self.list.Append(str) | |
369 | def OnButtonRemove(self, evt): | |
370 | self.list.Delete(self.list.GetSelection()) | |
371 | def OnUpdateUI(self, evt): | |
372 | if evt.GetId() == self.ID_BUTTON_REMOVE: | |
373 | evt.Enable(self.list.GetSelection() != -1) | |
374 | elif evt.GetId() == self.ID_BUTTON_UP: | |
375 | evt.Enable(self.list.GetSelection() > 0) | |
376 | elif evt.GetId() == self.ID_BUTTON_DOWN: | |
377 | evt.Enable(self.list.GetSelection() != -1 and \ | |
378 | self.list.GetSelection() < self.list.Number() - 1) | |
379 | ||
380 | class ParamContent(PPanel): | |
381 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
382 | PPanel.__init__(self, parent, id, name) | |
383 | self.ID_TEXT_CTRL = wxNewId() | |
384 | self.ID_BUTTON_EDIT = wxNewId() | |
385 | self.SetBackgroundColour(panel.GetBackgroundColour()) | |
386 | sizer = wxBoxSizer() | |
387 | self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1)) | |
388 | sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 10) | |
389 | self.button = wxButton(self, self.ID_BUTTON_EDIT, 'Edit...') | |
390 | sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL) | |
391 | self.SetAutoLayout(true) | |
392 | self.SetSizer(sizer) | |
393 | sizer.Fit(self) | |
394 | self.textModified = false | |
395 | EVT_BUTTON(self, self.ID_BUTTON_EDIT, self.OnButtonEdit) | |
396 | EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
397 | def OnChange(self, evt): | |
398 | if self.freeze: return | |
399 | self.SetModified() | |
400 | self.textModified = true | |
401 | evt.Skip() | |
402 | def GetValue(self): | |
403 | if self.textModified: # text has newer value | |
404 | return eval(self.text.GetValue()) | |
405 | return self.value | |
406 | def SetValue(self, value): | |
407 | self.freeze = true | |
408 | self.value = value | |
409 | self.text.SetValue(str(value)) # update text ctrl | |
410 | self.freeze = false | |
411 | def OnButtonEdit(self, evt): | |
412 | if self.textModified: # text has newer value | |
413 | self.value = eval(self.text.GetValue()) | |
414 | dlg = ContentDialog(self, self.value) | |
415 | if dlg.ShowModal() == wxID_OK: | |
416 | value = [] | |
417 | for i in range(dlg.list.Number()): | |
418 | value.append(dlg.list.GetString(i)) | |
419 | # Add ignored flags | |
420 | self.SetValue(value) | |
421 | self.SetModified() | |
422 | self.textModified = false | |
423 | dlg.Destroy() | |
424 | ||
425 | # Boxless radiobox | |
426 | class RadioBox(PPanel): | |
427 | def __init__(self, parent, id, choices, | |
428 | pos=wxDefaultPosition, size=wxDefaultSize, name='radiobox'): | |
429 | PPanel.__init__(self, parent, id, name) | |
430 | self.SetBackgroundColour(panel.GetBackgroundColour()) | |
431 | self.choices = choices | |
432 | topSizer = wxBoxSizer() | |
433 | for i in choices: | |
434 | button = wxRadioButton(self, -1, i, name=i) | |
435 | topSizer.Add(button) | |
436 | EVT_RADIOBUTTON(self, button.GetId(), self.OnRadioChoice) | |
437 | self.SetAutoLayout(true) | |
438 | self.SetSizer(topSizer) | |
439 | topSizer.Fit(self) | |
440 | def SetStringSelection(self, value): | |
441 | self.freeze = true | |
442 | for i in self.choices: | |
443 | self.FindWindowByName(i).SetValue(i == value) | |
444 | self.value = value | |
445 | self.freeze = false | |
446 | def OnRadioChoice(self, evt): | |
447 | if self.freeze: return | |
448 | if evt.GetSelection(): | |
449 | self.value = evt.GetEventObject().GetName() | |
450 | self.SetModified() | |
451 | def GetStringSelection(self): | |
452 | return self.value | |
453 | ||
454 | class ParamBool(RadioBox): | |
455 | values = {'yes': '1', 'no': '0'} | |
456 | seulav = {'1': 'yes', '0': 'no'} | |
457 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
458 | RadioBox.__init__(self, parent, id, choices = self.values.keys(), name=name) | |
459 | def GetValue(self): | |
460 | return self.values[self.GetStringSelection()] | |
461 | def SetValue(self, value): | |
462 | if not value: value = '1' | |
463 | self.SetStringSelection(self.seulav[value]) | |
464 | ||
465 | class ParamOrient(RadioBox): | |
466 | values = {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'} | |
467 | seulav = {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'} | |
468 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
469 | RadioBox.__init__(self, parent, id, choices = self.values.keys(), name=name) | |
470 | def GetValue(self): | |
471 | return self.values[self.GetStringSelection()] | |
472 | def SetValue(self, value): | |
473 | if not value: value = 'wxHORIZONTAL' | |
474 | self.SetStringSelection(self.seulav[value]) | |
475 | ||
476 | class ParamFile(PPanel): | |
477 | def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''): | |
478 | PPanel.__init__(self, parent, id, name) | |
479 | self.ID_TEXT_CTRL = wxNewId() | |
480 | self.ID_BUTTON_BROWSE = wxNewId() | |
481 | self.SetBackgroundColour(panel.GetBackgroundColour()) | |
482 | sizer = wxBoxSizer() | |
483 | self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1)) | |
484 | sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 10) | |
485 | self.button = wxButton(self, self.ID_BUTTON_BROWSE, 'Browse...') | |
486 | sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL) | |
487 | self.SetAutoLayout(true) | |
488 | self.SetSizer(sizer) | |
489 | sizer.Fit(self) | |
490 | self.textModified = false | |
491 | EVT_BUTTON(self, self.ID_BUTTON_BROWSE, self.OnButtonBrowse) | |
492 | EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange) | |
493 | def OnChange(self, evt): | |
494 | if self.freeze: return | |
495 | self.SetModified() | |
496 | self.textModified = true | |
497 | evt.Skip() | |
498 | def GetValue(self): | |
499 | if self.textModified: # text has newer value | |
500 | return eval(self.text.GetValue()) | |
501 | return self.value | |
502 | def SetValue(self, value): | |
503 | self.freeze = true | |
504 | self.value = value | |
505 | self.text.SetValue(value) # update text ctrl | |
506 | self.freeze = false | |
507 | def OnButtonBrowse(self, evt): | |
508 | if self.textModified: # text has newer value | |
509 | self.value = self.text.GetValue() | |
510 | dlg = wxFileDialog(self, | |
511 | defaultDir = os.path.abspath(os.path.dirname(self.value)), | |
512 | defaultFile = os.path.basename(self.value)) | |
513 | if dlg.ShowModal() == wxID_OK: | |
514 | # Make relative | |
515 | common = os.path.commonprefix([frame.dataFile, dlg.GetPath()]) | |
516 | self.SetValue(dlg.GetPath()[len(common):]) | |
517 | self.SetModified() | |
518 | self.textModified = false | |
519 | dlg.Destroy() | |
520 | ||
521 | paramDict = { | |
522 | 'flag': ParamFlag, | |
523 | 'style': ParamStyle, 'exstyle': ParamExStyle, | |
524 | 'pos': ParamPosSize, 'size': ParamPosSize, | |
525 | 'border': ParamInt, 'cols': ParamInt, 'rows': ParamInt, | |
526 | 'vgap': ParamInt, 'hgap': ParamInt, | |
527 | 'checkable': ParamBool, 'accel': ParamAccel, | |
528 | 'label': ParamText, 'title': ParamText, 'value': ParamText, | |
529 | 'content': ParamContent, 'selection': ParamInt, | |
530 | 'min': ParamInt, 'max': ParamInt, | |
531 | 'fg': ParamColour, 'bg': ParamColour, 'font': ParamFont, | |
532 | 'enabled': ParamBool, 'focused': ParamBool, 'hidden': ParamBool, | |
533 | 'tooltip': ParamText, 'bitmap': ParamFile, 'icon': ParamFile, | |
534 | } | |
535 |