]> git.saurik.com Git - wxWidgets.git/blame - wxPython/tools/XRCed/params.py
SWIG updates for wxGTK
[wxWidgets.git] / wxPython / tools / XRCed / params.py
CommitLineData
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
7from wxPython.wx import *
8from wxPython.xrc import *
9import string
32ce09e2 10import os.path
09f3d4e6
RD
11
12# Object which is currently processed
13currentXXX = None
14def SetCurrentXXX(xxx):
15 global currentXXX
16 currentXXX = xxx
17
32ce09e2
RD
18genericStyles = ['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
25class 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
36 panel.SetModified(true)
a40b5e84
RD
37
38class 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()
32ce09e2
RD
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()
09f3d4e6
RD
103
104class 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
115class 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
121class 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 126class 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
134class 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
a40b5e84
RD
156 if not value: value = '#FFFFFF'
157 self.value = value
158 self.text.SetValue(str(value)) # update text ctrl
32ce09e2
RD
159 colour = wxColour(int(value[1:3], 16), int(value[3:5], 16), int(value[5:7], 16))
160 self.button.SetBackgroundColour(colour)
a40b5e84 161 self.button.Refresh()
32ce09e2 162 self.freeze = false
a40b5e84 163 def OnChange(self, evt):
32ce09e2
RD
164 if self.freeze: return
165 self.SetModified()
a40b5e84
RD
166 self.textModified = true
167 evt.Skip()
168 def OnPaintButton(self, evt):
169 dc = wxPaintDC(self.button)
170 dc.SetBrush(wxTRANSPARENT_BRUSH)
32ce09e2 171 if self.IsEnabled(): dc.SetPen(wxBLACK_PEN)
a40b5e84
RD
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())
32ce09e2
RD
179 self.SetModified()
180 self.textModified = false
181 dlg.Destroy()
a40b5e84
RD
182
183################################################################################
184
185# Mapping from wx constants ro XML strings
186fontFamiliesWx2Xml = {wxDEFAULT: 'default', wxDECORATIVE: 'decorative',
187 wxROMAN: 'roman', wxSCRIPT: 'script', wxSWISS: 'swiss',
188 wxMODERN: 'modern'}
189fontStylesWx2Xml = {wxNORMAL: 'normal', wxSLANT: 'slant', wxITALIC: 'italic'}
190fontWeightsWx2Xml = {wxNORMAL: 'normal', wxLIGHT: 'light', wxBOLD: 'bold'}
191def ReverseMap(m):
192 rm = {}
193 for k,v in m.items(): rm[v] = k
194 return rm
195fontFamiliesXml2wx = ReverseMap(fontFamiliesWx2Xml)
196fontStylesXml2wx = ReverseMap(fontStylesWx2Xml)
197fontWeightsXml2wx = ReverseMap(fontWeightsWx2Xml)
198
199class ParamFont(PPanel):
32ce09e2 200 def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
a40b5e84
RD
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()
32ce09e2
RD
206 self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1))
207 sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 10)
a40b5e84 208 self.button = wxButton(self, self.ID_BUTTON_SELECT, 'Select...')
32ce09e2 209 sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL)
a40b5e84
RD
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):
32ce09e2
RD
217 if self.freeze: return
218 self.SetModified()
a40b5e84
RD
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):
32ce09e2 226 self.freeze = true # disable other handlers
a40b5e84
RD
227 if not value: value = [''] * 7
228 self.value = value
229 self.text.SetValue(str(value)) # update text ctrl
32ce09e2 230 self.freeze = false
a40b5e84
RD
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)
32ce09e2
RD
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()
a40b5e84
RD
266
267################################################################################
268
269class ParamInt(PPanel):
32ce09e2 270 def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
a40b5e84
RD
271 PPanel.__init__(self, parent, id, name)
272 self.ID_SPIN_CTRL = wxNewId()
09f3d4e6 273 sizer = wxBoxSizer()
32ce09e2 274 self.spin = wxSpinCtrl(self, self.ID_SPIN_CTRL, size=wxSize(50,-1))
09f3d4e6
RD
275 self.SetBackgroundColour(panel.GetBackgroundColour())
276 sizer.Add(self.spin)
277 self.SetAutoLayout(true)
278 self.SetSizer(sizer)
279 sizer.Fit(self)
09f3d4e6
RD
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):
32ce09e2 284 self.freeze = true
09f3d4e6
RD
285 if not value: value = 0
286 self.spin.SetValue(int(value))
32ce09e2 287 self.freeze = false
09f3d4e6 288 def OnChange(self, evt):
32ce09e2
RD
289 if self.freeze: return
290 self.SetModified()
09f3d4e6
RD
291 evt.Skip()
292
32ce09e2
RD
293class 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
09f3d4e6 312 def OnChange(self, evt):
32ce09e2
RD
313 if self.freeze: return
314 self.SetModified()
09f3d4e6
RD
315 evt.Skip()
316
32ce09e2
RD
317class ParamAccel(ParamText):
318 def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
319 ParamText.__init__(self, parent, id, size, name, 50)
09f3d4e6 320
32ce09e2
RD
321class ParamPosSize(ParamText):
322 def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
323 ParamText.__init__(self, parent, id, size, name, 80)
09f3d4e6
RD
324
325class ContentDialog(wxDialog):
326 def __init__(self, parent, value):
a40b5e84 327 #wxPreDialog(self)
09f3d4e6
RD
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)
a40b5e84
RD
339 self.SetAutoLayout(true)
340 # !!! self.SetSizer(sizer)
341 self.GetSizer().Fit(self)
09f3d4e6
RD
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:
a40b5e84
RD
377 evt.Enable(self.list.GetSelection() != -1 and \
378 self.list.GetSelection() < self.list.Number() - 1)
09f3d4e6 379
a40b5e84 380class ParamContent(PPanel):
32ce09e2 381 def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
a40b5e84
RD
382 PPanel.__init__(self, parent, id, name)
383 self.ID_TEXT_CTRL = wxNewId()
384 self.ID_BUTTON_EDIT = wxNewId()
09f3d4e6 385 self.SetBackgroundColour(panel.GetBackgroundColour())
09f3d4e6 386 sizer = wxBoxSizer()
32ce09e2
RD
387 self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1))
388 sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 10)
09f3d4e6 389 self.button = wxButton(self, self.ID_BUTTON_EDIT, 'Edit...')
32ce09e2 390 sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL)
09f3d4e6
RD
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):
32ce09e2
RD
398 if self.freeze: return
399 self.SetModified()
09f3d4e6
RD
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):
32ce09e2 407 self.freeze = true
09f3d4e6
RD
408 self.value = value
409 self.text.SetValue(str(value)) # update text ctrl
32ce09e2 410 self.freeze = false
09f3d4e6
RD
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)
32ce09e2
RD
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()
09f3d4e6
RD
424
425# Boxless radiobox
a40b5e84 426class RadioBox(PPanel):
09f3d4e6
RD
427 def __init__(self, parent, id, choices,
428 pos=wxDefaultPosition, size=wxDefaultSize, name='radiobox'):
a40b5e84 429 PPanel.__init__(self, parent, id, name)
09f3d4e6
RD
430 self.SetBackgroundColour(panel.GetBackgroundColour())
431 self.choices = choices
432 topSizer = wxBoxSizer()
433 for i in choices:
32ce09e2
RD
434 button = wxRadioButton(self, -1, i, name=i)
435 topSizer.Add(button)
436 EVT_RADIOBUTTON(self, button.GetId(), self.OnRadioChoice)
09f3d4e6
RD
437 self.SetAutoLayout(true)
438 self.SetSizer(topSizer)
439 topSizer.Fit(self)
09f3d4e6 440 def SetStringSelection(self, value):
32ce09e2 441 self.freeze = true
09f3d4e6 442 for i in self.choices:
32ce09e2 443 self.FindWindowByName(i).SetValue(i == value)
09f3d4e6 444 self.value = value
32ce09e2 445 self.freeze = false
09f3d4e6 446 def OnRadioChoice(self, evt):
32ce09e2
RD
447 if self.freeze: return
448 if evt.GetSelection():
449 self.value = evt.GetEventObject().GetName()
450 self.SetModified()
09f3d4e6
RD
451 def GetStringSelection(self):
452 return self.value
453
454class ParamBool(RadioBox):
455 values = {'yes': '1', 'no': '0'}
456 seulav = {'1': 'yes', '0': 'no'}
32ce09e2 457 def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
09f3d4e6 458 RadioBox.__init__(self, parent, id, choices = self.values.keys(), name=name)
09f3d4e6
RD
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
465class ParamOrient(RadioBox):
466 values = {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'}
467 seulav = {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'}
32ce09e2 468 def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
09f3d4e6 469 RadioBox.__init__(self, parent, id, choices = self.values.keys(), name=name)
09f3d4e6
RD
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
32ce09e2
RD
476class 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
09f3d4e6
RD
521paramDict = {
522 'flag': ParamFlag,
a40b5e84 523 'style': ParamStyle, 'exstyle': ParamExStyle,
09f3d4e6
RD
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,
a40b5e84
RD
531 'fg': ParamColour, 'bg': ParamColour, 'font': ParamFont,
532 'enabled': ParamBool, 'focused': ParamBool, 'hidden': ParamBool,
32ce09e2 533 'tooltip': ParamText, 'bitmap': ParamFile, 'icon': ParamFile,
09f3d4e6 534 }
a40b5e84 535