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 vars initialized in Panel.__init__ for button and textbox size in screen pixels
29 buttonSize
= textSise
= None
30 # Default Button size in dialog units
34 # Class that can properly disable children
35 class PPanel(wx
.Panel
):
36 def __init__(self
, parent
, name
):
37 wx
.Panel
.__init
__(self
, parent
, -1, name
=name
)
38 self
.modified
= self
.freeze
= False
39 def Enable(self
, value
):
41 # Something strange is going on with enable so we make sure...
42 for w
in self
.GetChildren():
44 #wx.Panel.Enable(self, value)
45 def SetModified(self
, state
=True):
47 if state
: g
.panel
.SetModified(True)
48 # Common method to set modified state
49 def OnChange(self
, evt
):
50 if self
.freeze
: return
54 class ParamBinaryOr(PPanel
):
55 def __init__(self
, parent
, name
):
56 PPanel
.__init
__(self
, parent
, name
)
57 self
.ID_TEXT_CTRL
= wx
.NewId()
58 self
.ID_BUTTON_CHOICES
= wx
.NewId()
60 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
61 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
62 self
.button
= wx
.Button(self
, self
.ID_BUTTON_CHOICES
, 'Edit...',
63 size
=(buttonSize
[0], textSize
[1]))
64 sizer
.Add(self
.button
, 0, wx
.EXPAND
)
65 self
.SetSizerAndFit(sizer
)
66 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_CHOICES
, self
.OnButtonChoices
)
67 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
69 return self
.text
.GetValue()
70 def SetValue(self
, value
):
72 self
.text
.SetValue(value
)
74 def OnButtonChoices(self
, evt
):
75 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_CHOICES')
76 if self
.GetName() == 'flag': dlg
.SetTitle('Sizer item flags')
77 elif self
.GetName() == 'style': dlg
.SetTitle('Window styles')
78 elif self
.GetName() == 'exstyle': dlg
.SetTitle('Extended window styles')
79 listBox
= xrc
.XRCCTRL(dlg
, 'CHECKLIST')
80 listBox
.InsertItems(self
.values
, 0)
81 value
= map(string
.strip
, self
.text
.GetValue().split('|'))
82 if value
== ['']: value
= []
86 listBox
.Check(self
.values
.index(i
))
89 if self
.equal
.has_key(i
):
90 listBox
.Check(self
.values
.index(self
.equal
[i
]))
92 print 'WARNING: unknown flag: %s: ignored.' % i
94 if dlg
.ShowModal() == wx
.ID_OK
:
96 for i
in range(listBox
.GetCount()):
97 if listBox
.IsChecked(i
):
98 value
.append(self
.values
[i
])
100 value
.extend(ignored
)
101 self
.SetValue('|'.join(value
))
105 class ParamFlag(ParamBinaryOr
):
106 values
= ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL',
107 'wxEXPAND', 'wxGROW', 'wxSHAPED', 'wxSTRETCH_NOT',
108 'wxALIGN_CENTRE', 'wxALIGN_LEFT', 'wxALIGN_RIGHT',
109 'wxALIGN_TOP', 'wxALIGN_BOTTOM',
110 'wxALIGN_CENTRE_VERTICAL', 'wxALIGN_CENTRE_HORIZONTAL',
111 'wxADJUST_MINSIZE', 'wxFIXED_MINSIZE'
113 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE',
114 'wxALIGN_CENTER_VERTICAL': 'wxALIGN_CENTRE_VERTICAL',
115 'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL',
116 'wxUP': 'wxTOP', 'wxDOWN': 'wxBOTTOM', 'wxNORTH': 'wxTOP',
117 'wxSOUTH': 'wxBOTTOM', 'wxWEST': 'wxLEFT', 'wxEAST': 'wxRIGHT'}
118 def __init__(self
, parent
, name
):
119 ParamBinaryOr
.__init
__(self
, parent
, name
)
121 class ParamNonGenericStyle(ParamBinaryOr
):
122 def __init__(self
, parent
, name
):
123 self
.values
= g
.currentXXX
.winStyles
124 ParamBinaryOr
.__init
__(self
, parent
, name
)
126 class ParamStyle(ParamBinaryOr
):
127 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE'}
128 def __init__(self
, parent
, name
):
129 ParamBinaryOr
.__init
__(self
, parent
, name
)
130 self
.valuesSpecific
= g
.currentXXX
.winStyles
131 if self
.valuesSpecific
: # override if using specific styles
133 self
.valuesGeneric
= [s
for s
in genericStyles
134 if s
not in self
.valuesSpecific
]
135 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_CHOICES
, self
.OnButtonChoicesBoth
)
137 self
.values
= genericStyles
138 def OnButtonChoicesBoth(self
, evt
):
139 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_STYLES')
140 listBoxSpecific
= xrc
.XRCCTRL(dlg
, 'CHECKLIST_SPECIFIC')
141 listBoxSpecific
.InsertItems(self
.valuesSpecific
, 0)
142 listBoxGeneric
= xrc
.XRCCTRL(dlg
, 'CHECKLIST_GENERIC')
143 listBoxGeneric
.InsertItems(self
.valuesGeneric
, 0)
144 value
= map(string
.strip
, self
.text
.GetValue().split('|'))
145 if value
== ['']: value
= []
146 # Set specific styles
147 value2
= [] # collect generic and ignored here
150 listBoxSpecific
.Check(self
.valuesSpecific
.index(i
))
153 if self
.equal
.has_key(i
):
154 listBoxSpecific
.Check(self
.valuesSpecific
.index(self
.equal
[i
]))
158 # Set generic styles, collect non-standart values
161 listBoxGeneric
.Check(self
.valuesGeneric
.index(i
))
164 if self
.equal
.has_key(i
):
165 listBoxGeneric
.Check(self
.valuesGeneric
.index(self
.equal
[i
]))
167 print 'WARNING: unknown flag: %s: ignored.' % i
169 if dlg
.ShowModal() == wx
.ID_OK
:
170 value
= [self
.valuesSpecific
[i
]
171 for i
in range(listBoxSpecific
.GetCount())
172 if listBoxSpecific
.IsChecked(i
)] + \
173 [self
.valuesGeneric
[i
]
174 for i
in range(listBoxGeneric
.GetCount())
175 if listBoxGeneric
.IsChecked(i
)] + ignored
176 self
.SetValue('|'.join(value
))
180 class ParamExStyle(ParamBinaryOr
):
181 def __init__(self
, parent
, name
):
183 self
.values
= g
.currentXXX
.exStyles
+ genericExStyles
186 ParamBinaryOr
.__init
__(self
, parent
, name
)
188 class ParamColour(PPanel
):
189 def __init__(self
, parent
, name
):
190 PPanel
.__init
__(self
, parent
, name
)
191 self
.ID_TEXT_CTRL
= wx
.NewId()
192 self
.ID_BUTTON
= wx
.NewId()
193 sizer
= wx
.BoxSizer()
194 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(80,-1))
195 sizer
.Add(self
.text
, 0, wx
.ALIGN_CENTER_VERTICAL | wx
.TOP | wx
.BOTTOM
, 2)
196 self
.button
= wx
.Panel(self
, self
.ID_BUTTON
, wx
.DefaultPosition
, wx
.Size(20, 20))
197 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL | wx
.LEFT
, 5)
199 self
.textModified
= False
200 wx
.EVT_PAINT(self
.button
, self
.OnPaintButton
)
201 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
202 wx
.EVT_LEFT_DOWN(self
.button
, self
.OnLeftDown
)
204 return self
.text
.GetValue()
205 def SetValue(self
, value
):
207 if not value
: value
= '#FFFFFF'
208 self
.text
.SetValue(str(value
)) # update text ctrl
210 colour
= wx
.Colour(int(value
[1:3], 16), int(value
[3:5], 16), int(value
[5:7], 16))
211 self
.button
.SetBackgroundColour(colour
)
212 except: # ignore errors
214 self
.button
.Refresh()
216 def OnPaintButton(self
, evt
):
217 dc
= wx
.PaintDC(self
.button
)
218 dc
.SetBrush(wx
.TRANSPARENT_BRUSH
)
219 if self
.IsEnabled(): dc
.SetPen(wx
.BLACK_PEN
)
220 else: dc
.SetPen(wx
.GREY_PEN
)
221 size
= self
.button
.GetSize()
222 dc
.DrawRectangle(0, 0, size
.width
, size
.height
)
223 def OnLeftDown(self
, evt
):
224 data
= wx
.ColourData()
225 data
.SetColour(self
.GetValue())
226 dlg
= wx
.ColourDialog(self
, data
)
227 if dlg
.ShowModal() == wx
.ID_OK
:
228 self
.SetValue('#%02X%02X%02X' % dlg
.GetColourData().GetColour().Get())
232 ################################################################################
234 # Mapping from wx constants to XML strings
235 fontFamiliesWx2Xml
= {wx
.DEFAULT
: 'default', wx
.DECORATIVE
: 'decorative',
236 wx
.ROMAN
: 'roman', wx
.SCRIPT
: 'script', wx
.SWISS
: 'swiss',
238 fontStylesWx2Xml
= {wx.NORMAL: 'normal', wx.SLANT: 'slant', wx.ITALIC: 'italic'}
239 fontWeightsWx2Xml
= {wx.NORMAL: 'normal', wx.LIGHT: 'light', wx.BOLD: 'bold'}
242 for k
,v
in m
.items(): rm
[v
] = k
244 fontFamiliesXml2wx
= ReverseMap(fontFamiliesWx2Xml
)
245 fontStylesXml2wx
= ReverseMap(fontStylesWx2Xml
)
246 fontWeightsXml2wx
= ReverseMap(fontWeightsWx2Xml
)
248 class ParamFont(PPanel
):
249 def __init__(self
, parent
, name
):
250 PPanel
.__init
__(self
, parent
, name
)
251 self
.ID_TEXT_CTRL
= wx
.NewId()
252 self
.ID_BUTTON_SELECT
= wx
.NewId()
253 sizer
= wx
.BoxSizer()
254 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(200,-1))
255 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
256 self
.button
= wx
.Button(self
, self
.ID_BUTTON_SELECT
, 'Select...', size
=buttonSize
)
257 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
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
351 wx
.EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
353 return str(self
.spin
.GetValue())
354 def SetValue(self
, value
):
356 if not value
: value
= 0
357 self
.spin
.SetValue(int(value
))
360 # Non-negative number
361 class ParamIntNN(PPanel
):
362 def __init__(self
, parent
, name
):
363 PPanel
.__init
__(self
, parent
, name
)
364 self
.ID_SPIN_CTRL
= wx
.NewId()
365 sizer
= wx
.BoxSizer()
366 self
.spin
= wx
.SpinCtrl(self
, self
.ID_SPIN_CTRL
, size
=(60,-1))
367 self
.spin
.SetRange(0, 10000) # min/max integers
370 wx
.EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
372 return str(self
.spin
.GetValue())
373 def SetValue(self
, value
):
375 if not value
: value
= 0
376 self
.spin
.SetValue(int(value
))
379 # Same as int but allows dialog units (XXXd)
380 class ParamUnit(PPanel
):
381 def __init__(self
, parent
, name
):
382 PPanel
.__init
__(self
, parent
, name
)
383 self
.ID_TEXT_CTRL
= wx
.NewId()
384 self
.ID_SPIN_BUTTON
= wx
.NewId()
385 sizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
386 self
.spin
= wx
.SpinButton(self
, self
.ID_SPIN_BUTTON
, style
= wx
.SP_VERTICAL
, size
=(-1,0))
387 textW
= 60 - self
.spin
.GetSize()[0]
388 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(textW
,-1))
389 self
.spin
.SetRange(-10000, 10000)
390 sizer
.Add(self
.text
, 0, wx
.EXPAND
)
391 sizer
.Add(self
.spin
, 0, wx
.EXPAND
)
393 self
.spin
.Bind(wx
.EVT_SPIN_UP
, self
.OnSpinUp
)
394 self
.spin
.Bind(wx
.EVT_SPIN_DOWN
, self
.OnSpinDown
)
395 self
.text
.Bind(wx
.EVT_TEXT
, self
.OnChange
)
398 return self
.text
.GetValue()
399 def SetValue(self
, value
):
400 if not value
: value
= '0'
401 self
.text
.SetValue(value
)
405 # Check if we are working with dialog units
406 value
= self
.text
.GetValue()
408 if value
[-1].upper() == 'D':
412 intValue
= int(value
) + x
413 self
.spin
.SetValue(intValue
)
414 if x
: # 0 can be passed to update spin value only
415 self
.text
.SetValue(str(intValue
) + units
)
418 # !!! Strange, if I use wx.LogWarning, event is re-generated
419 print 'ERROR: incorrect unit format'
421 def OnSpinUp(self
, evt
):
424 def OnSpinDown(self
, evt
):
425 if self
.freeze
: return
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
.SetSizerAndFit(sizer
)
440 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
441 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
443 return self
.text
.GetValue()
444 def SetValue(self
, value
):
445 self
.freeze
= True # disable other handlers
446 self
.text
.SetValue(value
)
447 self
.freeze
= False # disable other handlers
448 def OnButtonEdit(self
, evt
):
449 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_TEXT')
450 textCtrl
= xrc
.XRCCTRL(dlg
, 'TEXT')
451 textCtrl
.SetValue(self
.text
.GetValue())
452 if dlg
.ShowModal() == wx
.ID_OK
:
453 self
.text
.SetValue(textCtrl
.GetValue())
457 class ParamText(PPanel
):
458 def __init__(self
, parent
, name
, textWidth
=-1, style
=0):
459 PPanel
.__init
__(self
, parent
, name
)
460 self
.ID_TEXT_CTRL
= wx
.NewId()
461 # We use sizer even here to have the same size of text control
462 sizer
= wx
.BoxSizer()
463 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(textWidth
,-1), style
=style
)
464 if textWidth
== -1: option
= 1
466 sizer
.Add(self
.text
, option
, wx
.ALIGN_CENTER_VERTICAL | wx
.TOP | wx
.BOTTOM
, 2)
468 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
470 return self
.text
.GetValue()
471 def SetValue(self
, value
):
472 self
.freeze
= True # disable other handlers
473 self
.text
.SetValue(value
)
474 self
.freeze
= False # disable other handlers
476 class ParamAccel(ParamText
):
477 def __init__(self
, parent
, name
):
478 ParamText
.__init
__(self
, parent
, name
, 100)
480 class ParamPosSize(ParamText
):
481 def __init__(self
, parent
, name
):
482 ParamText
.__init
__(self
, parent
, name
, 80)
484 class ParamLabel(ParamText
):
485 def __init__(self
, parent
, name
):
486 ParamText
.__init
__(self
, parent
, name
, 200)
488 class ParamEncoding(ParamText
):
489 def __init__(self
, parent
, name
):
490 ParamText
.__init
__(self
, parent
, name
, 100)
492 class ParamComment(ParamText
):
493 def __init__(self
, parent
, name
):
494 ParamText
.__init
__(self
, parent
, name
, 330 + buttonSize
[0],
495 style
=wx
.TE_PROCESS_ENTER
)
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
)
616 self
.textModified
= False
617 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
618 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
619 def OnChange(self
, evt
):
620 PPanel
.OnChange(self
, evt
)
621 self
.textModified
= True
623 if self
.textModified
: # text has newer value
625 return self
.text
.GetValue().split('|')
629 def SetValue(self
, value
):
631 if not value
: value
= []
633 repr_
= '|'.join(map(str, value
))
634 self
.text
.SetValue(repr_
) # update text ctrl
636 def OnButtonEdit(self
, evt
):
637 if self
.textModified
: # text has newer value
638 self
.value
= self
.GetValue()
639 dlg
= ContentDialog(self
, self
.value
)
640 if dlg
.ShowModal() == wx
.ID_OK
:
642 for i
in range(dlg
.list.GetCount()):
643 value
.append(dlg
.list.GetString(i
))
646 self
.textModified
= False
648 def SetModified(self
, state
=True):
649 PPanel
.SetModified(self
, state
)
650 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('|'))
733 dlg
= IntListDialog(self
, self
.value
)
734 if dlg
.ShowModal() == wx
.ID_OK
:
736 for i
in range(dlg
.list.GetCount()):
737 value
.append(int(dlg
.list.GetString(i
)))
740 self
.textModified
= False
744 class RadioBox(PPanel
):
745 def __init__(self
, parent
, id, choices
,
746 pos
=wx
.DefaultPosition
, name
='radiobox'):
747 PPanel
.__init
__(self
, parent
, name
)
748 self
.choices
= choices
749 topSizer
= wx
.BoxSizer()
751 button
= wx
.RadioButton(self
, -1, i
, size
=(-1,buttonSize
[1]), name
=i
)
752 topSizer
.Add(button
, 0, wx
.RIGHT
, 5)
753 wx
.EVT_RADIOBUTTON(self
, button
.GetId(), self
.OnRadioChoice
)
754 self
.SetSizer(topSizer
)
755 def SetStringSelection(self
, value
):
757 for i
in self
.choices
:
758 self
.FindWindowByName(i
).SetValue(i
== value
)
761 def OnRadioChoice(self
, evt
):
762 if self
.freeze
: return
763 if evt
.GetSelection():
764 self
.value
= evt
.GetEventObject().GetName()
766 def GetStringSelection(self
):
769 class ParamBool(RadioBox
):
770 values
= {'yes': '1', 'no': '0'}
771 seulav
= {'1': 'yes', '0': 'no'}
772 def __init__(self
, parent
, name
):
773 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
775 return self
.values
[self
.GetStringSelection()]
776 def SetValue(self
, value
):
777 if not value
: value
= '1'
778 self
.SetStringSelection(self
.seulav
[value
])
780 class ParamOrient(RadioBox
):
781 values
= {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'}
782 seulav
= {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'}
783 def __init__(self
, parent
, name
):
784 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
786 return self
.values
[self
.GetStringSelection()]
787 def SetValue(self
, value
):
788 if not value
: value
= 'wxHORIZONTAL'
789 self
.SetStringSelection(self
.seulav
[value
])
791 class ParamOrientation(RadioBox
):
792 values
= {'horizontal': 'horizontal', 'vertical': 'vertical'}
793 seulav
= {'horizontal': 'horizontal', 'vertical': 'vertical'}
794 def __init__(self
, parent
, name
):
795 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
797 return self
.values
[self
.GetStringSelection()]
798 def SetValue(self
, value
):
799 if not value
: value
= 'vertical'
800 self
.SetStringSelection(self
.seulav
[value
])
802 class ParamFile(PPanel
):
803 def __init__(self
, parent
, name
):
804 PPanel
.__init
__(self
, parent
, name
)
805 self
.ID_TEXT_CTRL
= wx
.NewId()
806 self
.ID_BUTTON_BROWSE
= wx
.NewId()
807 sizer
= wx
.BoxSizer()
808 self
.text
= wx
.TextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wx
.Size(200,-1))
809 sizer
.Add(self
.text
, 0, wx
.RIGHT | wx
.ALIGN_CENTER_VERTICAL
, 5)
810 self
.button
= wx
.Button(self
, self
.ID_BUTTON_BROWSE
, 'Browse...',size
=buttonSize
)
811 sizer
.Add(self
.button
, 0, wx
.ALIGN_CENTER_VERTICAL
)
813 self
.textModified
= False
814 wx
.EVT_BUTTON(self
, self
.ID_BUTTON_BROWSE
, self
.OnButtonBrowse
)
815 wx
.EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
816 def OnChange(self
, evt
):
817 PPanel
.OnChange(self
, evt
)
818 self
.textModified
= True
820 if self
.textModified
: # text has newer value
821 return self
.text
.GetValue()
823 def SetValue(self
, value
):
826 self
.text
.SetValue(value
) # update text ctrl
828 def OnButtonBrowse(self
, evt
):
829 if self
.textModified
: # text has newer value
830 self
.value
= self
.text
.GetValue()
831 dlg
= wx
.FileDialog(self
,
832 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
)),
833 defaultFile
= os
.path
.basename(self
.value
))
834 if dlg
.ShowModal() == wx
.ID_OK
:
835 # Get common part of selected path and current
837 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
839 curpath
= os
.path
.join(os
.getcwd(), '')
840 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
841 self
.SetValue(dlg
.GetPath()[len(common
):])
843 self
.textModified
= False
846 class ParamBitmap(PPanel
):
847 def __init__(self
, parent
, name
):
849 g
.frame
.res
.LoadOnPanel(pre
, parent
, 'PANEL_BITMAP')
851 self
.modified
= self
.freeze
= False
852 self
.radio_std
= xrc
.XRCCTRL(self
, 'RADIO_STD')
853 self
.radio_file
= xrc
.XRCCTRL(self
, 'RADIO_FILE')
854 self
.combo
= xrc
.XRCCTRL(self
, 'COMBO_STD')
855 self
.text
= xrc
.XRCCTRL(self
, 'TEXT_FILE')
856 self
.button
= xrc
.XRCCTRL(self
, 'BUTTON_BROWSE')
857 self
.textModified
= False
858 self
.SetAutoLayout(True)
859 self
.GetSizer().SetMinSize((260, -1))
860 self
.GetSizer().Fit(self
)
861 wx
.EVT_RADIOBUTTON(self
, xrc
.XRCID('RADIO_STD'), self
.OnRadioStd
)
862 wx
.EVT_RADIOBUTTON(self
, xrc
.XRCID('RADIO_FILE'), self
.OnRadioFile
)
863 wx
.EVT_BUTTON(self
, xrc
.XRCID('BUTTON_BROWSE'), self
.OnButtonBrowse
)
864 wx
.EVT_COMBOBOX(self
, xrc
.XRCID('COMBO_STD'), self
.OnCombo
)
865 wx
.EVT_TEXT(self
, xrc
.XRCID('COMBO_STD'), self
.OnChange
)
866 wx
.EVT_TEXT(self
, xrc
.XRCID('TEXT_FILE'), self
.OnChange
)
867 def OnRadioStd(self
, evt
):
869 self
.SetValue(['wxART_MISSING_IMAGE',''])
870 def OnRadioFile(self
, evt
):
872 self
.SetValue(['',''])
873 def updateRadios(self
):
875 self
.radio_std
.SetValue(True)
876 self
.radio_file
.SetValue(False)
877 self
.text
.Enable(False)
878 self
.button
.Enable(False)
879 self
.combo
.Enable(True)
881 self
.radio_std
.SetValue(False)
882 self
.radio_file
.SetValue(True)
883 self
.text
.Enable(True)
884 self
.button
.Enable(True)
885 self
.combo
.Enable(False)
886 def OnChange(self
, evt
):
887 PPanel
.OnChange(self
, evt
)
888 self
.textModified
= True
889 def OnCombo(self
, evt
):
890 PPanel
.OnChange(self
, evt
)
891 self
.value
[0] = self
.combo
.GetValue()
893 if self
.textModified
: # text has newer value
894 return [self
.combo
.GetValue(), self
.text
.GetValue()]
896 def SetValue(self
, value
):
899 self
.value
= ['', '']
902 self
.combo
.SetValue(self
.value
[0])
903 self
.text
.SetValue(self
.value
[1]) # update text ctrl
906 def OnButtonBrowse(self
, evt
):
907 if self
.textModified
: # text has newer value
908 self
.value
[1] = self
.text
.GetValue()
909 dlg
= wx
.FileDialog(self
,
910 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
[1])),
911 defaultFile
= os
.path
.basename(self
.value
[1]))
912 if dlg
.ShowModal() == wx
.ID_OK
:
913 # Get common part of selected path and current
915 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
917 curpath
= os
.path
.join(os
.getcwd(), '')
918 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
919 self
.SetValue(['', dlg
.GetPath()[len(common
):]])
921 self
.textModified
= False
926 'style': ParamStyle
, 'exstyle': ParamExStyle
,
927 'pos': ParamPosSize
, 'size': ParamPosSize
,
928 'cellpos': ParamPosSize
, 'cellspan': ParamPosSize
,
929 'border': ParamUnit
, 'cols': ParamIntNN
, 'rows': ParamIntNN
,
930 'vgap': ParamUnit
, 'hgap': ParamUnit
,
931 'checkable': ParamBool
, 'checked': ParamBool
, 'radio': ParamBool
,
933 'label': ParamMultilineText
, 'title': ParamText
, 'value': ParamText
,
934 'content': ParamContent
, 'selection': ParamIntNN
,
935 'min': ParamInt
, 'max': ParamInt
,
936 'fg': ParamColour
, 'bg': ParamColour
, 'font': ParamFont
,
937 'enabled': ParamBool
, 'focused': ParamBool
, 'hidden': ParamBool
,
938 'tooltip': ParamText
, 'bitmap': ParamBitmap
, 'icon': ParamBitmap
,
939 'encoding': ParamEncoding
, 'borders': ParamUnit
,
940 'comment': ParamComment