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 # Global var initialized in Panel.__init__ for button size in screen pixels
30 # Button size in dialog units
33 # Class that can properly disable children
34 class PPanel(wx
.Panel
):
35 def __init__(self
, parent
, name
):
36 wx
.Panel
.__init
__(self
, parent
, -1, name
=name
)
37 self
.modified
= self
.freeze
= False
38 def Enable(self
, value
):
39 # Something strange is going on with enable so we make sure...
40 for w
in self
.GetChildren():
42 #wx.Panel.Enable(self, value)
43 def SetModified(self
, state
=True):
45 if state
: g
.panel
.SetModified(True)
46 # Common method to set modified state
47 def OnChange(self
, evt
):
48 if self
.freeze
: return
52 class ParamBinaryOr(PPanel
):
53 def __init__(self
, parent
, name
):
54 PPanel
.__init
__(self
, parent
, name
)
55 self
.ID_TEXT_CTRL
= wx
.NewId()
56 self
.ID_BUTTON_CHOICES
= wx
.NewId()
58 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
59 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
60 self
.button
= wx
.Button(self
, self
.ID_BUTTON_CHOICES
, 'Edit...', size
=buttonSize
)
61 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
63 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_CHOICES
, self
.OnButtonChoices
)
64 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
66 return self
.text
.GetValue()
67 def SetValue(self
, value
):
69 self
.text
.SetValue(value
)
71 def OnButtonChoices(self
, evt
):
72 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_CHOICES')
73 if self
.GetName() == 'flag': dlg
.SetTitle('Sizer item flags')
74 elif self
.GetName() == 'style': dlg
.SetTitle('Window styles')
75 elif self
.GetName() == 'exstyle': dlg
.SetTitle('Extended window styles')
76 listBox
= xrc
.XRCCTRL(dlg
, 'CHECKLIST')
77 listBox
.InsertItems(self
.values
, 0)
78 value
= map(string
.strip
, self
.text
.GetValue().split('|'))
79 if value
== ['']: value
= []
83 listBox
.Check(self
.values
.index(i
))
86 if self
.equal
.has_key(i
):
87 listBox
.Check(self
.values
.index(self
.equal
[i
]))
89 print 'WARNING: unknown flag: %s: ignored.' % i
91 if dlg
.ShowModal() == wx
.ID_OK
:
93 for i
in range(listBox
.GetCount()):
94 if listBox
.IsChecked(i
):
95 value
.append(self
.values
[i
])
98 self
.SetValue('|'.join(value
))
102 class ParamFlag(ParamBinaryOr
):
103 values
= ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL',
104 'wxEXPAND', 'wxGROW', 'wxSHAPED', 'wxSTRETCH_NOT',
105 'wxALIGN_CENTRE', 'wxALIGN_LEFT', 'wxALIGN_RIGHT',
106 'wxALIGN_TOP', 'wxALIGN_BOTTOM',
107 'wxALIGN_CENTRE_VERTICAL', 'wxALIGN_CENTRE_HORIZONTAL',
108 'wxADJUST_MINSIZE', 'wxFIXED_MINSIZE'
110 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE',
111 'wxALIGN_CENTER_VERTICAL': 'wxALIGN_CENTRE_VERTICAL',
112 'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL',
113 'wxUP': 'wxTOP', 'wxDOWN': 'wxBOTTOM', 'wxNORTH': 'wxTOP',
114 'wxSOUTH': 'wxBOTTOM', 'wxWEST': 'wxLEFT', 'wxEAST': 'wxRIGHT'}
115 def __init__(self
, parent
, name
):
116 ParamBinaryOr
.__init
__(self
, parent
, name
)
118 class ParamNonGenericStyle(ParamBinaryOr
):
119 def __init__(self
, parent
, name
):
120 self
.values
= g
.currentXXX
.winStyles
121 ParamBinaryOr
.__init
__(self
, parent
, name
)
123 class ParamStyle(ParamBinaryOr
):
124 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE'}
125 def __init__(self
, parent
, name
):
126 ParamBinaryOr
.__init
__(self
, parent
, name
)
127 self
.valuesSpecific
= g
.currentXXX
.winStyles
128 if self
.valuesSpecific
: # override if using specific styles
130 self
.valuesGeneric
= [s
for s
in genericStyles
131 if s
not in self
.valuesSpecific
]
132 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_CHOICES
, self
.OnButtonChoicesBoth
)
134 self
.values
= genericStyles
135 def OnButtonChoicesBoth(self
, evt
):
136 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_STYLES')
137 listBoxSpecific
= xrc
.XRCCTRL(dlg
, 'CHECKLIST_SPECIFIC')
138 listBoxSpecific
.InsertItems(self
.valuesSpecific
, 0)
139 listBoxGeneric
= xrc
.XRCCTRL(dlg
, 'CHECKLIST_GENERIC')
140 listBoxGeneric
.InsertItems(self
.valuesGeneric
, 0)
141 value
= map(string
.strip
, self
.text
.GetValue().split('|'))
142 if value
== ['']: value
= []
143 # Set specific styles
144 value2
= [] # collect generic and ignored here
147 listBoxSpecific
.Check(self
.valuesSpecific
.index(i
))
150 if self
.equal
.has_key(i
):
151 listBoxSpecific
.Check(self
.valuesSpecific
.index(self
.equal
[i
]))
155 # Set generic styles, collect non-standart values
158 listBoxGeneric
.Check(self
.valuesGeneric
.index(i
))
161 if self
.equal
.has_key(i
):
162 listBoxGeneric
.Check(self
.valuesGeneric
.index(self
.equal
[i
]))
164 print 'WARNING: unknown flag: %s: ignored.' % i
166 if dlg
.ShowModal() == wx
.ID_OK
:
167 value
= [self
.valuesSpecific
[i
]
168 for i
in range(listBoxSpecific
.GetCount())
169 if listBoxSpecific
.IsChecked(i
)] + \
170 [self
.valuesGeneric
[i
]
171 for i
in range(listBoxGeneric
.GetCount())
172 if listBoxGeneric
.IsChecked(i
)] + ignored
173 self
.SetValue('|'.join(value
))
177 class ParamExStyle(ParamBinaryOr
):
178 def __init__(self
, parent
, name
):
180 self
.values
= g
.currentXXX
.exStyles
+ genericExStyles
183 ParamBinaryOr
.__init
__(self
, parent
, name
)
185 class ParamColour(PPanel
):
186 def __init__(self
, parent
, name
):
187 PPanel
.__init
__(self
, parent
, name
)
188 self
.ID_TEXT_CTRL
= wx
.NewId()
189 self
.ID_BUTTON
= wx
.NewId()
190 sizer
= wx
.BoxSizer()
191 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(80,-1))
192 sizer
.Add(self
.text
, 0, wx
.ALIGN_CENTER_VERTICAL | wx
.TOP | wx
.BOTTOM
, 2)
193 self
.button
= wx
.Panel(self
, self
.ID_BUTTON
, wx
.DefaultPosition
, wx
.Size(20, 20))
194 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL | wx
.LEFT
, 5)
196 self
.textModified
= False
197 wx
.EVT_PAINT(self
.button
, self
.OnPaintButton
)
198 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
199 wx
.EVT_LEFT_DOWN(self
.button
, self
.OnLeftDown
)
201 return self
.text
.GetValue()
202 def SetValue(self
, value
):
204 if not value
: value
= '#FFFFFF'
205 self
.text
.SetValue(str(value
)) # update text ctrl
207 colour
= wx
.Colour(int(value
[1:3], 16), int(value
[3:5], 16), int(value
[5:7], 16))
208 self
.button
.SetBackgroundColour(colour
)
209 except: # ignore errors
211 self
.button
.Refresh()
213 def OnPaintButton(self
, evt
):
214 dc
= wx
.PaintDC(self
.button
)
215 dc
.SetBrush(wx
.TRANSPARENT_BRUSH
)
216 if self
.IsEnabled(): dc
.SetPen(wx
.BLACK_PEN
)
217 else: dc
.SetPen(wx
.GREY_PEN
)
218 size
= self
.button
.GetSize()
219 dc
.DrawRectangle(0, 0, size
.width
, size
.height
)
220 def OnLeftDown(self
, evt
):
221 data
= wx
.ColourData()
222 data
.SetColour(self
.GetValue())
223 dlg
= wx
.ColourDialog(self
, data
)
224 if dlg
.ShowModal() == wx
.ID_OK
:
225 self
.SetValue('#%02X%02X%02X' % dlg
.GetColourData().GetColour().Get())
229 ################################################################################
231 # Mapping from wx constants to XML strings
232 fontFamiliesWx2Xml
= {wx
.DEFAULT
: 'default', wx
.DECORATIVE
: 'decorative',
233 wx
.ROMAN
: 'roman', wx
.SCRIPT
: 'script', wx
.SWISS
: 'swiss',
235 fontStylesWx2Xml
= {wx.NORMAL: 'normal', wx.SLANT: 'slant', wx.ITALIC: 'italic'}
236 fontWeightsWx2Xml
= {wx.NORMAL: 'normal', wx.LIGHT: 'light', wx.BOLD: 'bold'}
239 for k
,v
in m
.items(): rm
[v
] = k
241 fontFamiliesXml2wx
= ReverseMap(fontFamiliesWx2Xml
)
242 fontStylesXml2wx
= ReverseMap(fontStylesWx2Xml
)
243 fontWeightsXml2wx
= ReverseMap(fontWeightsWx2Xml
)
245 class ParamFont(PPanel
):
246 def __init__(self
, parent
, name
):
247 PPanel
.__init
__(self
, parent
, name
)
248 self
.ID_TEXT_CTRL
= wx
.NewId()
249 self
.ID_BUTTON_SELECT
= wx
.NewId()
250 sizer
= wx
.BoxSizer()
251 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(200,-1))
252 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
253 self
.button
= wx
.Button(self
, self
.ID_BUTTON_SELECT
, 'Select...', size
=buttonSize
)
254 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
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
348 wx
.EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
350 return str(self
.spin
.GetValue())
351 def SetValue(self
, value
):
353 if not value
: value
= 0
354 self
.spin
.SetValue(int(value
))
357 # Non-negative number
358 class ParamIntNN(PPanel
):
359 def __init__(self
, parent
, name
):
360 PPanel
.__init
__(self
, parent
, name
)
361 self
.ID_SPIN_CTRL
= wx
.NewId()
362 sizer
= wx
.BoxSizer()
363 self
.spin
= wx
.SpinCtrl(self
, self
.ID_SPIN_CTRL
, size
=(60,-1))
364 self
.spin
.SetRange(0, 10000) # min/max integers
367 wx
.EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
369 return str(self
.spin
.GetValue())
370 def SetValue(self
, value
):
372 if not value
: value
= 0
373 self
.spin
.SetValue(int(value
))
376 # Same as int but allows dialog units (XXXd)
377 class ParamUnit(PPanel
):
378 def __init__(self
, parent
, name
):
379 PPanel
.__init
__(self
, parent
, name
)
380 self
.ID_TEXT_CTRL
= wx
.NewId()
381 self
.ID_SPIN_BUTTON
= wx
.NewId()
382 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
383 self
.spin
= wx
.SpinButton(self
, self
.ID_SPIN_BUTTON
, style
= wx
.SP_VERTICAL
, size
=(-1,0))
384 textW
= 60 - self
.spin
.GetSize()[0]
385 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(textW
,-1))
386 self
.spin
.SetRange(-10000, 10000)
387 sizer
.Add(self
.text
, 0, wx
.EXPAND
)
388 sizer
.Add(self
.spin
, 0, wx
.EXPAND
)
390 self
.spin
.Bind(wx
.EVT_SPIN_UP
, self
.OnSpinUp
)
391 self
.spin
.Bind(wx
.EVT_SPIN_DOWN
, self
.OnSpinDown
)
393 return self
.text
.GetValue()
394 def SetValue(self
, value
):
395 if not value
: value
= '0'
396 self
.text
.SetValue(value
)
400 # Check if we are working with dialog units
401 value
= self
.text
.GetValue()
403 if value
[-1].upper() == 'D':
407 intValue
= int(value
) + x
408 self
.spin
.SetValue(intValue
)
409 if x
: # 0 can be passed to update spin value only
410 self
.text
.SetValue(str(intValue
) + units
)
413 # !!! Strange, if I use wx.LogWarning, event is re-generated
414 print 'ERROR: incorrect unit format'
416 def OnSpinUp(self
, evt
):
419 def OnSpinDown(self
, evt
):
420 if self
.freeze
: return
424 class ParamMultilineText(PPanel
):
425 def __init__(self
, parent
, name
, textWidth
=-1):
426 PPanel
.__init
__(self
, parent
, name
)
427 self
.ID_TEXT_CTRL
= wx
.NewId()
428 self
.ID_BUTTON_EDIT
= wx
.NewId()
429 sizer
= wx
.BoxSizer()
430 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
431 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
432 self
.button
= wx
.Button(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
433 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
434 self
.SetSizerAndFit(sizer
)
435 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
436 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
438 return self
.text
.GetValue()
439 def SetValue(self
, value
):
440 self
.freeze
= True # disable other handlers
441 self
.text
.SetValue(value
)
442 self
.freeze
= False # disable other handlers
443 def OnButtonEdit(self
, evt
):
444 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_TEXT')
445 textCtrl
= xrc
.XRCCTRL(dlg
, 'TEXT')
446 textCtrl
.SetValue(self
.text
.GetValue())
447 if dlg
.ShowModal() == wx
.ID_OK
:
448 self
.text
.SetValue(textCtrl
.GetValue())
452 class ParamText(PPanel
):
453 def __init__(self
, parent
, name
, textWidth
=-1):
454 PPanel
.__init
__(self
, parent
, name
)
455 self
.ID_TEXT_CTRL
= wx
.NewId()
456 # We use sizer even here to have the same size of text control
457 sizer
= wx
.BoxSizer()
458 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(textWidth
,-1))
459 if textWidth
== -1: option
= 1
461 sizer
.Add(self
.text
, option
, wx
.ALIGN_CENTER_VERTICAL | wx
.TOP | wx
.BOTTOM
, 2)
463 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
465 return self
.text
.GetValue()
466 def SetValue(self
, value
):
467 self
.freeze
= True # disable other handlers
468 self
.text
.SetValue(value
)
469 self
.freeze
= False # disable other handlers
471 class ParamAccel(ParamText
):
472 def __init__(self
, parent
, name
):
473 ParamText
.__init
__(self
, parent
, name
, 100)
475 class ParamPosSize(ParamText
):
476 def __init__(self
, parent
, name
):
477 ParamText
.__init
__(self
, parent
, name
, 80)
479 class ParamLabel(ParamText
):
480 def __init__(self
, parent
, name
):
481 ParamText
.__init
__(self
, parent
, name
, 200)
483 class ParamEncoding(ParamText
):
484 def __init__(self
, parent
, name
):
485 ParamText
.__init
__(self
, parent
, name
, 100)
487 class ParamComment(ParamText
):
488 def __init__(self
, parent
, name
):
489 ParamText
.__init
__(self
, parent
, name
, 330 + buttonSize
[0])
491 class ContentDialog(wx
.Dialog
):
492 def __init__(self
, parent
, value
):
495 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT')
497 self
.list = xrc
.XRCCTRL(self
, 'LIST')
501 self
.SetAutoLayout(True)
502 self
.GetSizer().Fit(self
)
504 self
.ID_BUTTON_APPEND
= xrc
.XRCID('BUTTON_APPEND')
505 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
506 self
.ID_BUTTON_UP
= xrc
.XRCID('BUTTON_UP')
507 self
.ID_BUTTON_DOWN
= xrc
.XRCID('BUTTON_DOWN')
508 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
509 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
510 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
511 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
512 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
513 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
514 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
515 def OnButtonUp(self
, evt
):
516 i
= self
.list.GetSelection()
517 str = self
.list.GetString(i
)
519 self
.list.InsertItems([str], i
-1)
520 self
.list.SetSelection(i
-1)
521 def OnButtonDown(self
, evt
):
522 i
= self
.list.GetSelection()
523 str = self
.list.GetString(i
)
525 self
.list.InsertItems([str], i
+1)
526 self
.list.SetSelection(i
+1)
527 def OnButtonAppend(self
, evt
):
528 str = wx
.GetTextFromUser('Enter new item:', 'Append', '', self
)
529 self
.list.Append(str)
530 def OnButtonRemove(self
, evt
):
531 self
.list.Delete(self
.list.GetSelection())
532 def OnUpdateUI(self
, evt
):
533 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
534 evt
.Enable(self
.list.GetSelection() != -1)
535 elif evt
.GetId() == self
.ID_BUTTON_UP
:
536 evt
.Enable(self
.list.GetSelection() > 0)
537 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
538 evt
.Enable(self
.list.GetSelection() != -1 and \
539 self
.list.GetSelection() < self
.list.GetCount() - 1)
541 class ContentCheckListDialog(wx
.Dialog
):
542 def __init__(self
, parent
, value
):
544 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT_CHECKLIST')
546 self
.list = xrc
.XRCCTRL(self
, 'CHECK_LIST')
551 self
.list.Check(i
, ch
)
553 self
.SetAutoLayout(True)
554 self
.GetSizer().Fit(self
)
556 self
.ID_BUTTON_APPEND
= xrc
.XRCID('BUTTON_APPEND')
557 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
558 self
.ID_BUTTON_UP
= xrc
.XRCID('BUTTON_UP')
559 self
.ID_BUTTON_DOWN
= xrc
.XRCID('BUTTON_DOWN')
560 wx
.EVT_CHECKLISTBOX(self
, self
.list.GetId(), self
.OnCheck
)
561 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
562 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
563 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
564 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
565 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
566 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
567 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
568 def OnCheck(self
, evt
):
569 # !!! Wrong wxGTK (wxMSW?) behavior: toggling selection if checking
570 self
.list.Deselect(evt
.GetSelection())
571 def OnButtonUp(self
, evt
):
572 i
= self
.list.GetSelection()
573 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
575 self
.list.InsertItems([str], i
-1)
576 self
.list.Check(i
-1, ch
)
577 self
.list.SetSelection(i
-1)
578 def OnButtonDown(self
, evt
):
579 i
= self
.list.GetSelection()
580 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
582 self
.list.InsertItems([str], i
+1)
583 self
.list.Check(i
+1, ch
)
584 self
.list.SetSelection(i
+1)
585 def OnButtonAppend(self
, evt
):
586 str = wx
.GetTextFromUser('Enter new item:', 'Append', '', self
)
587 self
.list.Append(str)
588 def OnButtonRemove(self
, evt
):
589 self
.list.Delete(self
.list.GetSelection())
590 def OnUpdateUI(self
, evt
):
591 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
592 evt
.Enable(self
.list.GetSelection() != -1)
593 elif evt
.GetId() == self
.ID_BUTTON_UP
:
594 evt
.Enable(self
.list.GetSelection() > 0)
595 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
596 evt
.Enable(self
.list.GetSelection() != -1 and \
597 self
.list.GetSelection() < self
.list.GetCount() - 1)
599 class ParamContent(PPanel
):
600 def __init__(self
, parent
, name
):
601 PPanel
.__init
__(self
, parent
, name
)
602 self
.ID_TEXT_CTRL
= wx
.NewId()
603 self
.ID_BUTTON_EDIT
= wx
.NewId()
604 sizer
= wx
.BoxSizer()
605 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
606 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
607 self
.button
= wx
.Button(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
608 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
610 self
.textModified
= False
611 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
612 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
613 def OnChange(self
, evt
):
614 PPanel
.OnChange(self
, evt
)
615 self
.textModified
= True
617 if self
.textModified
: # text has newer value
619 return self
.text
.GetValue().split('|')
623 def SetValue(self
, value
):
625 if not value
: value
= []
627 repr_
= '|'.join(map(str, value
))
628 self
.text
.SetValue(repr_
) # update text ctrl
630 def OnButtonEdit(self
, evt
):
631 if self
.textModified
: # text has newer value
632 self
.value
= self
.GetValue()
633 dlg
= ContentDialog(self
, self
.value
)
634 if dlg
.ShowModal() == wx
.ID_OK
:
636 for i
in range(dlg
.list.GetCount()):
637 value
.append(dlg
.list.GetString(i
))
640 self
.textModified
= False
642 def SetModified(self
, state
=True):
643 PPanel
.SetModified(self
, state
)
644 self
.textModified
= False
647 class ParamContentCheckList(ParamContent
):
648 def __init__(self
, parent
, name
):
649 ParamContent
.__init
__(self
, parent
, name
)
650 def OnButtonEdit(self
, evt
):
651 if self
.textModified
: # text has newer value
652 self
.value
= self
.GetValue()
653 dlg
= ContentCheckListDialog(self
, self
.value
)
654 if dlg
.ShowModal() == wx
.ID_OK
:
656 for i
in range(dlg
.list.GetCount()):
657 value
.append((dlg
.list.GetString(i
), int(dlg
.list.IsChecked(i
))))
660 self
.textModified
= False
662 def SetValue(self
, value
):
664 if not value
: value
= []
666 repr_
= '|'.join(map(str,value
))
667 self
.text
.SetValue(repr_
) # update text ctrl
670 class IntListDialog(wx
.Dialog
):
671 def __init__(self
, parent
, value
):
673 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_INTLIST')
675 self
.list = xrc
.XRCCTRL(self
, 'LIST')
679 if type(v
) != IntType
:
680 wx
.LogError('Invalid item type')
682 self
.list.Append(str(v
))
683 self
.SetAutoLayout(True)
684 self
.GetSizer().Fit(self
)
686 self
.spinCtrl
= xrc
.XRCCTRL(self
, 'SPIN')
687 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_ADD'), self
.OnButtonAdd
)
688 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
689 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
690 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_CLEAR'), self
.OnButtonClear
)
691 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
692 def OnButtonAdd(self
, evt
):
693 # Check that it's unique
695 v
= self
.spinCtrl
.GetValue()
696 s
= str(v
) # to be sure
697 i
= self
.list.FindString(s
)
698 if i
== -1: # ignore non-unique
699 # Find place to insert
701 for i
in range(self
.list.GetCount()):
702 if int(self
.list.GetString(i
)) > v
:
705 if found
: self
.list.InsertItems([s
], i
)
706 else: self
.list.Append(s
)
708 wx
.LogError('List item is not an int!')
709 def OnButtonRemove(self
, evt
):
710 self
.list.Delete(self
.list.GetSelection())
711 def OnButtonClear(self
, evt
):
713 def OnUpdateUI(self
, evt
):
714 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
715 evt
.Enable(self
.list.GetSelection() != -1)
718 class ParamIntList(ParamContent
):
719 def __init__(self
, parent
, name
):
720 ParamContent
.__init
__(self
, parent
, name
)
721 def OnButtonEdit(self
, evt
):
722 if self
.textModified
: # text has newer value
724 self
.value
= map(int, self
.text
.GetValue().split('|'))
727 dlg
= IntListDialog(self
, self
.value
)
728 if dlg
.ShowModal() == wx
.ID_OK
:
730 for i
in range(dlg
.list.GetCount()):
731 value
.append(int(dlg
.list.GetString(i
)))
734 self
.textModified
= False
738 class RadioBox(PPanel
):
739 def __init__(self
, parent
, id, choices
,
740 pos
=wx
.DefaultPosition
, name
='radiobox'):
741 PPanel
.__init
__(self
, parent
, name
)
742 self
.choices
= choices
743 topSizer
= wx
.BoxSizer()
745 button
= wx
.RadioButton(self
, -1, i
, size
=(-1,buttonSize
[1]), name
=i
)
746 topSizer
.Add(button
, 0, wx
.RIGHT
, 5)
747 wx
.EVT_RADIOBUTTON(self
, button
.GetId(), self
.OnRadioChoice
)
748 self
.SetSizer(topSizer
)
749 def SetStringSelection(self
, value
):
751 for i
in self
.choices
:
752 self
.FindWindowByName(i
).SetValue(i
== value
)
755 def OnRadioChoice(self
, evt
):
756 if self
.freeze
: return
757 if evt
.GetSelection():
758 self
.value
= evt
.GetEventObject().GetName()
760 def GetStringSelection(self
):
763 class ParamBool(RadioBox
):
764 values
= {'yes': '1', 'no': '0'}
765 seulav
= {'1': 'yes', '0': 'no'}
766 def __init__(self
, parent
, name
):
767 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
769 return self
.values
[self
.GetStringSelection()]
770 def SetValue(self
, value
):
771 if not value
: value
= '1'
772 self
.SetStringSelection(self
.seulav
[value
])
774 class ParamOrient(RadioBox
):
775 values
= {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'}
776 seulav
= {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'}
777 def __init__(self
, parent
, name
):
778 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
780 return self
.values
[self
.GetStringSelection()]
781 def SetValue(self
, value
):
782 if not value
: value
= 'wxHORIZONTAL'
783 self
.SetStringSelection(self
.seulav
[value
])
785 class ParamOrientation(RadioBox
):
786 values
= {'horizontal': 'horizontal', 'vertical': 'vertical'}
787 seulav
= {'horizontal': 'horizontal', 'vertical': 'vertical'}
788 def __init__(self
, parent
, name
):
789 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
791 return self
.values
[self
.GetStringSelection()]
792 def SetValue(self
, value
):
793 if not value
: value
= 'vertical'
794 self
.SetStringSelection(self
.seulav
[value
])
796 class ParamFile(PPanel
):
797 def __init__(self
, parent
, name
):
798 PPanel
.__init
__(self
, parent
, name
)
799 self
.ID_TEXT_CTRL
= wx
.NewId()
800 self
.ID_BUTTON_BROWSE
= wx
.NewId()
801 sizer
= wx
.BoxSizer()
802 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
803 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
804 self
.button
= wx
.Button(self
, self
.ID_BUTTON_BROWSE
, 'Browse...',size
=buttonSize
)
805 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
807 self
.textModified
= False
808 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_BROWSE
, self
.OnButtonBrowse
)
809 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
810 def OnChange(self
, evt
):
811 PPanel
.OnChange(self
, evt
)
812 self
.textModified
= True
814 if self
.textModified
: # text has newer value
815 return self
.text
.GetValue()
817 def SetValue(self
, value
):
820 self
.text
.SetValue(value
) # update text ctrl
822 def OnButtonBrowse(self
, evt
):
823 if self
.textModified
: # text has newer value
824 self
.value
= self
.text
.GetValue()
825 dlg
= wx
.FileDialog(self
,
826 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
)),
827 defaultFile
= os
.path
.basename(self
.value
))
828 if dlg
.ShowModal() == wx
.ID_OK
:
829 # Get common part of selected path and current
831 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
833 curpath
= os
.path
.join(os
.getcwd(), '')
834 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
835 self
.SetValue(dlg
.GetPath()[len(common
):])
837 self
.textModified
= False
840 class ParamBitmap(PPanel
):
841 def __init__(self
, parent
, name
):
843 g
.frame
.res
.LoadOnPanel(pre
, parent
, 'PANEL_BITMAP')
845 self
.modified
= self
.freeze
= False
846 self
.radio_std
= xrc
.XRCCTRL(self
, 'RADIO_STD')
847 self
.radio_file
= xrc
.XRCCTRL(self
, 'RADIO_FILE')
848 self
.combo
= xrc
.XRCCTRL(self
, 'COMBO_STD')
849 self
.text
= xrc
.XRCCTRL(self
, 'TEXT_FILE')
850 self
.button
= xrc
.XRCCTRL(self
, 'BUTTON_BROWSE')
851 self
.textModified
= False
852 self
.SetAutoLayout(True)
853 self
.GetSizer().SetMinSize((260, -1))
854 self
.GetSizer().Fit(self
)
855 wx
.EVT_RADIOBUTTON(self
, xrc
.XRCID('RADIO_STD'), self
.OnRadioStd
)
856 wx
.EVT_RADIOBUTTON(self
, xrc
.XRCID('RADIO_FILE'), self
.OnRadioFile
)
857 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_BROWSE'), self
.OnButtonBrowse
)
858 wx
.EVT_COMBOBOX(self
, xrc
.XRCID('COMBO_STD'), self
.OnCombo
)
859 wx
.EVT_TEXT(self
, xrc
.XRCID('COMBO_STD'), self
.OnChange
)
860 wx
.EVT_TEXT(self
, xrc
.XRCID('TEXT_FILE'), self
.OnChange
)
861 def OnRadioStd(self
, evt
):
863 self
.SetValue(['wxART_MISSING_IMAGE',''])
864 def OnRadioFile(self
, evt
):
866 self
.SetValue(['',''])
867 def updateRadios(self
):
869 self
.radio_std
.SetValue(True)
870 self
.radio_file
.SetValue(False)
871 self
.text
.Enable(False)
872 self
.button
.Enable(False)
873 self
.combo
.Enable(True)
875 self
.radio_std
.SetValue(False)
876 self
.radio_file
.SetValue(True)
877 self
.text
.Enable(True)
878 self
.button
.Enable(True)
879 self
.combo
.Enable(False)
880 def OnChange(self
, evt
):
881 PPanel
.OnChange(self
, evt
)
882 self
.textModified
= True
883 def OnCombo(self
, evt
):
884 PPanel
.OnChange(self
, evt
)
885 self
.value
[0] = self
.combo
.GetValue()
887 if self
.textModified
: # text has newer value
888 return [self
.combo
.GetValue(), self
.text
.GetValue()]
890 def SetValue(self
, value
):
893 self
.value
= ['', '']
896 self
.combo
.SetValue(self
.value
[0])
897 self
.text
.SetValue(self
.value
[1]) # update text ctrl
900 def OnButtonBrowse(self
, evt
):
901 if self
.textModified
: # text has newer value
902 self
.value
[1] = self
.text
.GetValue()
903 dlg
= wx
.FileDialog(self
,
904 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
[1])),
905 defaultFile
= os
.path
.basename(self
.value
[1]))
906 if dlg
.ShowModal() == wx
.ID_OK
:
907 # Get common part of selected path and current
909 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
911 curpath
= os
.path
.join(os
.getcwd(), '')
912 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
913 self
.SetValue(['', dlg
.GetPath()[len(common
):]])
915 self
.textModified
= False
920 'style': ParamStyle
, 'exstyle': ParamExStyle
,
921 'pos': ParamPosSize
, 'size': ParamPosSize
,
922 'cellpos': ParamPosSize
, 'cellspan': ParamPosSize
,
923 'border': ParamUnit
, 'cols': ParamIntNN
, 'rows': ParamIntNN
,
924 'vgap': ParamUnit
, 'hgap': ParamUnit
,
925 'checkable': ParamBool
, 'checked': ParamBool
, 'radio': ParamBool
,
927 'label': ParamMultilineText
, 'title': ParamText
, 'value': ParamText
,
928 'content': ParamContent
, 'selection': ParamIntNN
,
929 'min': ParamInt
, 'max': ParamInt
,
930 'fg': ParamColour
, 'bg': ParamColour
, 'font': ParamFont
,
931 'enabled': ParamBool
, 'focused': ParamBool
, 'hidden': ParamBool
,
932 'tooltip': ParamText
, 'bitmap': ParamBitmap
, 'icon': ParamBitmap
,
933 'encoding': ParamEncoding
, 'borders': ParamUnit
,
934 'comment': ParamComment