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
):
42 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 print font
.GetEncoding()
324 if font
.GetEncoding() == wx
.FONTENCODING_SYSTEM
:
327 encName
= wx
.FontMapper
.GetEncodingName(font
.GetEncoding()).encode()
328 value
= [str(font
.GetPointSize()),
329 fontFamiliesWx2Xml
.get(font
.GetFamily(), "default"),
330 fontStylesWx2Xml
.get(font
.GetStyle(), "normal"),
331 fontWeightsWx2Xml
.get(font
.GetWeight(), "normal"),
332 str(int(font
.GetUnderlined())),
333 font
.GetFaceName().encode(),
338 self
.textModified
= False
341 ################################################################################
343 class ParamInt(PPanel
):
344 def __init__(self
, parent
, name
):
345 PPanel
.__init
__(self
, parent
, name
)
346 self
.ID_SPIN_CTRL
= wx
.NewId()
347 sizer
= wx
.BoxSizer()
348 self
.spin
= wx
.SpinCtrl(self
, self
.ID_SPIN_CTRL
, size
=(60,-1))
349 self
.spin
.SetRange(-2147483648, 2147483647) # min/max integers
351 self
.SetAutoLayout(True)
354 wx
.EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
356 return str(self
.spin
.GetValue())
357 def SetValue(self
, value
):
359 if not value
: value
= 0
360 self
.spin
.SetValue(int(value
))
363 # Non-negative number
364 class ParamIntNN(PPanel
):
365 def __init__(self
, parent
, name
):
366 PPanel
.__init
__(self
, parent
, name
)
367 self
.ID_SPIN_CTRL
= wx
.NewId()
368 sizer
= wx
.BoxSizer()
369 self
.spin
= wx
.SpinCtrl(self
, self
.ID_SPIN_CTRL
, size
=(60,-1))
370 self
.spin
.SetRange(0, 10000) # min/max integers
372 self
.SetAutoLayout(True)
375 wx
.EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
377 return str(self
.spin
.GetValue())
378 def SetValue(self
, value
):
380 if not value
: value
= 0
381 self
.spin
.SetValue(int(value
))
384 # Same as int but allows dialog units (XXXd)
385 class ParamUnit(PPanel
):
386 def __init__(self
, parent
, name
):
387 PPanel
.__init
__(self
, parent
, name
)
388 self
.ID_TEXT_CTRL
= wx
.NewId()
389 self
.ID_SPIN_BUTTON
= wx
.NewId()
390 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
391 self
.spin
= wx
.SpinButton(self
, self
.ID_SPIN_BUTTON
, style
= wx
.SP_VERTICAL
, size
=(-1,1))
392 textW
= 60 - self
.spin
.GetSize()[0]
393 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(textW
,-1))
394 self
.spin
.SetRange(-10000, 10000)
395 sizer
.Add(self
.text
, 0, wx
.EXPAND
)
396 sizer
.Add(self
.spin
, 0, wx
.EXPAND
)
397 #sizer.SetMinSize((50,-1))
398 self
.SetAutoLayout(True)
401 wx
.EVT_SPIN_UP(self
, self
.ID_SPIN_BUTTON
, self
.OnSpinUp
)
402 wx
.EVT_SPIN_DOWN(self
, self
.ID_SPIN_BUTTON
, self
.OnSpinDown
)
404 return self
.text
.GetValue()
405 def SetValue(self
, value
):
407 if not value
: value
= '0'
408 self
.text
.SetValue(value
)
411 # Check if we are working with dialog units
412 value
= self
.text
.GetValue()
414 if value
[-1].upper() == 'D':
418 intValue
= int(value
) + x
419 self
.spin
.SetValue(intValue
)
420 self
.text
.SetValue(str(intValue
) + units
)
423 # !!! Strange, if I use wx.LogWarning, event is re-generated
424 print 'incorrect unit format'
425 def OnSpinUp(self
, evt
):
427 def OnSpinDown(self
, evt
):
430 class ParamMultilineText(PPanel
):
431 def __init__(self
, parent
, name
, textWidth
=-1):
432 PPanel
.__init
__(self
, parent
, name
)
433 self
.ID_TEXT_CTRL
= wx
.NewId()
434 self
.ID_BUTTON_EDIT
= wx
.NewId()
435 sizer
= wx
.BoxSizer()
436 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
437 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
438 self
.button
= wx
.Button(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
439 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
440 self
.SetAutoLayout(True)
443 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
444 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
446 return self
.text
.GetValue()
447 def SetValue(self
, value
):
448 self
.freeze
= True # disable other handlers
449 self
.text
.SetValue(value
)
450 self
.freeze
= False # disable other handlers
451 def OnButtonEdit(self
, evt
):
452 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_TEXT')
453 textCtrl
= xrc
.XRCCTRL(dlg
, 'TEXT')
454 textCtrl
.SetValue(self
.text
.GetValue())
455 if dlg
.ShowModal() == wx
.ID_OK
:
456 self
.text
.SetValue(textCtrl
.GetValue())
460 class ParamText(PPanel
):
461 def __init__(self
, parent
, name
, textWidth
=-1):
462 PPanel
.__init
__(self
, parent
, name
)
463 self
.ID_TEXT_CTRL
= wx
.NewId()
464 # We use sizer even here to have the same size of text control
465 sizer
= wx
.BoxSizer()
466 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(textWidth
,-1))
467 if textWidth
== -1: option
= 1
469 sizer
.Add(self
.text
, option
, wx
.ALIGN_CENTER_VERTICAL | wx
.TOP | wx
.BOTTOM
, 2)
470 self
.SetAutoLayout(True)
473 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
475 return self
.text
.GetValue()
476 def SetValue(self
, value
):
477 self
.freeze
= True # disable other handlers
478 self
.text
.SetValue(value
)
479 self
.freeze
= False # disable other handlers
481 class ParamAccel(ParamText
):
482 def __init__(self
, parent
, name
):
483 ParamText
.__init
__(self
, parent
, name
, 100)
485 class ParamPosSize(ParamText
):
486 def __init__(self
, parent
, name
):
487 ParamText
.__init
__(self
, parent
, name
, 80)
489 class ParamLabel(ParamText
):
490 def __init__(self
, parent
, name
):
491 ParamText
.__init
__(self
, parent
, name
, 200)
493 class ParamEncoding(ParamText
):
494 def __init__(self
, parent
, name
):
495 ParamText
.__init
__(self
, parent
, name
, 100)
497 class ContentDialog(wx
.Dialog
):
498 def __init__(self
, parent
, value
):
501 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT')
503 self
.list = xrc
.XRCCTRL(self
, 'LIST')
507 self
.SetAutoLayout(True)
508 self
.GetSizer().Fit(self
)
510 self
.ID_BUTTON_APPEND
= xrc
.XRCID('BUTTON_APPEND')
511 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
512 self
.ID_BUTTON_UP
= xrc
.XRCID('BUTTON_UP')
513 self
.ID_BUTTON_DOWN
= xrc
.XRCID('BUTTON_DOWN')
514 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
515 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
516 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
517 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
518 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
519 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
520 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
521 def OnButtonUp(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 OnButtonDown(self
, evt
):
528 i
= self
.list.GetSelection()
529 str = self
.list.GetString(i
)
531 self
.list.InsertItems([str], i
+1)
532 self
.list.SetSelection(i
+1)
533 def OnButtonAppend(self
, evt
):
534 str = wx
.GetTextFromUser('Enter new item:', 'Append', '', self
)
535 self
.list.Append(str)
536 def OnButtonRemove(self
, evt
):
537 self
.list.Delete(self
.list.GetSelection())
538 def OnUpdateUI(self
, evt
):
539 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
540 evt
.Enable(self
.list.GetSelection() != -1)
541 elif evt
.GetId() == self
.ID_BUTTON_UP
:
542 evt
.Enable(self
.list.GetSelection() > 0)
543 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
544 evt
.Enable(self
.list.GetSelection() != -1 and \
545 self
.list.GetSelection() < self
.list.GetCount() - 1)
547 class ContentCheckListDialog(wx
.Dialog
):
548 def __init__(self
, parent
, value
):
550 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT_CHECKLIST')
552 self
.list = xrc
.XRCCTRL(self
, 'CHECK_LIST')
557 self
.list.Check(i
, ch
)
559 self
.SetAutoLayout(True)
560 self
.GetSizer().Fit(self
)
562 self
.ID_BUTTON_APPEND
= xrc
.XRCID('BUTTON_APPEND')
563 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
564 self
.ID_BUTTON_UP
= xrc
.XRCID('BUTTON_UP')
565 self
.ID_BUTTON_DOWN
= xrc
.XRCID('BUTTON_DOWN')
566 wx
.EVT_CHECKLISTBOX(self
, self
.list.GetId(), self
.OnCheck
)
567 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
568 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
569 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
570 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
571 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
572 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
573 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
574 def OnCheck(self
, evt
):
575 # !!! Wrong wxGTK (wxMSW?) behavior: toggling selection if checking
576 self
.list.Deselect(evt
.GetSelection())
577 def OnButtonUp(self
, evt
):
578 i
= self
.list.GetSelection()
579 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
581 self
.list.InsertItems([str], i
-1)
582 self
.list.Check(i
-1, ch
)
583 self
.list.SetSelection(i
-1)
584 def OnButtonDown(self
, evt
):
585 i
= self
.list.GetSelection()
586 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
588 self
.list.InsertItems([str], i
+1)
589 self
.list.Check(i
+1, ch
)
590 self
.list.SetSelection(i
+1)
591 def OnButtonAppend(self
, evt
):
592 str = wx
.GetTextFromUser('Enter new item:', 'Append', '', self
)
593 self
.list.Append(str)
594 def OnButtonRemove(self
, evt
):
595 self
.list.Delete(self
.list.GetSelection())
596 def OnUpdateUI(self
, evt
):
597 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
598 evt
.Enable(self
.list.GetSelection() != -1)
599 elif evt
.GetId() == self
.ID_BUTTON_UP
:
600 evt
.Enable(self
.list.GetSelection() > 0)
601 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
602 evt
.Enable(self
.list.GetSelection() != -1 and \
603 self
.list.GetSelection() < self
.list.GetCount() - 1)
605 class ParamContent(PPanel
):
606 def __init__(self
, parent
, name
):
607 PPanel
.__init
__(self
, parent
, name
)
608 self
.ID_TEXT_CTRL
= wx
.NewId()
609 self
.ID_BUTTON_EDIT
= wx
.NewId()
610 sizer
= wx
.BoxSizer()
611 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
612 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
613 self
.button
= wx
.Button(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
614 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
615 self
.SetAutoLayout(True)
618 self
.textModified
= False
619 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
620 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
621 def OnChange(self
, evt
):
622 PPanel
.OnChange(self
, evt
)
623 self
.textModified
= True
625 if self
.textModified
: # text has newer value
627 return self
.text
.GetValue().split('|')
629 wx
.LogError('Syntax error in parameter value: ' + self
.GetName())
632 def SetValue(self
, value
):
634 if not value
: value
= []
636 repr_
= '|'.join(map(str, value
))
637 self
.text
.SetValue(repr_
) # update text ctrl
639 def OnButtonEdit(self
, evt
):
640 if self
.textModified
: # text has newer value
641 self
.value
= self
.GetValue()
642 dlg
= ContentDialog(self
, self
.value
)
643 if dlg
.ShowModal() == wx
.ID_OK
:
645 for i
in range(dlg
.list.GetCount()):
646 value
.append(dlg
.list.GetString(i
))
649 self
.textModified
= False
653 class ParamContentCheckList(ParamContent
):
654 def __init__(self
, parent
, name
):
655 ParamContent
.__init
__(self
, parent
, name
)
656 def OnButtonEdit(self
, evt
):
657 if self
.textModified
: # text has newer value
658 self
.value
= self
.GetValue()
659 dlg
= ContentCheckListDialog(self
, self
.value
)
660 if dlg
.ShowModal() == wx
.ID_OK
:
662 for i
in range(dlg
.list.GetCount()):
663 value
.append((dlg
.list.GetString(i
), int(dlg
.list.IsChecked(i
))))
666 self
.textModified
= False
668 def SetValue(self
, value
):
670 if not value
: value
= []
672 repr_
= '|'.join(map(str,value
))
673 self
.text
.SetValue(repr_
) # update text ctrl
676 class IntListDialog(wx
.Dialog
):
677 def __init__(self
, parent
, value
):
679 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_INTLIST')
681 self
.list = xrc
.XRCCTRL(self
, 'LIST')
685 if type(v
) != IntType
:
686 wx
.LogError('Invalid item type')
688 self
.list.Append(str(v
))
689 self
.SetAutoLayout(True)
690 self
.GetSizer().Fit(self
)
692 self
.spinCtrl
= xrc
.XRCCTRL(self
, 'SPIN')
693 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_ADD'), self
.OnButtonAdd
)
694 self
.ID_BUTTON_REMOVE
= xrc
.XRCID('BUTTON_REMOVE')
695 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
696 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_CLEAR'), self
.OnButtonClear
)
697 wx
.EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
698 def OnButtonAdd(self
, evt
):
699 # Check that it's unique
701 v
= self
.spinCtrl
.GetValue()
702 s
= str(v
) # to be sure
703 i
= self
.list.FindString(s
)
704 if i
== -1: # ignore non-unique
705 # Find place to insert
707 for i
in range(self
.list.GetCount()):
708 if int(self
.list.GetString(i
)) > v
:
711 if found
: self
.list.InsertItems([s
], i
)
712 else: self
.list.Append(s
)
714 wx
.LogError('List item is not an int!')
715 def OnButtonRemove(self
, evt
):
716 self
.list.Delete(self
.list.GetSelection())
717 def OnButtonClear(self
, evt
):
719 def OnUpdateUI(self
, evt
):
720 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
721 evt
.Enable(self
.list.GetSelection() != -1)
724 class ParamIntList(ParamContent
):
725 def __init__(self
, parent
, name
):
726 ParamContent
.__init
__(self
, parent
, name
)
727 def OnButtonEdit(self
, evt
):
728 if self
.textModified
: # text has newer value
730 self
.value
= map(int, self
.text
.GetValue().split('|'))
732 wx
.LogError('Syntax error in parameter value: ' + self
.GetName())
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