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)
62 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_CHOICES
, self
.OnButtonChoices
)
63 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
65 return self
.text
.GetValue()
66 def SetValue(self
, value
):
68 self
.text
.SetValue(value
)
70 def OnButtonChoices(self
, evt
):
71 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_CHOICES')
72 if self
.GetName() == 'flag': dlg
.SetTitle('Sizer item flags')
73 elif self
.GetName() == 'style': dlg
.SetTitle('Window styles')
74 elif self
.GetName() == 'exstyle': dlg
.SetTitle('Extended window styles')
75 listBox
= xrc
.XRCCTRL(dlg
, 'CHECKLIST')
76 listBox
.InsertItems(self
.values
, 0)
77 value
= map(string
.strip
, self
.text
.GetValue().split('|'))
78 if value
== ['']: value
= []
82 listBox
.Check(self
.values
.index(i
))
85 if self
.equal
.has_key(i
):
86 listBox
.Check(self
.values
.index(self
.equal
[i
]))
88 print 'WARNING: unknown flag: %s: ignored.' % i
90 if dlg
.ShowModal() == wx
.ID_OK
:
92 for i
in range(listBox
.GetCount()):
93 if listBox
.IsChecked(i
):
94 value
.append(self
.values
[i
])
97 self
.SetValue('|'.join(value
))
101 class ParamFlag(ParamBinaryOr
):
102 values
= ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL',
103 'wxEXPAND', 'wxGROW', 'wxSHAPED', 'wxSTRETCH_NOT',
104 'wxALIGN_CENTRE', 'wxALIGN_LEFT', 'wxALIGN_RIGHT',
105 'wxALIGN_TOP', 'wxALIGN_BOTTOM',
106 'wxALIGN_CENTRE_VERTICAL', 'wxALIGN_CENTRE_HORIZONTAL',
107 'wxADJUST_MINSIZE', 'wxFIXED_MINSIZE'
109 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE',
110 'wxALIGN_CENTER_VERTICAL': 'wxALIGN_CENTRE_VERTICAL',
111 'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL',
112 'wxUP': 'wxTOP', 'wxDOWN': 'wxBOTTOM', 'wxNORTH': 'wxTOP',
113 'wxSOUTH': 'wxBOTTOM', 'wxWEST': 'wxLEFT', 'wxEAST': 'wxRIGHT'}
114 def __init__(self
, parent
, name
):
115 ParamBinaryOr
.__init
__(self
, parent
, name
)
117 class ParamNonGenericStyle(ParamBinaryOr
):
118 def __init__(self
, parent
, name
):
119 self
.values
= g
.currentXXX
.winStyles
120 ParamBinaryOr
.__init
__(self
, parent
, name
)
122 class ParamStyle(ParamBinaryOr
):
123 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE'}
124 def __init__(self
, parent
, name
):
125 ParamBinaryOr
.__init
__(self
, parent
, name
)
126 self
.valuesSpecific
= g
.currentXXX
.winStyles
127 if self
.valuesSpecific
: # override if using specific styles
129 self
.valuesGeneric
= [s
for s
in genericStyles
130 if s
not in self
.valuesSpecific
]
131 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_CHOICES
, self
.OnButtonChoicesBoth
)
133 self
.values
= genericStyles
134 def OnButtonChoicesBoth(self
, evt
):
135 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_STYLES')
136 listBoxSpecific
= xrc
.XRCCTRL(dlg
, 'CHECKLIST_SPECIFIC')
137 listBoxSpecific
.InsertItems(self
.valuesSpecific
, 0)
138 listBoxGeneric
= xrc
.XRCCTRL(dlg
, 'CHECKLIST_GENERIC')
139 listBoxGeneric
.InsertItems(self
.valuesGeneric
, 0)
140 value
= map(string
.strip
, self
.text
.GetValue().split('|'))
141 if value
== ['']: value
= []
142 # Set specific styles
143 value2
= [] # collect generic and ignored here
146 listBoxSpecific
.Check(self
.valuesSpecific
.index(i
))
149 if self
.equal
.has_key(i
):
150 listBoxSpecific
.Check(self
.valuesSpecific
.index(self
.equal
[i
]))
154 # Set generic styles, collect non-standart values
157 listBoxGeneric
.Check(self
.valuesGeneric
.index(i
))
160 if self
.equal
.has_key(i
):
161 listBoxGeneric
.Check(self
.valuesGeneric
.index(self
.equal
[i
]))
163 print 'WARNING: unknown flag: %s: ignored.' % i
165 if dlg
.ShowModal() == wx
.ID_OK
:
166 value
= [self
.valuesSpecific
[i
]
167 for i
in range(listBoxSpecific
.GetCount())
168 if listBoxSpecific
.IsChecked(i
)] + \
169 [self
.valuesGeneric
[i
]
170 for i
in range(listBoxGeneric
.GetCount())
171 if listBoxGeneric
.IsChecked(i
)] + ignored
172 self
.SetValue('|'.join(value
))
176 class ParamExStyle(ParamBinaryOr
):
177 def __init__(self
, parent
, name
):
179 self
.values
= g
.currentXXX
.exStyles
+ genericExStyles
182 ParamBinaryOr
.__init
__(self
, parent
, name
)
184 class ParamColour(PPanel
):
185 def __init__(self
, parent
, name
):
186 PPanel
.__init
__(self
, parent
, name
)
187 self
.ID_TEXT_CTRL
= wx
.NewId()
188 self
.ID_BUTTON
= wx
.NewId()
189 sizer
= wx
.BoxSizer()
190 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(80,-1))
191 sizer
.Add(self
.text
, 0, wx
.ALIGN_CENTER_VERTICAL | wx
.TOP | wx
.BOTTOM
, 2)
192 self
.button
= wx
.Panel(self
, self
.ID_BUTTON
, wx
.DefaultPosition
, wx
.Size(20, 20))
193 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL | wx
.LEFT
, 5)
194 self
.SetAutoLayout(True)
197 self
.textModified
= False
198 wx
.EVT_PAINT(self
.button
, self
.OnPaintButton
)
199 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
200 wx
.EVT_LEFT_DOWN(self
.button
, self
.OnLeftDown
)
202 return self
.text
.GetValue()
203 def SetValue(self
, value
):
205 if not value
: value
= '#FFFFFF'
206 self
.text
.SetValue(str(value
)) # update text ctrl
208 colour
= wx
.Colour(int(value
[1:3], 16), int(value
[3:5], 16), int(value
[5:7], 16))
209 self
.button
.SetBackgroundColour(colour
)
210 except: # ignore errors
212 self
.button
.Refresh()
214 def OnPaintButton(self
, evt
):
215 dc
= wx
.PaintDC(self
.button
)
216 dc
.SetBrush(wx
.TRANSPARENT_BRUSH
)
217 if self
.IsEnabled(): dc
.SetPen(wx
.BLACK_PEN
)
218 else: dc
.SetPen(wx
.GREY_PEN
)
219 size
= self
.button
.GetSize()
220 dc
.DrawRectangle(0, 0, size
.width
, size
.height
)
221 def OnLeftDown(self
, evt
):
222 data
= wx
.ColourData()
223 data
.SetColour(self
.GetValue())
224 dlg
= wx
.ColourDialog(self
, data
)
225 if dlg
.ShowModal() == wx
.ID_OK
:
226 self
.SetValue('#%02X%02X%02X' % dlg
.GetColourData().GetColour().Get())
230 ################################################################################
232 # Mapping from wx constants to XML strings
233 fontFamiliesWx2Xml
= {wx
.DEFAULT
: 'default', wx
.DECORATIVE
: 'decorative',
234 wx
.ROMAN
: 'roman', wx
.SCRIPT
: 'script', wx
.SWISS
: 'swiss',
236 fontStylesWx2Xml
= {wx.NORMAL: 'normal', wx.SLANT: 'slant', wx.ITALIC: 'italic'}
237 fontWeightsWx2Xml
= {wx.NORMAL: 'normal', wx.LIGHT: 'light', wx.BOLD: 'bold'}
240 for k
,v
in m
.items(): rm
[v
] = k
242 fontFamiliesXml2wx
= ReverseMap(fontFamiliesWx2Xml
)
243 fontStylesXml2wx
= ReverseMap(fontStylesWx2Xml
)
244 fontWeightsXml2wx
= ReverseMap(fontWeightsWx2Xml
)
246 class ParamFont(PPanel
):
247 def __init__(self
, parent
, name
):
248 PPanel
.__init
__(self
, parent
, name
)
249 self
.ID_TEXT_CTRL
= wx
.NewId()
250 self
.ID_BUTTON_SELECT
= wx
.NewId()
251 sizer
= wx
.BoxSizer()
252 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(200,-1))
253 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
254 self
.button
= wx
.Button(self
, self
.ID_BUTTON_SELECT
, 'Select...', size
=buttonSize
)
255 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
256 self
.SetAutoLayout(True)
259 self
.textModified
= False
260 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_SELECT
, self
.OnButtonSelect
)
261 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
262 def OnChange(self
, evt
):
263 PPanel
.OnChange(self
, evt
)
264 self
.textModified
= True
265 def _defaultValue(self
):
266 return [`g
._sysFont
.GetPointSize()`
, 'default', 'normal', 'normal', '0', '', '']
268 if self
.textModified
: # text has newer value
270 return eval(self
.text
.GetValue())
272 wx
.LogError('Syntax error in parameter value: ' + self
.GetName())
273 return self
._defaultValue
()
275 def SetValue(self
, value
):
276 self
.freeze
= True # disable other handlers
277 if not value
: value
= self
._defaultValue
()
279 self
.text
.SetValue(str(value
)) # update text ctrl
281 def OnButtonSelect(self
, evt
):
282 if self
.textModified
: # text has newer value
284 self
.value
= eval(self
.text
.GetValue())
286 wx
.LogError('Syntax error in parameter value: ' + self
.GetName())
287 self
.value
= self
._defaultValue
()
290 size
= g
._sysFont
.GetPointSize()
292 style
= weight
= wx
.NORMAL
295 enc
= wx
.FONTENCODING_DEFAULT
296 # Fall back to default if exceptions
299 try: size
= int(self
.value
[0])
300 except ValueError: error
= True; wx
.LogError('Invalid size specification')
301 try: family
= fontFamiliesXml2wx
[self
.value
[1]]
302 except KeyError: error
= True; wx
.LogError('Invalid family specification')
303 try: style
= fontStylesXml2wx
[self
.value
[2]]
304 except KeyError: error
= True; wx
.LogError('Invalid style specification')
305 try: weight
= fontWeightsXml2wx
[self
.value
[3]]
306 except KeyError: error
= True; wx
.LogError('Invalid weight specification')
307 try: underlined
= bool(self
.value
[4])
308 except ValueError: error
= True; wx
.LogError('Invalid underlined flag specification')
312 mapper
= wx
.FontMapper()
313 if not self
.value
[6]: enc
= mapper
.CharsetToEncoding(self
.value
[6])
315 if error
: wx
.LogError('Invalid font specification')
316 if enc
== wx
.FONTENCODING_DEFAULT
: enc
= wx
.FONTENCODING_SYSTEM
317 font
= wx
.Font(size
, family
, style
, weight
, underlined
, face
, enc
)
319 data
.SetInitialFont(font
)
320 dlg
= wx
.FontDialog(self
, data
)
321 if dlg
.ShowModal() == wx
.ID_OK
:
322 font
= dlg
.GetFontData().GetChosenFont()
323 if font
.GetEncoding() == wx
.FONTENCODING_SYSTEM
:
326 encName
= wx
.FontMapper
.GetEncodingName(font
.GetEncoding()).encode()
327 value
= [str(font
.GetPointSize()),
328 fontFamiliesWx2Xml
.get(font
.GetFamily(), "default"),
329 fontStylesWx2Xml
.get(font
.GetStyle(), "normal"),
330 fontWeightsWx2Xml
.get(font
.GetWeight(), "normal"),
331 str(int(font
.GetUnderlined())),
332 font
.GetFaceName().encode(),
337 self
.textModified
= False
340 ################################################################################
342 class ParamInt(PPanel
):
343 def __init__(self
, parent
, name
):
344 PPanel
.__init
__(self
, parent
, name
)
345 self
.ID_SPIN_CTRL
= wx
.NewId()
346 sizer
= wx
.BoxSizer()
347 self
.spin
= wx
.SpinCtrl(self
, self
.ID_SPIN_CTRL
, size
=(60,-1))
348 self
.spin
.SetRange(-2147483648, 2147483647) # min/max integers
350 self
.SetAutoLayout(True)
353 wx
.EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
355 return str(self
.spin
.GetValue())
356 def SetValue(self
, value
):
358 if not value
: value
= 0
359 self
.spin
.SetValue(int(value
))
362 # Non-negative number
363 class ParamIntNN(PPanel
):
364 def __init__(self
, parent
, name
):
365 PPanel
.__init
__(self
, parent
, name
)
366 self
.ID_SPIN_CTRL
= wx
.NewId()
367 sizer
= wx
.BoxSizer()
368 self
.spin
= wx
.SpinCtrl(self
, self
.ID_SPIN_CTRL
, size
=(60,-1))
369 self
.spin
.SetRange(0, 10000) # min/max integers
371 self
.SetAutoLayout(True)
374 wx
.EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
376 return str(self
.spin
.GetValue())
377 def SetValue(self
, value
):
379 if not value
: value
= 0
380 self
.spin
.SetValue(int(value
))
383 # Same as int but allows dialog units (XXXd)
384 class ParamUnit(PPanel
):
385 def __init__(self
, parent
, name
):
386 PPanel
.__init
__(self
, parent
, name
)
387 self
.ID_TEXT_CTRL
= wx
.NewId()
388 self
.ID_SPIN_BUTTON
= wx
.NewId()
389 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
390 self
.spin
= wx
.SpinButton(self
, self
.ID_SPIN_BUTTON
, style
= wx
.SP_VERTICAL
, size
=(-1,1))
391 textW
= 60 - self
.spin
.GetSize()[0]
392 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(textW
,-1))
393 self
.spin
.SetRange(-10000, 10000)
394 sizer
.Add(self
.text
, 0, wx
.EXPAND
)
395 sizer
.Add(self
.spin
, 0, wx
.EXPAND
)
396 #sizer.SetMinSize((50,-1))
397 self
.SetAutoLayout(True)
400 wx
.EVT_SPIN_UP(self
, self
.ID_SPIN_BUTTON
, self
.OnSpinUp
)
401 wx
.EVT_SPIN_DOWN(self
, self
.ID_SPIN_BUTTON
, self
.OnSpinDown
)
403 return self
.text
.GetValue()
404 def SetValue(self
, value
):
406 if not value
: value
= '0'
407 self
.text
.SetValue(value
)
410 # Check if we are working with dialog units
411 value
= self
.text
.GetValue()
413 if value
[-1].upper() == 'D':
417 intValue
= int(value
) + x
418 self
.spin
.SetValue(intValue
)
419 self
.text
.SetValue(str(intValue
) + units
)
422 # !!! Strange, if I use wx.LogWarning, event is re-generated
423 print 'ERROR: incorrect unit format'
424 def OnSpinUp(self
, evt
):
426 def OnSpinDown(self
, evt
):
429 class ParamMultilineText(PPanel
):
430 def __init__(self
, parent
, name
, textWidth
=-1):
431 PPanel
.__init
__(self
, parent
, name
)
432 self
.ID_TEXT_CTRL
= wx
.NewId()
433 self
.ID_BUTTON_EDIT
= wx
.NewId()
434 sizer
= wx
.BoxSizer()
435 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
436 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
437 self
.button
= wx
.Button(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
438 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
439 self
.SetAutoLayout(True)
442 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
443 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
445 return self
.text
.GetValue()
446 def SetValue(self
, value
):
447 self
.freeze
= True # disable other handlers
448 self
.text
.SetValue(value
)
449 self
.freeze
= False # disable other handlers
450 def OnButtonEdit(self
, evt
):
451 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_TEXT')
452 textCtrl
= xrc
.XRCCTRL(dlg
, 'TEXT')
453 textCtrl
.SetValue(self
.text
.GetValue())
454 if dlg
.ShowModal() == wx
.ID_OK
:
455 self
.text
.SetValue(textCtrl
.GetValue())
459 class ParamText(PPanel
):
460 def __init__(self
, parent
, name
, textWidth
=-1):
461 PPanel
.__init
__(self
, parent
, name
)
462 self
.ID_TEXT_CTRL
= wx
.NewId()
463 # We use sizer even here to have the same size of text control
464 sizer
= wx
.BoxSizer()
465 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(textWidth
,-1))
466 if textWidth
== -1: option
= 1
468 sizer
.Add(self
.text
, option
, wx
.ALIGN_CENTER_VERTICAL | wx
.TOP | wx
.BOTTOM
, 2)
469 self
.SetAutoLayout(True)
472 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
474 return self
.text
.GetValue()
475 def SetValue(self
, value
):
476 self
.freeze
= True # disable other handlers
477 self
.text
.SetValue(value
)
478 self
.freeze
= False # disable other handlers
480 class ParamAccel(ParamText
):
481 def __init__(self
, parent
, name
):
482 ParamText
.__init
__(self
, parent
, name
, 100)
484 class ParamPosSize(ParamText
):
485 def __init__(self
, parent
, name
):
486 ParamText
.__init
__(self
, parent
, name
, 80)
488 class ParamLabel(ParamText
):
489 def __init__(self
, parent
, name
):
490 ParamText
.__init
__(self
, parent
, name
, 200)
492 class ParamEncoding(ParamText
):
493 def __init__(self
, parent
, name
):
494 ParamText
.__init
__(self
, parent
, name
, 100)
496 class ContentDialog(wx
.Dialog
):
497 def __init__(self
, parent
, value
):
500 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT')
502 self
.list = xrc
.XRCCTRL(self
, 'LIST')
506 self
.SetAutoLayout(True)
507 self
.GetSizer().Fit(self
)
509 self
.ID_BUTTON_APPEND
= xrc
.XRCID('BUTTON_APPEND')
510 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
511 self
.ID_BUTTON_UP
= xrc
.XRCID('BUTTON_UP')
512 self
.ID_BUTTON_DOWN
= xrc
.XRCID('BUTTON_DOWN')
513 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
514 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
515 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
516 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
517 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
518 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
519 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
520 def OnButtonUp(self
, evt
):
521 i
= self
.list.GetSelection()
522 str = self
.list.GetString(i
)
524 self
.list.InsertItems([str], i
-1)
525 self
.list.SetSelection(i
-1)
526 def OnButtonDown(self
, evt
):
527 i
= self
.list.GetSelection()
528 str = self
.list.GetString(i
)
530 self
.list.InsertItems([str], i
+1)
531 self
.list.SetSelection(i
+1)
532 def OnButtonAppend(self
, evt
):
533 str = wx
.GetTextFromUser('Enter new item:', 'Append', '', self
)
534 self
.list.Append(str)
535 def OnButtonRemove(self
, evt
):
536 self
.list.Delete(self
.list.GetSelection())
537 def OnUpdateUI(self
, evt
):
538 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
539 evt
.Enable(self
.list.GetSelection() != -1)
540 elif evt
.GetId() == self
.ID_BUTTON_UP
:
541 evt
.Enable(self
.list.GetSelection() > 0)
542 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
543 evt
.Enable(self
.list.GetSelection() != -1 and \
544 self
.list.GetSelection() < self
.list.GetCount() - 1)
546 class ContentCheckListDialog(wx
.Dialog
):
547 def __init__(self
, parent
, value
):
549 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT_CHECKLIST')
551 self
.list = xrc
.XRCCTRL(self
, 'CHECK_LIST')
556 self
.list.Check(i
, ch
)
558 self
.SetAutoLayout(True)
559 self
.GetSizer().Fit(self
)
561 self
.ID_BUTTON_APPEND
= xrc
.XRCID('BUTTON_APPEND')
562 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
563 self
.ID_BUTTON_UP
= xrc
.XRCID('BUTTON_UP')
564 self
.ID_BUTTON_DOWN
= xrc
.XRCID('BUTTON_DOWN')
565 wx
.EVT_CHECKLISTBOX(self
, self
.list.GetId(), self
.OnCheck
)
566 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
567 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
568 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
569 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
570 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
571 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
572 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
573 def OnCheck(self
, evt
):
574 # !!! Wrong wxGTK (wxMSW?) behavior: toggling selection if checking
575 self
.list.Deselect(evt
.GetSelection())
576 def OnButtonUp(self
, evt
):
577 i
= self
.list.GetSelection()
578 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
580 self
.list.InsertItems([str], i
-1)
581 self
.list.Check(i
-1, ch
)
582 self
.list.SetSelection(i
-1)
583 def OnButtonDown(self
, evt
):
584 i
= self
.list.GetSelection()
585 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
587 self
.list.InsertItems([str], i
+1)
588 self
.list.Check(i
+1, ch
)
589 self
.list.SetSelection(i
+1)
590 def OnButtonAppend(self
, evt
):
591 str = wx
.GetTextFromUser('Enter new item:', 'Append', '', self
)
592 self
.list.Append(str)
593 def OnButtonRemove(self
, evt
):
594 self
.list.Delete(self
.list.GetSelection())
595 def OnUpdateUI(self
, evt
):
596 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
597 evt
.Enable(self
.list.GetSelection() != -1)
598 elif evt
.GetId() == self
.ID_BUTTON_UP
:
599 evt
.Enable(self
.list.GetSelection() > 0)
600 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
601 evt
.Enable(self
.list.GetSelection() != -1 and \
602 self
.list.GetSelection() < self
.list.GetCount() - 1)
604 class ParamContent(PPanel
):
605 def __init__(self
, parent
, name
):
606 PPanel
.__init
__(self
, parent
, name
)
607 self
.ID_TEXT_CTRL
= wx
.NewId()
608 self
.ID_BUTTON_EDIT
= wx
.NewId()
609 sizer
= wx
.BoxSizer()
610 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
611 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
612 self
.button
= wx
.Button(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
613 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
614 self
.SetAutoLayout(True)
617 self
.textModified
= False
618 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
619 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
620 def OnChange(self
, evt
):
621 PPanel
.OnChange(self
, evt
)
622 self
.textModified
= True
624 if self
.textModified
: # text has newer value
626 return self
.text
.GetValue().split('|')
630 def SetValue(self
, value
):
632 if not value
: value
= []
634 repr_
= '|'.join(map(str, value
))
635 self
.text
.SetValue(repr_
) # update text ctrl
637 def OnButtonEdit(self
, evt
):
638 if self
.textModified
: # text has newer value
639 self
.value
= self
.GetValue()
640 dlg
= ContentDialog(self
, self
.value
)
641 if dlg
.ShowModal() == wx
.ID_OK
:
643 for i
in range(dlg
.list.GetCount()):
644 value
.append(dlg
.list.GetString(i
))
647 self
.textModified
= False
649 def SetModified(self
, state
=True):
650 PPanel
.SetModified(self
, state
)
651 self
.textModified
= False
654 class ParamContentCheckList(ParamContent
):
655 def __init__(self
, parent
, name
):
656 ParamContent
.__init
__(self
, parent
, name
)
657 def OnButtonEdit(self
, evt
):
658 if self
.textModified
: # text has newer value
659 self
.value
= self
.GetValue()
660 dlg
= ContentCheckListDialog(self
, self
.value
)
661 if dlg
.ShowModal() == wx
.ID_OK
:
663 for i
in range(dlg
.list.GetCount()):
664 value
.append((dlg
.list.GetString(i
), int(dlg
.list.IsChecked(i
))))
667 self
.textModified
= False
669 def SetValue(self
, value
):
671 if not value
: value
= []
673 repr_
= '|'.join(map(str,value
))
674 self
.text
.SetValue(repr_
) # update text ctrl
677 class IntListDialog(wx
.Dialog
):
678 def __init__(self
, parent
, value
):
680 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_INTLIST')
682 self
.list = xrc
.XRCCTRL(self
, 'LIST')
686 if type(v
) != IntType
:
687 wx
.LogError('Invalid item type')
689 self
.list.Append(str(v
))
690 self
.SetAutoLayout(True)
691 self
.GetSizer().Fit(self
)
693 self
.spinCtrl
= xrc
.XRCCTRL(self
, 'SPIN')
694 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_ADD'), self
.OnButtonAdd
)
695 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
696 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
697 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_CLEAR'), self
.OnButtonClear
)
698 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
699 def OnButtonAdd(self
, evt
):
700 # Check that it's unique
702 v
= self
.spinCtrl
.GetValue()
703 s
= str(v
) # to be sure
704 i
= self
.list.FindString(s
)
705 if i
== -1: # ignore non-unique
706 # Find place to insert
708 for i
in range(self
.list.GetCount()):
709 if int(self
.list.GetString(i
)) > v
:
712 if found
: self
.list.InsertItems([s
], i
)
713 else: self
.list.Append(s
)
715 wx
.LogError('List item is not an int!')
716 def OnButtonRemove(self
, evt
):
717 self
.list.Delete(self
.list.GetSelection())
718 def OnButtonClear(self
, evt
):
720 def OnUpdateUI(self
, evt
):
721 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
722 evt
.Enable(self
.list.GetSelection() != -1)
725 class ParamIntList(ParamContent
):
726 def __init__(self
, parent
, name
):
727 ParamContent
.__init
__(self
, parent
, name
)
728 def OnButtonEdit(self
, evt
):
729 if self
.textModified
: # text has newer value
731 self
.value
= map(int, self
.text
.GetValue().split('|'))
734 dlg
= IntListDialog(self
, self
.value
)
735 if dlg
.ShowModal() == wx
.ID_OK
:
737 for i
in range(dlg
.list.GetCount()):
738 value
.append(int(dlg
.list.GetString(i
)))
741 self
.textModified
= False
745 class RadioBox(PPanel
):
746 def __init__(self
, parent
, id, choices
,
747 pos
=wx
.DefaultPosition
, name
='radiobox'):
748 PPanel
.__init
__(self
, parent
, name
)
749 self
.choices
= choices
750 topSizer
= wx
.BoxSizer()
752 button
= wx
.RadioButton(self
, -1, i
, size
=(-1,buttonSize
[1]), name
=i
)
753 topSizer
.Add(button
, 0, wx
.RIGHT
, 5)
754 wx
.EVT_RADIOBUTTON(self
, button
.GetId(), self
.OnRadioChoice
)
755 self
.SetAutoLayout(True)
756 self
.SetSizer(topSizer
)
758 def SetStringSelection(self
, value
):
760 for i
in self
.choices
:
761 self
.FindWindowByName(i
).SetValue(i
== value
)
764 def OnRadioChoice(self
, evt
):
765 if self
.freeze
: return
766 if evt
.GetSelection():
767 self
.value
= evt
.GetEventObject().GetName()
769 def GetStringSelection(self
):
772 class ParamBool(RadioBox
):
773 values
= {'yes': '1', 'no': '0'}
774 seulav
= {'1': 'yes', '0': 'no'}
775 def __init__(self
, parent
, name
):
776 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
778 return self
.values
[self
.GetStringSelection()]
779 def SetValue(self
, value
):
780 if not value
: value
= '1'
781 self
.SetStringSelection(self
.seulav
[value
])
783 class ParamOrient(RadioBox
):
784 values
= {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'}
785 seulav
= {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'}
786 def __init__(self
, parent
, name
):
787 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
789 return self
.values
[self
.GetStringSelection()]
790 def SetValue(self
, value
):
791 if not value
: value
= 'wxHORIZONTAL'
792 self
.SetStringSelection(self
.seulav
[value
])
794 class ParamOrientation(RadioBox
):
795 values
= {'horizontal': 'horizontal', 'vertical': 'vertical'}
796 seulav
= {'horizontal': 'horizontal', 'vertical': 'vertical'}
797 def __init__(self
, parent
, name
):
798 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
800 return self
.values
[self
.GetStringSelection()]
801 def SetValue(self
, value
):
802 if not value
: value
= 'vertical'
803 self
.SetStringSelection(self
.seulav
[value
])
805 class ParamFile(PPanel
):
806 def __init__(self
, parent
, name
):
807 PPanel
.__init
__(self
, parent
, name
)
808 self
.ID_TEXT_CTRL
= wx
.NewId()
809 self
.ID_BUTTON_BROWSE
= wx
.NewId()
810 sizer
= wx
.BoxSizer()
811 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
812 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
813 self
.button
= wx
.Button(self
, self
.ID_BUTTON_BROWSE
, 'Browse...',size
=buttonSize
)
814 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
815 self
.SetAutoLayout(True)
818 self
.textModified
= False
819 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_BROWSE
, self
.OnButtonBrowse
)
820 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
821 def OnChange(self
, evt
):
822 PPanel
.OnChange(self
, evt
)
823 self
.textModified
= True
825 if self
.textModified
: # text has newer value
826 return self
.text
.GetValue()
828 def SetValue(self
, value
):
831 self
.text
.SetValue(value
) # update text ctrl
833 def OnButtonBrowse(self
, evt
):
834 if self
.textModified
: # text has newer value
835 self
.value
= self
.text
.GetValue()
836 dlg
= wx
.FileDialog(self
,
837 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
)),
838 defaultFile
= os
.path
.basename(self
.value
))
839 if dlg
.ShowModal() == wx
.ID_OK
:
840 # Get common part of selected path and current
842 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
844 curpath
= os
.path
.join(os
.getcwd(), '')
845 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
846 self
.SetValue(dlg
.GetPath()[len(common
):])
848 self
.textModified
= False
851 class ParamBitmap(PPanel
):
852 def __init__(self
, parent
, name
):
854 g
.frame
.res
.LoadOnPanel(pre
, parent
, 'PANEL_BITMAP')
856 self
.modified
= self
.freeze
= False
857 self
.radio_std
= xrc
.XRCCTRL(self
, 'RADIO_STD')
858 self
.radio_file
= xrc
.XRCCTRL(self
, 'RADIO_FILE')
859 self
.combo
= xrc
.XRCCTRL(self
, 'COMBO_STD')
860 self
.text
= xrc
.XRCCTRL(self
, 'TEXT_FILE')
861 self
.button
= xrc
.XRCCTRL(self
, 'BUTTON_BROWSE')
862 self
.textModified
= False
863 self
.SetAutoLayout(True)
864 self
.GetSizer().SetMinSize((260, -1))
865 self
.GetSizer().Fit(self
)
866 wx
.EVT_RADIOBUTTON(self
, xrc
.XRCID('RADIO_STD'), self
.OnRadioStd
)
867 wx
.EVT_RADIOBUTTON(self
, xrc
.XRCID('RADIO_FILE'), self
.OnRadioFile
)
868 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_BROWSE'), self
.OnButtonBrowse
)
869 wx
.EVT_COMBOBOX(self
, xrc
.XRCID('COMBO_STD'), self
.OnCombo
)
870 wx
.EVT_TEXT(self
, xrc
.XRCID('COMBO_STD'), self
.OnChange
)
871 wx
.EVT_TEXT(self
, xrc
.XRCID('TEXT_FILE'), self
.OnChange
)
872 def OnRadioStd(self
, evt
):
874 self
.SetValue(['wxART_MISSING_IMAGE',''])
875 def OnRadioFile(self
, evt
):
877 self
.SetValue(['',''])
878 def updateRadios(self
):
880 self
.radio_std
.SetValue(True)
881 self
.radio_file
.SetValue(False)
882 self
.text
.Enable(False)
883 self
.button
.Enable(False)
884 self
.combo
.Enable(True)
886 self
.radio_std
.SetValue(False)
887 self
.radio_file
.SetValue(True)
888 self
.text
.Enable(True)
889 self
.button
.Enable(True)
890 self
.combo
.Enable(False)
891 def OnChange(self
, evt
):
892 PPanel
.OnChange(self
, evt
)
893 self
.textModified
= True
894 def OnCombo(self
, evt
):
895 PPanel
.OnChange(self
, evt
)
896 self
.value
[0] = self
.combo
.GetValue()
898 if self
.textModified
: # text has newer value
899 return [self
.combo
.GetValue(), self
.text
.GetValue()]
901 def SetValue(self
, value
):
904 self
.value
= ['', '']
907 self
.combo
.SetValue(self
.value
[0])
908 self
.text
.SetValue(self
.value
[1]) # update text ctrl
911 def OnButtonBrowse(self
, evt
):
912 if self
.textModified
: # text has newer value
913 self
.value
[1] = self
.text
.GetValue()
914 dlg
= wx
.FileDialog(self
,
915 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
[1])),
916 defaultFile
= os
.path
.basename(self
.value
[1]))
917 if dlg
.ShowModal() == wx
.ID_OK
:
918 # Get common part of selected path and current
920 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
922 curpath
= os
.path
.join(os
.getcwd(), '')
923 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
924 self
.SetValue(['', dlg
.GetPath()[len(common
):]])
926 self
.textModified
= False
931 'style': ParamStyle
, 'exstyle': ParamExStyle
,
932 'pos': ParamPosSize
, 'size': ParamPosSize
,
933 'cellpos': ParamPosSize
, 'cellspan': ParamPosSize
,
934 'border': ParamUnit
, 'cols': ParamIntNN
, 'rows': ParamIntNN
,
935 'vgap': ParamUnit
, 'hgap': ParamUnit
,
936 'checkable': ParamBool
, 'checked': ParamBool
, 'radio': ParamBool
,
938 'label': ParamMultilineText
, 'title': ParamText
, 'value': ParamText
,
939 'content': ParamContent
, 'selection': ParamIntNN
,
940 'min': ParamInt
, 'max': ParamInt
,
941 'fg': ParamColour
, 'bg': ParamColour
, 'font': ParamFont
,
942 'enabled': ParamBool
, 'focused': ParamBool
, 'hidden': ParamBool
,
943 'tooltip': ParamText
, 'bitmap': ParamBitmap
, 'icon': ParamBitmap
,
944 'encoding': ParamEncoding
, 'borders': ParamUnit