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