2 # Purpose: Classes for parameter introduction
3 # Author: Roman Rolinsky <rolinsky@mema.ucl.ac.be>
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'
20 'wxWS_EX_VALIDATE_RECURSIVELY',
21 'wxWS_EX_BLOCK_EVENTS',
23 'wxFRAME_EX_CONTEXTHELP',
24 'wxWS_EX_PROCESS_IDLE',
25 'wxWS_EX_PROCESS_UI_UPDATES'
28 buttonSize
= (35,-1) # in dialog units, transformed to pixels in panel ctor
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():
39 #wx.Panel.Enable(self, value)
40 def SetModified(self
, state
=True):
42 if state
: g
.panel
.SetModified(True)
43 # Common method to set modified state
44 def OnChange(self
, evt
):
45 if self
.freeze
: return
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()
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
.SetSizerAndFit(sizer
)
61 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_CHOICES
, self
.OnButtonChoices
)
62 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
64 return self
.text
.GetValue()
65 def SetValue(self
, value
):
67 self
.text
.SetValue(value
)
69 def OnButtonChoices(self
, evt
):
70 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_CHOICES')
71 if self
.GetName() == 'flag': dlg
.SetTitle('Sizer item flags')
72 elif self
.GetName() == 'style': dlg
.SetTitle('Window styles')
73 elif self
.GetName() == 'exstyle': dlg
.SetTitle('Extended window styles')
74 listBox
= xrc
.XRCCTRL(dlg
, 'CHECKLIST')
75 listBox
.InsertItems(self
.values
, 0)
76 value
= map(string
.strip
, self
.text
.GetValue().split('|'))
77 if value
== ['']: value
= []
81 listBox
.Check(self
.values
.index(i
))
84 if self
.equal
.has_key(i
):
85 listBox
.Check(self
.values
.index(self
.equal
[i
]))
87 print 'WARNING: unknown flag: %s: ignored.' % i
89 if dlg
.ShowModal() == wx
.ID_OK
:
91 for i
in range(listBox
.GetCount()):
92 if listBox
.IsChecked(i
):
93 value
.append(self
.values
[i
])
96 self
.SetValue('|'.join(value
))
100 class ParamFlag(ParamBinaryOr
):
101 values
= ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL',
102 'wxEXPAND', 'wxGROW', 'wxSHAPED', 'wxSTRETCH_NOT',
103 'wxALIGN_CENTRE', 'wxALIGN_LEFT', 'wxALIGN_RIGHT',
104 'wxALIGN_TOP', 'wxALIGN_BOTTOM',
105 'wxALIGN_CENTRE_VERTICAL', 'wxALIGN_CENTRE_HORIZONTAL',
106 'wxADJUST_MINSIZE', 'wxFIXED_MINSIZE'
108 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE',
109 'wxALIGN_CENTER_VERTICAL': 'wxALIGN_CENTRE_VERTICAL',
110 'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL',
111 'wxUP': 'wxTOP', 'wxDOWN': 'wxBOTTOM', 'wxNORTH': 'wxTOP',
112 'wxSOUTH': 'wxBOTTOM', 'wxWEST': 'wxLEFT', 'wxEAST': 'wxRIGHT'}
113 def __init__(self
, parent
, name
):
114 ParamBinaryOr
.__init
__(self
, parent
, name
)
116 class ParamNonGenericStyle(ParamBinaryOr
):
117 def __init__(self
, parent
, name
):
118 self
.values
= g
.currentXXX
.winStyles
119 ParamBinaryOr
.__init
__(self
, parent
, name
)
121 class ParamStyle(ParamBinaryOr
):
122 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE'}
123 def __init__(self
, parent
, name
):
124 ParamBinaryOr
.__init
__(self
, parent
, name
)
125 self
.valuesSpecific
= g
.currentXXX
.winStyles
126 if self
.valuesSpecific
: # override if using specific styles
128 self
.valuesGeneric
= [s
for s
in genericStyles
129 if s
not in self
.valuesSpecific
]
130 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_CHOICES
, self
.OnButtonChoicesBoth
)
132 self
.values
= genericStyles
133 def OnButtonChoicesBoth(self
, evt
):
134 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_STYLES')
135 listBoxSpecific
= xrc
.XRCCTRL(dlg
, 'CHECKLIST_SPECIFIC')
136 listBoxSpecific
.InsertItems(self
.valuesSpecific
, 0)
137 listBoxGeneric
= xrc
.XRCCTRL(dlg
, 'CHECKLIST_GENERIC')
138 listBoxGeneric
.InsertItems(self
.valuesGeneric
, 0)
139 value
= map(string
.strip
, self
.text
.GetValue().split('|'))
140 if value
== ['']: value
= []
141 # Set specific styles
142 value2
= [] # collect generic and ignored here
145 listBoxSpecific
.Check(self
.valuesSpecific
.index(i
))
148 if self
.equal
.has_key(i
):
149 listBoxSpecific
.Check(self
.valuesSpecific
.index(self
.equal
[i
]))
153 # Set generic styles, collect non-standart values
156 listBoxGeneric
.Check(self
.valuesGeneric
.index(i
))
159 if self
.equal
.has_key(i
):
160 listBoxGeneric
.Check(self
.valuesGeneric
.index(self
.equal
[i
]))
162 print 'WARNING: unknown flag: %s: ignored.' % i
164 if dlg
.ShowModal() == wx
.ID_OK
:
165 value
= [self
.valuesSpecific
[i
]
166 for i
in range(listBoxSpecific
.GetCount())
167 if listBoxSpecific
.IsChecked(i
)] + \
168 [self
.valuesGeneric
[i
]
169 for i
in range(listBoxGeneric
.GetCount())
170 if listBoxGeneric
.IsChecked(i
)] + ignored
171 self
.SetValue('|'.join(value
))
175 class ParamExStyle(ParamBinaryOr
):
176 def __init__(self
, parent
, name
):
178 self
.values
= g
.currentXXX
.exStyles
+ genericExStyles
181 ParamBinaryOr
.__init
__(self
, parent
, name
)
183 class ParamColour(PPanel
):
184 def __init__(self
, parent
, name
):
185 PPanel
.__init
__(self
, parent
, name
)
186 self
.ID_TEXT_CTRL
= wx
.NewId()
187 self
.ID_BUTTON
= wx
.NewId()
188 sizer
= wx
.BoxSizer()
189 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(80,-1))
190 sizer
.Add(self
.text
, 0, wx
.ALIGN_CENTER_VERTICAL | wx
.TOP | wx
.BOTTOM
, 2)
191 self
.button
= wx
.Panel(self
, self
.ID_BUTTON
, wx
.DefaultPosition
, wx
.Size(20, 20))
192 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL | wx
.LEFT
, 5)
193 self
.SetAutoLayout(True)
194 self
.SetSizerAndFit(sizer
)
195 self
.textModified
= False
196 wx
.EVT_PAINT(self
.button
, self
.OnPaintButton
)
197 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
198 wx
.EVT_LEFT_DOWN(self
.button
, self
.OnLeftDown
)
200 return self
.text
.GetValue()
201 def SetValue(self
, value
):
203 if not value
: value
= '#FFFFFF'
204 self
.text
.SetValue(str(value
)) # update text ctrl
206 colour
= wx
.Colour(int(value
[1:3], 16), int(value
[3:5], 16), int(value
[5:7], 16))
207 self
.button
.SetBackgroundColour(colour
)
208 except: # ignore errors
210 self
.button
.Refresh()
212 def OnPaintButton(self
, evt
):
213 dc
= wx
.PaintDC(self
.button
)
214 dc
.SetBrush(wx
.TRANSPARENT_BRUSH
)
215 if self
.IsEnabled(): dc
.SetPen(wx
.BLACK_PEN
)
216 else: dc
.SetPen(wx
.GREY_PEN
)
217 size
= self
.button
.GetSize()
218 dc
.DrawRectangle(0, 0, size
.width
, size
.height
)
219 def OnLeftDown(self
, evt
):
220 data
= wx
.ColourData()
221 data
.SetColour(self
.GetValue())
222 dlg
= wx
.ColourDialog(self
, data
)
223 if dlg
.ShowModal() == wx
.ID_OK
:
224 self
.SetValue('#%02X%02X%02X' % dlg
.GetColourData().GetColour().Get())
228 ################################################################################
230 # Mapping from wx constants to XML strings
231 fontFamiliesWx2Xml
= {wx
.DEFAULT
: 'default', wx
.DECORATIVE
: 'decorative',
232 wx
.ROMAN
: 'roman', wx
.SCRIPT
: 'script', wx
.SWISS
: 'swiss',
234 fontStylesWx2Xml
= {wx.NORMAL: 'normal', wx.SLANT: 'slant', wx.ITALIC: 'italic'}
235 fontWeightsWx2Xml
= {wx.NORMAL: 'normal', wx.LIGHT: 'light', wx.BOLD: 'bold'}
238 for k
,v
in m
.items(): rm
[v
] = k
240 fontFamiliesXml2wx
= ReverseMap(fontFamiliesWx2Xml
)
241 fontStylesXml2wx
= ReverseMap(fontStylesWx2Xml
)
242 fontWeightsXml2wx
= ReverseMap(fontWeightsWx2Xml
)
244 class ParamFont(PPanel
):
245 def __init__(self
, parent
, name
):
246 PPanel
.__init
__(self
, parent
, name
)
247 self
.ID_TEXT_CTRL
= wx
.NewId()
248 self
.ID_BUTTON_SELECT
= wx
.NewId()
249 sizer
= wx
.BoxSizer()
250 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(200,-1))
251 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
252 self
.button
= wx
.Button(self
, self
.ID_BUTTON_SELECT
, 'Select...', size
=buttonSize
)
253 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
254 self
.SetAutoLayout(True)
255 self
.SetSizerAndFit(sizer
)
256 self
.textModified
= False
257 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_SELECT
, self
.OnButtonSelect
)
258 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
259 def OnChange(self
, evt
):
260 PPanel
.OnChange(self
, evt
)
261 self
.textModified
= True
262 def _defaultValue(self
):
263 return [`g
._sysFont
.GetPointSize()`
, 'default', 'normal', 'normal', '0', '', '']
265 if self
.textModified
: # text has newer value
267 return eval(self
.text
.GetValue())
269 wx
.LogError('Syntax error in parameter value: ' + self
.GetName())
270 return self
._defaultValue
()
272 def SetValue(self
, value
):
273 self
.freeze
= True # disable other handlers
274 if not value
: value
= self
._defaultValue
()
276 self
.text
.SetValue(str(value
)) # update text ctrl
278 def OnButtonSelect(self
, evt
):
279 if self
.textModified
: # text has newer value
281 self
.value
= eval(self
.text
.GetValue())
283 wx
.LogError('Syntax error in parameter value: ' + self
.GetName())
284 self
.value
= self
._defaultValue
()
287 size
= g
._sysFont
.GetPointSize()
289 style
= weight
= wx
.NORMAL
292 enc
= wx
.FONTENCODING_DEFAULT
293 # Fall back to default if exceptions
296 try: size
= int(self
.value
[0])
297 except ValueError: error
= True; wx
.LogError('Invalid size specification')
298 try: family
= fontFamiliesXml2wx
[self
.value
[1]]
299 except KeyError: error
= True; wx
.LogError('Invalid family specification')
300 try: style
= fontStylesXml2wx
[self
.value
[2]]
301 except KeyError: error
= True; wx
.LogError('Invalid style specification')
302 try: weight
= fontWeightsXml2wx
[self
.value
[3]]
303 except KeyError: error
= True; wx
.LogError('Invalid weight specification')
304 try: underlined
= bool(self
.value
[4])
305 except ValueError: error
= True; wx
.LogError('Invalid underlined flag specification')
309 mapper
= wx
.FontMapper()
310 if not self
.value
[6]: enc
= mapper
.CharsetToEncoding(self
.value
[6])
312 if error
: wx
.LogError('Invalid font specification')
313 if enc
== wx
.FONTENCODING_DEFAULT
: enc
= wx
.FONTENCODING_SYSTEM
314 font
= wx
.Font(size
, family
, style
, weight
, underlined
, face
, enc
)
316 data
.SetInitialFont(font
)
317 dlg
= wx
.FontDialog(self
, data
)
318 if dlg
.ShowModal() == wx
.ID_OK
:
319 font
= dlg
.GetFontData().GetChosenFont()
320 if font
.GetEncoding() == wx
.FONTENCODING_SYSTEM
:
323 encName
= wx
.FontMapper
.GetEncodingName(font
.GetEncoding()).encode()
324 value
= [str(font
.GetPointSize()),
325 fontFamiliesWx2Xml
.get(font
.GetFamily(), "default"),
326 fontStylesWx2Xml
.get(font
.GetStyle(), "normal"),
327 fontWeightsWx2Xml
.get(font
.GetWeight(), "normal"),
328 str(int(font
.GetUnderlined())),
329 font
.GetFaceName().encode(),
334 self
.textModified
= False
337 ################################################################################
339 class ParamInt(PPanel
):
340 def __init__(self
, parent
, name
):
341 PPanel
.__init
__(self
, parent
, name
)
342 self
.ID_SPIN_CTRL
= wx
.NewId()
343 sizer
= wx
.BoxSizer()
344 self
.spin
= wx
.SpinCtrl(self
, self
.ID_SPIN_CTRL
, size
=(60,-1))
345 self
.spin
.SetRange(-2147483648, 2147483647) # min/max integers
347 self
.SetAutoLayout(True)
348 self
.SetSizerAndFit(sizer
)
349 wx
.EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
351 return str(self
.spin
.GetValue())
352 def SetValue(self
, value
):
354 if not value
: value
= 0
355 self
.spin
.SetValue(int(value
))
358 # Non-negative number
359 class ParamIntNN(PPanel
):
360 def __init__(self
, parent
, name
):
361 PPanel
.__init
__(self
, parent
, name
)
362 self
.ID_SPIN_CTRL
= wx
.NewId()
363 sizer
= wx
.BoxSizer()
364 self
.spin
= wx
.SpinCtrl(self
, self
.ID_SPIN_CTRL
, size
=(60,-1))
365 self
.spin
.SetRange(0, 10000) # min/max integers
367 self
.SetAutoLayout(True)
368 self
.SetSizerAndFit(sizer
)
369 wx
.EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
371 return str(self
.spin
.GetValue())
372 def SetValue(self
, value
):
374 if not value
: value
= 0
375 self
.spin
.SetValue(int(value
))
378 # Same as int but allows dialog units (XXXd)
379 class ParamUnit(PPanel
):
380 def __init__(self
, parent
, name
):
381 PPanel
.__init
__(self
, parent
, name
)
382 self
.ID_TEXT_CTRL
= wx
.NewId()
383 self
.ID_SPIN_BUTTON
= wx
.NewId()
384 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
385 self
.spin
= wx
.SpinButton(self
, self
.ID_SPIN_BUTTON
, style
= wx
.SP_VERTICAL
, size
=(-1,0))
386 textW
= 60 - self
.spin
.GetSize()[0]
387 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(textW
,-1))
388 self
.spin
.SetRange(-10000, 10000)
389 sizer
.Add(self
.text
, 0, wx
.EXPAND
)
390 sizer
.Add(self
.spin
, 0, wx
.EXPAND
)
391 self
.SetAutoLayout(True)
392 self
.SetSizerAndFit(sizer
)
393 self
.spin
.Bind(wx
.EVT_SPIN_UP
, self
.OnSpinUp
)
394 self
.spin
.Bind(wx
.EVT_SPIN_DOWN
, self
.OnSpinDown
)
396 return self
.text
.GetValue()
397 def SetValue(self
, value
):
398 if not value
: value
= '0'
399 self
.text
.SetValue(value
)
403 # Check if we are working with dialog units
404 value
= self
.text
.GetValue()
406 if value
[-1].upper() == 'D':
410 intValue
= int(value
) + x
411 self
.spin
.SetValue(intValue
)
412 if x
: # 0 can be passed to update spin value only
413 self
.text
.SetValue(str(intValue
) + units
)
416 # !!! Strange, if I use wx.LogWarning, event is re-generated
417 print 'ERROR: incorrect unit format'
419 def OnSpinUp(self
, evt
):
422 def OnSpinDown(self
, evt
):
423 if self
.freeze
: return
427 class ParamMultilineText(PPanel
):
428 def __init__(self
, parent
, name
, textWidth
=-1):
429 PPanel
.__init
__(self
, parent
, name
)
430 self
.ID_TEXT_CTRL
= wx
.NewId()
431 self
.ID_BUTTON_EDIT
= wx
.NewId()
432 sizer
= wx
.BoxSizer()
433 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
434 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
435 self
.button
= wx
.Button(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
436 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
437 self
.SetAutoLayout(True)
438 self
.SetSizerAndFit(sizer
)
439 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
440 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
442 return self
.text
.GetValue()
443 def SetValue(self
, value
):
444 self
.freeze
= True # disable other handlers
445 self
.text
.SetValue(value
)
446 self
.freeze
= False # disable other handlers
447 def OnButtonEdit(self
, evt
):
448 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_TEXT')
449 textCtrl
= xrc
.XRCCTRL(dlg
, 'TEXT')
450 textCtrl
.SetValue(self
.text
.GetValue())
451 if dlg
.ShowModal() == wx
.ID_OK
:
452 self
.text
.SetValue(textCtrl
.GetValue())
456 class ParamText(PPanel
):
457 def __init__(self
, parent
, name
, textWidth
=-1):
458 PPanel
.__init
__(self
, parent
, name
)
459 self
.ID_TEXT_CTRL
= wx
.NewId()
460 # We use sizer even here to have the same size of text control
461 sizer
= wx
.BoxSizer()
462 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(textWidth
,-1))
463 if textWidth
== -1: option
= 1
465 sizer
.Add(self
.text
, option
, wx
.ALIGN_CENTER_VERTICAL | wx
.TOP | wx
.BOTTOM
, 2)
466 self
.SetAutoLayout(True)
467 self
.SetSizerAndFit(sizer
)
468 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
470 return self
.text
.GetValue()
471 def SetValue(self
, value
):
472 self
.freeze
= True # disable other handlers
473 self
.text
.SetValue(value
)
474 self
.freeze
= False # disable other handlers
476 class ParamAccel(ParamText
):
477 def __init__(self
, parent
, name
):
478 ParamText
.__init
__(self
, parent
, name
, 100)
480 class ParamPosSize(ParamText
):
481 def __init__(self
, parent
, name
):
482 ParamText
.__init
__(self
, parent
, name
, 80)
484 class ParamLabel(ParamText
):
485 def __init__(self
, parent
, name
):
486 ParamText
.__init
__(self
, parent
, name
, 200)
488 class ParamEncoding(ParamText
):
489 def __init__(self
, parent
, name
):
490 ParamText
.__init
__(self
, parent
, name
, 100)
492 class ContentDialog(wx
.Dialog
):
493 def __init__(self
, parent
, value
):
496 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT')
498 self
.list = xrc
.XRCCTRL(self
, 'LIST')
502 self
.SetAutoLayout(True)
503 self
.GetSizer().Fit(self
)
505 self
.ID_BUTTON_APPEND
= xrc
.XRCID('BUTTON_APPEND')
506 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
507 self
.ID_BUTTON_UP
= xrc
.XRCID('BUTTON_UP')
508 self
.ID_BUTTON_DOWN
= xrc
.XRCID('BUTTON_DOWN')
509 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
510 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
511 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
512 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
513 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
514 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
515 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
516 def OnButtonUp(self
, evt
):
517 i
= self
.list.GetSelection()
518 str = self
.list.GetString(i
)
520 self
.list.InsertItems([str], i
-1)
521 self
.list.SetSelection(i
-1)
522 def OnButtonDown(self
, evt
):
523 i
= self
.list.GetSelection()
524 str = self
.list.GetString(i
)
526 self
.list.InsertItems([str], i
+1)
527 self
.list.SetSelection(i
+1)
528 def OnButtonAppend(self
, evt
):
529 str = wx
.GetTextFromUser('Enter new item:', 'Append', '', self
)
530 self
.list.Append(str)
531 def OnButtonRemove(self
, evt
):
532 self
.list.Delete(self
.list.GetSelection())
533 def OnUpdateUI(self
, evt
):
534 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
535 evt
.Enable(self
.list.GetSelection() != -1)
536 elif evt
.GetId() == self
.ID_BUTTON_UP
:
537 evt
.Enable(self
.list.GetSelection() > 0)
538 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
539 evt
.Enable(self
.list.GetSelection() != -1 and \
540 self
.list.GetSelection() < self
.list.GetCount() - 1)
542 class ContentCheckListDialog(wx
.Dialog
):
543 def __init__(self
, parent
, value
):
545 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT_CHECKLIST')
547 self
.list = xrc
.XRCCTRL(self
, 'CHECK_LIST')
552 self
.list.Check(i
, ch
)
554 self
.SetAutoLayout(True)
555 self
.GetSizer().Fit(self
)
557 self
.ID_BUTTON_APPEND
= xrc
.XRCID('BUTTON_APPEND')
558 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
559 self
.ID_BUTTON_UP
= xrc
.XRCID('BUTTON_UP')
560 self
.ID_BUTTON_DOWN
= xrc
.XRCID('BUTTON_DOWN')
561 wx
.EVT_CHECKLISTBOX(self
, self
.list.GetId(), self
.OnCheck
)
562 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
563 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
564 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
565 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
566 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
567 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
568 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
569 def OnCheck(self
, evt
):
570 # !!! Wrong wxGTK (wxMSW?) behavior: toggling selection if checking
571 self
.list.Deselect(evt
.GetSelection())
572 def OnButtonUp(self
, evt
):
573 i
= self
.list.GetSelection()
574 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
576 self
.list.InsertItems([str], i
-1)
577 self
.list.Check(i
-1, ch
)
578 self
.list.SetSelection(i
-1)
579 def OnButtonDown(self
, evt
):
580 i
= self
.list.GetSelection()
581 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
583 self
.list.InsertItems([str], i
+1)
584 self
.list.Check(i
+1, ch
)
585 self
.list.SetSelection(i
+1)
586 def OnButtonAppend(self
, evt
):
587 str = wx
.GetTextFromUser('Enter new item:', 'Append', '', self
)
588 self
.list.Append(str)
589 def OnButtonRemove(self
, evt
):
590 self
.list.Delete(self
.list.GetSelection())
591 def OnUpdateUI(self
, evt
):
592 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
593 evt
.Enable(self
.list.GetSelection() != -1)
594 elif evt
.GetId() == self
.ID_BUTTON_UP
:
595 evt
.Enable(self
.list.GetSelection() > 0)
596 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
597 evt
.Enable(self
.list.GetSelection() != -1 and \
598 self
.list.GetSelection() < self
.list.GetCount() - 1)
600 class ParamContent(PPanel
):
601 def __init__(self
, parent
, name
):
602 PPanel
.__init
__(self
, parent
, name
)
603 self
.ID_TEXT_CTRL
= wx
.NewId()
604 self
.ID_BUTTON_EDIT
= wx
.NewId()
605 sizer
= wx
.BoxSizer()
606 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
607 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
608 self
.button
= wx
.Button(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
609 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
610 self
.SetAutoLayout(True)
611 self
.SetSizerAndFit(sizer
)
612 self
.textModified
= False
613 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
614 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
615 def OnChange(self
, evt
):
616 PPanel
.OnChange(self
, evt
)
617 self
.textModified
= True
619 if self
.textModified
: # text has newer value
621 return self
.text
.GetValue().split('|')
625 def SetValue(self
, value
):
627 if not value
: value
= []
629 repr_
= '|'.join(map(str, value
))
630 self
.text
.SetValue(repr_
) # update text ctrl
632 def OnButtonEdit(self
, evt
):
633 if self
.textModified
: # text has newer value
634 self
.value
= self
.GetValue()
635 dlg
= ContentDialog(self
, self
.value
)
636 if dlg
.ShowModal() == wx
.ID_OK
:
638 for i
in range(dlg
.list.GetCount()):
639 value
.append(dlg
.list.GetString(i
))
642 self
.textModified
= False
644 def SetModified(self
, state
=True):
645 PPanel
.SetModified(self
, state
)
646 self
.textModified
= False
649 class ParamContentCheckList(ParamContent
):
650 def __init__(self
, parent
, name
):
651 ParamContent
.__init
__(self
, parent
, name
)
652 def OnButtonEdit(self
, evt
):
653 if self
.textModified
: # text has newer value
654 self
.value
= self
.GetValue()
655 dlg
= ContentCheckListDialog(self
, self
.value
)
656 if dlg
.ShowModal() == wx
.ID_OK
:
658 for i
in range(dlg
.list.GetCount()):
659 value
.append((dlg
.list.GetString(i
), int(dlg
.list.IsChecked(i
))))
662 self
.textModified
= False
664 def SetValue(self
, value
):
666 if not value
: value
= []
668 repr_
= '|'.join(map(str,value
))
669 self
.text
.SetValue(repr_
) # update text ctrl
672 class IntListDialog(wx
.Dialog
):
673 def __init__(self
, parent
, value
):
675 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_INTLIST')
677 self
.list = xrc
.XRCCTRL(self
, 'LIST')
681 if type(v
) != IntType
:
682 wx
.LogError('Invalid item type')
684 self
.list.Append(str(v
))
685 self
.SetAutoLayout(True)
686 self
.GetSizer().Fit(self
)
688 self
.spinCtrl
= xrc
.XRCCTRL(self
, 'SPIN')
689 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_ADD'), self
.OnButtonAdd
)
690 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
691 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
692 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_CLEAR'), self
.OnButtonClear
)
693 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
694 def OnButtonAdd(self
, evt
):
695 # Check that it's unique
697 v
= self
.spinCtrl
.GetValue()
698 s
= str(v
) # to be sure
699 i
= self
.list.FindString(s
)
700 if i
== -1: # ignore non-unique
701 # Find place to insert
703 for i
in range(self
.list.GetCount()):
704 if int(self
.list.GetString(i
)) > v
:
707 if found
: self
.list.InsertItems([s
], i
)
708 else: self
.list.Append(s
)
710 wx
.LogError('List item is not an int!')
711 def OnButtonRemove(self
, evt
):
712 self
.list.Delete(self
.list.GetSelection())
713 def OnButtonClear(self
, evt
):
715 def OnUpdateUI(self
, evt
):
716 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
717 evt
.Enable(self
.list.GetSelection() != -1)
720 class ParamIntList(ParamContent
):
721 def __init__(self
, parent
, name
):
722 ParamContent
.__init
__(self
, parent
, name
)
723 def OnButtonEdit(self
, evt
):
724 if self
.textModified
: # text has newer value
726 self
.value
= map(int, self
.text
.GetValue().split('|'))
729 dlg
= IntListDialog(self
, self
.value
)
730 if dlg
.ShowModal() == wx
.ID_OK
:
732 for i
in range(dlg
.list.GetCount()):
733 value
.append(int(dlg
.list.GetString(i
)))
736 self
.textModified
= False
740 class RadioBox(PPanel
):
741 def __init__(self
, parent
, id, choices
,
742 pos
=wx
.DefaultPosition
, name
='radiobox'):
743 PPanel
.__init
__(self
, parent
, name
)
744 self
.choices
= choices
745 topSizer
= wx
.BoxSizer()
747 button
= wx
.RadioButton(self
, -1, i
, size
=(-1,buttonSize
[1]), name
=i
)
748 topSizer
.Add(button
, 0, wx
.RIGHT
, 5)
749 wx
.EVT_RADIOBUTTON(self
, button
.GetId(), self
.OnRadioChoice
)
750 self
.SetAutoLayout(True)
751 self
.SetSizerAndFit(topSizer
)
752 def SetStringSelection(self
, value
):
754 for i
in self
.choices
:
755 self
.FindWindowByName(i
).SetValue(i
== value
)
758 def OnRadioChoice(self
, evt
):
759 if self
.freeze
: return
760 if evt
.GetSelection():
761 self
.value
= evt
.GetEventObject().GetName()
763 def GetStringSelection(self
):
766 class ParamBool(RadioBox
):
767 values
= {'yes': '1', 'no': '0'}
768 seulav
= {'1': 'yes', '0': 'no'}
769 def __init__(self
, parent
, name
):
770 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
772 return self
.values
[self
.GetStringSelection()]
773 def SetValue(self
, value
):
774 if not value
: value
= '1'
775 self
.SetStringSelection(self
.seulav
[value
])
777 class ParamOrient(RadioBox
):
778 values
= {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'}
779 seulav
= {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'}
780 def __init__(self
, parent
, name
):
781 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
783 return self
.values
[self
.GetStringSelection()]
784 def SetValue(self
, value
):
785 if not value
: value
= 'wxHORIZONTAL'
786 self
.SetStringSelection(self
.seulav
[value
])
788 class ParamOrientation(RadioBox
):
789 values
= {'horizontal': 'horizontal', 'vertical': 'vertical'}
790 seulav
= {'horizontal': 'horizontal', 'vertical': 'vertical'}
791 def __init__(self
, parent
, name
):
792 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
794 return self
.values
[self
.GetStringSelection()]
795 def SetValue(self
, value
):
796 if not value
: value
= 'vertical'
797 self
.SetStringSelection(self
.seulav
[value
])
799 class ParamFile(PPanel
):
800 def __init__(self
, parent
, name
):
801 PPanel
.__init
__(self
, parent
, name
)
802 self
.ID_TEXT_CTRL
= wx
.NewId()
803 self
.ID_BUTTON_BROWSE
= wx
.NewId()
804 sizer
= wx
.BoxSizer()
805 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
806 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
807 self
.button
= wx
.Button(self
, self
.ID_BUTTON_BROWSE
, 'Browse...',size
=buttonSize
)
808 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
809 self
.SetAutoLayout(True)
810 self
.SetSizerAndFit(sizer
)
811 self
.textModified
= False
812 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_BROWSE
, self
.OnButtonBrowse
)
813 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
814 def OnChange(self
, evt
):
815 PPanel
.OnChange(self
, evt
)
816 self
.textModified
= True
818 if self
.textModified
: # text has newer value
819 return self
.text
.GetValue()
821 def SetValue(self
, value
):
824 self
.text
.SetValue(value
) # update text ctrl
826 def OnButtonBrowse(self
, evt
):
827 if self
.textModified
: # text has newer value
828 self
.value
= self
.text
.GetValue()
829 dlg
= wx
.FileDialog(self
,
830 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
)),
831 defaultFile
= os
.path
.basename(self
.value
))
832 if dlg
.ShowModal() == wx
.ID_OK
:
833 # Get common part of selected path and current
835 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
837 curpath
= os
.path
.join(os
.getcwd(), '')
838 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
839 self
.SetValue(dlg
.GetPath()[len(common
):])
841 self
.textModified
= False
844 class ParamBitmap(PPanel
):
845 def __init__(self
, parent
, name
):
847 g
.frame
.res
.LoadOnPanel(pre
, parent
, 'PANEL_BITMAP')
849 self
.modified
= self
.freeze
= False
850 self
.radio_std
= xrc
.XRCCTRL(self
, 'RADIO_STD')
851 self
.radio_file
= xrc
.XRCCTRL(self
, 'RADIO_FILE')
852 self
.combo
= xrc
.XRCCTRL(self
, 'COMBO_STD')
853 self
.text
= xrc
.XRCCTRL(self
, 'TEXT_FILE')
854 self
.button
= xrc
.XRCCTRL(self
, 'BUTTON_BROWSE')
855 self
.textModified
= False
856 self
.SetAutoLayout(True)
857 self
.GetSizer().SetMinSize((260, -1))
858 self
.GetSizer().Fit(self
)
859 wx
.EVT_RADIOBUTTON(self
, xrc
.XRCID('RADIO_STD'), self
.OnRadioStd
)
860 wx
.EVT_RADIOBUTTON(self
, xrc
.XRCID('RADIO_FILE'), self
.OnRadioFile
)
861 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_BROWSE'), self
.OnButtonBrowse
)
862 wx
.EVT_COMBOBOX(self
, xrc
.XRCID('COMBO_STD'), self
.OnCombo
)
863 wx
.EVT_TEXT(self
, xrc
.XRCID('COMBO_STD'), self
.OnChange
)
864 wx
.EVT_TEXT(self
, xrc
.XRCID('TEXT_FILE'), self
.OnChange
)
865 def OnRadioStd(self
, evt
):
867 self
.SetValue(['wxART_MISSING_IMAGE',''])
868 def OnRadioFile(self
, evt
):
870 self
.SetValue(['',''])
871 def updateRadios(self
):
873 self
.radio_std
.SetValue(True)
874 self
.radio_file
.SetValue(False)
875 self
.text
.Enable(False)
876 self
.button
.Enable(False)
877 self
.combo
.Enable(True)
879 self
.radio_std
.SetValue(False)
880 self
.radio_file
.SetValue(True)
881 self
.text
.Enable(True)
882 self
.button
.Enable(True)
883 self
.combo
.Enable(False)
884 def OnChange(self
, evt
):
885 PPanel
.OnChange(self
, evt
)
886 self
.textModified
= True
887 def OnCombo(self
, evt
):
888 PPanel
.OnChange(self
, evt
)
889 self
.value
[0] = self
.combo
.GetValue()
891 if self
.textModified
: # text has newer value
892 return [self
.combo
.GetValue(), self
.text
.GetValue()]
894 def SetValue(self
, value
):
897 self
.value
= ['', '']
900 self
.combo
.SetValue(self
.value
[0])
901 self
.text
.SetValue(self
.value
[1]) # update text ctrl
904 def OnButtonBrowse(self
, evt
):
905 if self
.textModified
: # text has newer value
906 self
.value
[1] = self
.text
.GetValue()
907 dlg
= wx
.FileDialog(self
,
908 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
[1])),
909 defaultFile
= os
.path
.basename(self
.value
[1]))
910 if dlg
.ShowModal() == wx
.ID_OK
:
911 # Get common part of selected path and current
913 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
915 curpath
= os
.path
.join(os
.getcwd(), '')
916 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
917 self
.SetValue(['', dlg
.GetPath()[len(common
):]])
919 self
.textModified
= False
924 'style': ParamStyle
, 'exstyle': ParamExStyle
,
925 'pos': ParamPosSize
, 'size': ParamPosSize
,
926 'cellpos': ParamPosSize
, 'cellspan': ParamPosSize
,
927 'border': ParamUnit
, 'cols': ParamIntNN
, 'rows': ParamIntNN
,
928 'vgap': ParamUnit
, 'hgap': ParamUnit
,
929 'checkable': ParamBool
, 'checked': ParamBool
, 'radio': ParamBool
,
931 'label': ParamMultilineText
, 'title': ParamText
, 'value': ParamText
,
932 'content': ParamContent
, 'selection': ParamIntNN
,
933 'min': ParamInt
, 'max': ParamInt
,
934 'fg': ParamColour
, 'bg': ParamColour
, 'font': ParamFont
,
935 'enabled': ParamBool
, 'focused': ParamBool
, 'hidden': ParamBool
,
936 'tooltip': ParamText
, 'bitmap': ParamBitmap
, 'icon': ParamBitmap
,
937 'encoding': ParamEncoding
, 'borders': ParamUnit