2 # Purpose: Classes for parameter introduction
3 # Author: Roman Rolinsky <rolinsky@mema.ucl.ac.be>
11 from wxPython
.xrc
import *
13 genericStyles
= ['wxSIMPLE_BORDER', 'wxDOUBLE_BORDER',
14 'wxSUNKEN_BORDER', 'wxRAISED_BORDER',
15 'wxSTATIC_BORDER', 'wxNO_BORDER',
16 'wxTRANSPARENT_WINDOW', 'wxWANTS_CHARS',
17 'wxNO_FULL_REPAINT_ON_RESIZE']
19 buttonSize
= (35,-1) # in dialog units, transformed to pixels in panel ctor
21 # Class that can properly disable children
22 class PPanel(wxPanel
):
23 def __init__(self
, parent
, name
):
24 wxPanel
.__init
__(self
, parent
, -1, name
=name
)
25 self
.modified
= self
.freeze
= False
26 def Enable(self
, value
):
27 # Something strange is going on with enable so we make sure...
28 for w
in self
.GetChildren():
30 wxPanel
.Enable(self
, value
)
31 def SetModified(self
):
33 g
.panel
.SetModified(True)
34 # Common method to set modified state
35 def OnChange(self
, evt
):
36 if self
.freeze
: return
40 class ParamBinaryOr(PPanel
):
41 def __init__(self
, parent
, name
):
42 PPanel
.__init
__(self
, parent
, name
)
43 self
.ID_TEXT_CTRL
= wxNewId()
44 self
.ID_BUTTON_CHOICES
= wxNewId()
45 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
47 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(200,-1))
48 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
49 self
.button
= wxButton(self
, self
.ID_BUTTON_CHOICES
, 'Edit...', size
=buttonSize
)
50 sizer
.Add(self
.button
, 0, wxALIGN_CENTER_VERTICAL
)
51 self
.SetAutoLayout(True)
54 EVT_BUTTON(self
, self
.ID_BUTTON_CHOICES
, self
.OnButtonChoices
)
55 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
57 return self
.text
.GetValue()
58 def SetValue(self
, value
):
60 self
.text
.SetValue(value
)
62 def OnButtonChoices(self
, evt
):
63 dlg
= wxDialog(self
, -1, 'Choices')
64 topSizer
= wxBoxSizer(wxVERTICAL
)
65 listBox
= wxCheckListBox(dlg
, -1, choices
=self
.values
, size
=(250,200))
66 value
= map(string
.strip
, self
.text
.GetValue().split('|'))
67 if value
== ['']: value
= []
71 listBox
.Check(self
.values
.index(i
))
74 if self
.equal
.has_key(i
):
75 listBox
.Check(self
.values
.index(self
.equal
[i
]))
77 print 'WARNING: unknown flag: %s: ignored.' % i
79 topSizer
.Add(listBox
, 1, wxEXPAND
)
81 buttonOk
= wxButton(dlg
, wxID_OK
, 'OK')
83 sizer
.Add(buttonOk
, 0, wxRIGHT
, 10)
85 sizer
.Add(wxButton(dlg
, wxID_CANCEL
, 'Cancel'))
86 topSizer
.Add(sizer
, 0, wxALL | wxEXPAND
, 10)
87 dlg
.SetAutoLayout(True)
88 dlg
.SetSizer(topSizer
)
91 if dlg
.ShowModal() == wxID_OK
:
93 for i
in range(listBox
.GetCount()):
94 if listBox
.IsChecked(i
):
95 value
.append(self
.values
[i
])
99 self
.SetValue(reduce(lambda a
,b
: a
+'|'+b
, value
))
105 class ParamFlag(ParamBinaryOr
):
106 values
= ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL',
107 'wxEXPAND', 'wxGROW', 'wxSHAPED', 'wxALIGN_CENTRE', 'wxALIGN_RIGHT',
108 'wxALIGN_BOTTOM', 'wxALIGN_CENTRE_VERTICAL',
109 'wxALIGN_CENTRE_HORIZONTAL']
110 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE',
111 'wxALIGN_CENTER_VERTICAL': 'wxALIGN_CENTRE_VERTICAL',
112 'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL'}
113 def __init__(self
, parent
, name
):
114 ParamBinaryOr
.__init
__(self
, parent
, name
)
116 class ParamStyle(ParamBinaryOr
):
117 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE'}
118 def __init__(self
, parent
, name
):
119 self
.values
= g
.currentXXX
.winStyles
+ genericStyles
120 ParamBinaryOr
.__init
__(self
, parent
, name
)
122 class ParamNonGenericStyle(ParamBinaryOr
):
123 def __init__(self
, parent
, name
):
124 self
.values
= g
.currentXXX
.winStyles
125 ParamBinaryOr
.__init
__(self
, parent
, name
)
127 class ParamExStyle(ParamBinaryOr
):
128 def __init__(self
, parent
, name
):
130 self
.values
= g
.currentXXX
.exStyles
# constant at the moment
133 ParamBinaryOr
.__init
__(self
, parent
, name
)
135 class ParamColour(PPanel
):
136 def __init__(self
, parent
, name
):
137 PPanel
.__init
__(self
, parent
, name
)
138 self
.ID_TEXT_CTRL
= wxNewId()
139 self
.ID_BUTTON
= wxNewId()
140 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
142 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(65,-1))
143 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
144 self
.button
= wxPanel(self
, self
.ID_BUTTON
, wxDefaultPosition
, wxSize(20, 1))
145 sizer
.Add(self
.button
, 0, wxGROW | wxALIGN_CENTER_VERTICAL
)
146 self
.SetAutoLayout(True)
149 self
.textModified
= False
150 EVT_PAINT(self
.button
, self
.OnPaintButton
)
151 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
152 EVT_LEFT_DOWN(self
.button
, self
.OnLeftDown
)
154 return self
.text
.GetValue()
155 def SetValue(self
, value
):
157 if not value
: value
= '#FFFFFF'
158 self
.text
.SetValue(str(value
)) # update text ctrl
159 colour
= wxColour(int(value
[1:3], 16), int(value
[3:5], 16), int(value
[5:7], 16))
160 self
.button
.SetBackgroundColour(colour
)
161 self
.button
.Refresh()
163 def OnPaintButton(self
, evt
):
164 dc
= wxPaintDC(self
.button
)
165 dc
.SetBrush(wxTRANSPARENT_BRUSH
)
166 if self
.IsEnabled(): dc
.SetPen(wxBLACK_PEN
)
167 else: dc
.SetPen(wxGREY_PEN
)
168 size
= self
.button
.GetSize()
169 dc
.DrawRectangle((0, 0), size
)
170 def OnLeftDown(self
, evt
):
171 data
= wxColourData()
172 data
.SetColour(self
.GetValue())
173 dlg
= wxColourDialog(self
, data
)
174 if dlg
.ShowModal() == wxID_OK
:
175 self
.SetValue('#%02X%02X%02X' % dlg
.GetColourData().GetColour().Get())
179 ################################################################################
181 # Mapping from wx constants ro XML strings
182 fontFamiliesWx2Xml
= {wxDEFAULT
: 'default', wxDECORATIVE
: 'decorative',
183 wxROMAN
: 'roman', wxSCRIPT
: 'script', wxSWISS
: 'swiss',
185 fontStylesWx2Xml
= {wxNORMAL: 'normal', wxSLANT: 'slant', wxITALIC: 'italic'}
186 fontWeightsWx2Xml
= {wxNORMAL: 'normal', wxLIGHT: 'light', wxBOLD: 'bold'}
189 for k
,v
in m
.items(): rm
[v
] = k
191 fontFamiliesXml2wx
= ReverseMap(fontFamiliesWx2Xml
)
192 fontStylesXml2wx
= ReverseMap(fontStylesWx2Xml
)
193 fontWeightsXml2wx
= ReverseMap(fontWeightsWx2Xml
)
195 class ParamFont(PPanel
):
196 def __init__(self
, parent
, name
):
197 PPanel
.__init
__(self
, parent
, name
)
198 self
.ID_TEXT_CTRL
= wxNewId()
199 self
.ID_BUTTON_SELECT
= wxNewId()
200 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
202 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(200,-1))
203 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
204 self
.button
= wxButton(self
, self
.ID_BUTTON_SELECT
, 'Select...', size
=buttonSize
)
205 sizer
.Add(self
.button
, 0, wxALIGN_CENTER_VERTICAL
)
206 self
.SetAutoLayout(True)
209 self
.textModified
= False
210 EVT_BUTTON(self
, self
.ID_BUTTON_SELECT
, self
.OnButtonSelect
)
211 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
212 def OnChange(self
, evt
):
213 PPanel
.OnChange(self
, evt
)
214 self
.textModified
= True
215 def _defaultValue(self
):
216 return ['12', 'default', 'normal', 'normal', '0', '', '']
218 if self
.textModified
: # text has newer value
220 return eval(self
.text
.GetValue())
222 wxLogError('Syntax error in parameter value: ' + self
.GetName())
223 return self
._defaultValue
()
225 def SetValue(self
, value
):
226 self
.freeze
= True # disable other handlers
227 if not value
: value
= self
._defaultValue
()
229 self
.text
.SetValue(str(value
)) # update text ctrl
231 def OnButtonSelect(self
, evt
):
232 if self
.textModified
: # text has newer value
234 self
.value
= eval(self
.text
.GetValue())
236 wxLogError('Syntax error in parameter value: ' + self
.GetName())
237 self
.value
= self
._defaultValue
()
242 style
= weight
= wxNORMAL
245 enc
= wxFONTENCODING_DEFAULT
246 # Fall back to default if exceptions
249 try: size
= int(self
.value
[0])
250 except ValueError: error
= True
251 try: family
= fontFamiliesXml2wx
[self
.value
[1]]
252 except KeyError: error
= True
253 try: style
= fontStylesXml2wx
[self
.value
[2]]
254 except KeyError: error
= True
255 try: weight
= fontWeightsXml2wx
[self
.value
[3]]
256 except KeyError: error
= True
257 try: underlined
= int(self
.value
[4])
258 except ValueError: error
= True
260 mapper
= wxFontMapper()
261 if not self
.value
[6]: enc
= mapper
.CharsetToEncoding(self
.value
[6])
264 if error
: wxLogError('Invalid font specification')
265 if enc
== wxFONTENCODING_DEFAULT
: enc
= wxFONTENCODING_SYSTEM
266 font
= wxFont(size
, family
, style
, weight
, underlined
, face
, enc
)
268 data
.SetInitialFont(font
)
269 dlg
= wxFontDialog(self
, data
)
270 if dlg
.ShowModal() == wxID_OK
:
271 font
= dlg
.GetFontData().GetChosenFont()
272 value
= [str(font
.GetPointSize()),
273 fontFamiliesWx2Xml
.get(font
.GetFamily(), "default"),
274 fontStylesWx2Xml
.get(font
.GetStyle(), "normal"),
275 fontWeightsWx2Xml
.get(font
.GetWeight(), "normal"),
276 str(font
.GetUnderlined()),
277 font
.GetFaceName().encode(),
278 wxFontMapper_GetEncodingName(font
.GetEncoding()).encode()
283 self
.textModified
= False
286 ################################################################################
288 class ParamInt(PPanel
):
289 def __init__(self
, parent
, name
):
290 PPanel
.__init
__(self
, parent
, name
)
291 self
.ID_SPIN_CTRL
= wxNewId()
293 self
.spin
= wxSpinCtrl(self
, self
.ID_SPIN_CTRL
, size
=(50,-1))
294 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
296 self
.SetAutoLayout(True)
299 EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
301 return str(self
.spin
.GetValue())
302 def SetValue(self
, value
):
304 if not value
: value
= 0
305 self
.spin
.SetValue(int(value
))
308 # Same as int but allows dialog units (XXXd)
309 class ParamUnit(PPanel
):
310 def __init__(self
, parent
, name
):
311 PPanel
.__init
__(self
, parent
, name
)
312 self
.ID_TEXT_CTRL
= wxNewId()
313 self
.ID_SPIN_BUTTON
= wxNewId()
315 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(35,-1))
316 self
.spin
= wxSpinButton(self
, self
.ID_SPIN_BUTTON
, style
= wxSP_VERTICAL
, size
=(-1,1))
317 self
.spin
.SetRange(-10000, 10000)
318 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
319 sizer
.Add(self
.text
, 0, wxEXPAND | wxRIGHT
, 2)
320 sizer
.Add(self
.spin
, 0, wxEXPAND
)
321 self
.SetAutoLayout(True)
324 EVT_SPIN_UP(self
, self
.ID_SPIN_BUTTON
, self
.OnSpinUp
)
325 EVT_SPIN_DOWN(self
, self
.ID_SPIN_BUTTON
, self
.OnSpinDown
)
327 return self
.text
.GetValue()
328 def SetValue(self
, value
):
330 if not value
: value
= '0'
331 self
.text
.SetValue(value
)
334 # Check if we are working with dialog units
335 value
= self
.text
.GetValue()
337 if value
[-1].upper() == 'D':
341 intValue
= int(value
) + x
342 self
.spin
.SetValue(intValue
)
343 self
.text
.SetValue(str(intValue
) + units
)
346 # !!! Strange, if I use wxLogWarning, event is re-generated
347 print 'incorrect unit format'
348 def OnSpinUp(self
, evt
):
350 def OnSpinDown(self
, evt
):
353 # Dialog for editing multi-line text
354 class TextDialog(wxDialog
):
355 def __init__(self
, parent
, value
):
357 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_TEXT')
359 self
._setOORInfo
(self
)
360 self
.text
= self
.FindWindowByName('TEXT')
361 self
.text
.SetValue(value
)
362 self
.SetAutoLayout(True)
363 self
.SetSize((300,200))
365 return self
.text
.GetValue()
367 class ParamMultilineText(PPanel
):
368 def __init__(self
, parent
, name
, textWidth
=-1):
369 PPanel
.__init
__(self
, parent
, name
)
370 self
.ID_TEXT_CTRL
= wxNewId()
371 self
.ID_BUTTON_EDIT
= wxNewId()
372 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
374 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
375 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(200,-1))
376 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
377 self
.button
= wxButton(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
378 sizer
.Add(self
.button
, 0, wxALIGN_CENTER_VERTICAL
)
379 self
.SetAutoLayout(True)
382 EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
383 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
385 return self
.text
.GetValue()
386 def SetValue(self
, value
):
387 self
.freeze
= True # disable other handlers
388 self
.text
.SetValue(value
)
389 self
.freeze
= False # disable other handlers
390 def OnButtonEdit(self
, evt
):
391 dlg
= TextDialog(self
, self
.text
.GetValue())
392 if dlg
.ShowModal() == wxID_OK
:
393 self
.text
.SetValue(dlg
.GetValue())
397 class ParamText(PPanel
):
398 def __init__(self
, parent
, name
, textWidth
=-1):
399 PPanel
.__init
__(self
, parent
, name
)
400 self
.ID_TEXT_CTRL
= wxNewId()
401 # We use sizer even here to have the same size of text control
403 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
404 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(textWidth
,-1))
405 if textWidth
== -1: option
= 1
407 sizer
.Add(self
.text
, option
, wxALIGN_CENTER_VERTICAL
)
408 self
.SetAutoLayout(True)
411 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
413 return self
.text
.GetValue()
414 def SetValue(self
, value
):
415 self
.freeze
= True # disable other handlers
416 self
.text
.SetValue(value
)
417 self
.freeze
= False # disable other handlers
419 class ParamAccel(ParamText
):
420 def __init__(self
, parent
, name
):
421 ParamText
.__init
__(self
, parent
, name
, 100)
423 class ParamPosSize(ParamText
):
424 def __init__(self
, parent
, name
):
425 ParamText
.__init
__(self
, parent
, name
, 80)
427 class ParamLabel(ParamText
):
428 def __init__(self
, parent
, name
):
429 ParamText
.__init
__(self
, parent
, name
, 200)
431 class ParamEncoding(ParamText
):
432 def __init__(self
, parent
, name
):
433 ParamText
.__init
__(self
, parent
, name
, 100)
435 class ContentDialog(wxDialog
):
436 def __init__(self
, parent
, value
):
439 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT')
441 self
._setOORInfo
(self
)
442 self
.list = self
.FindWindowByName('LIST')
446 self
.SetAutoLayout(True)
447 self
.GetSizer().Fit(self
)
449 self
.ID_BUTTON_APPEND
= XRCID('BUTTON_APPEND')
450 self
.ID_BUTTON_REMOVE
= XRCID('BUTTON_REMOVE')
451 self
.ID_BUTTON_UP
= XRCID('BUTTON_UP')
452 self
.ID_BUTTON_DOWN
= XRCID('BUTTON_DOWN')
453 EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
454 EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
455 EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
456 EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
457 EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
458 EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
459 EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
460 def OnButtonUp(self
, evt
):
461 i
= self
.list.GetSelection()
462 str = self
.list.GetString(i
)
464 self
.list.InsertItems([str], i
-1)
465 self
.list.SetSelection(i
-1)
466 def OnButtonDown(self
, evt
):
467 i
= self
.list.GetSelection()
468 str = self
.list.GetString(i
)
470 self
.list.InsertItems([str], i
+1)
471 self
.list.SetSelection(i
+1)
472 def OnButtonAppend(self
, evt
):
473 str = wxGetTextFromUser('Enter new item:', 'Append', '', self
)
474 self
.list.Append(str)
475 def OnButtonRemove(self
, evt
):
476 self
.list.Delete(self
.list.GetSelection())
477 def OnUpdateUI(self
, evt
):
478 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
479 evt
.Enable(self
.list.GetSelection() != -1)
480 elif evt
.GetId() == self
.ID_BUTTON_UP
:
481 evt
.Enable(self
.list.GetSelection() > 0)
482 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
483 evt
.Enable(self
.list.GetSelection() != -1 and \
484 self
.list.GetSelection() < self
.list.GetCount() - 1)
486 class ContentCheckListDialog(wxDialog
):
487 def __init__(self
, parent
, value
):
489 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT_CHECK_LIST')
491 self
._setOORInfo
(self
)
492 self
.list = self
.FindWindowByName('CHECK_LIST')
497 self
.list.Check(i
, ch
)
499 self
.SetAutoLayout(True)
500 self
.GetSizer().Fit(self
)
502 self
.ID_BUTTON_APPEND
= XRCID('BUTTON_APPEND')
503 self
.ID_BUTTON_REMOVE
= XRCID('BUTTON_REMOVE')
504 self
.ID_BUTTON_UP
= XRCID('BUTTON_UP')
505 self
.ID_BUTTON_DOWN
= XRCID('BUTTON_DOWN')
506 EVT_CHECKLISTBOX(self
, self
.list.GetId(), self
.OnCheck
)
507 EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
508 EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
509 EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
510 EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
511 EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
512 EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
513 EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
514 def OnCheck(self
, evt
):
515 # !!! Wrong wxGTK (wxMSW?) behavior: toggling selection if checking
516 self
.list.Deselect(evt
.GetSelection())
517 def OnButtonUp(self
, evt
):
518 i
= self
.list.GetSelection()
519 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
521 self
.list.InsertItems([str], i
-1)
522 self
.list.Check(i
-1, ch
)
523 self
.list.SetSelection(i
-1)
524 def OnButtonDown(self
, evt
):
525 i
= self
.list.GetSelection()
526 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
528 self
.list.InsertItems([str], i
+1)
529 self
.list.Check(i
+1, ch
)
530 self
.list.SetSelection(i
+1)
531 def OnButtonAppend(self
, evt
):
532 str = wxGetTextFromUser('Enter new item:', 'Append', '', self
)
533 self
.list.Append(str)
534 def OnButtonRemove(self
, evt
):
535 self
.list.Delete(self
.list.GetSelection())
536 def OnUpdateUI(self
, evt
):
537 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
538 evt
.Enable(self
.list.GetSelection() != -1)
539 elif evt
.GetId() == self
.ID_BUTTON_UP
:
540 evt
.Enable(self
.list.GetSelection() > 0)
541 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
542 evt
.Enable(self
.list.GetSelection() != -1 and \
543 self
.list.GetSelection() < self
.list.GetCount() - 1)
545 class ParamContent(PPanel
):
546 def __init__(self
, parent
, name
):
547 PPanel
.__init
__(self
, parent
, name
)
548 self
.ID_TEXT_CTRL
= wxNewId()
549 self
.ID_BUTTON_EDIT
= wxNewId()
550 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
552 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(200,-1))
553 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
554 self
.button
= wxButton(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
555 sizer
.Add(self
.button
, 0, wxALIGN_CENTER_VERTICAL
)
556 self
.SetAutoLayout(True)
559 self
.textModified
= False
560 EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
561 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
562 def OnChange(self
, evt
):
563 PPanel
.OnChange(self
, evt
)
564 self
.textModified
= True
566 if self
.textModified
: # text has newer value
568 return eval(self
.text
.GetValue())
570 wxLogError('Syntax error in parameter value: ' + self
.GetName())
573 def SetValue(self
, value
):
575 if not value
: value
= []
577 self
.text
.SetValue(str(value
)) # update text ctrl
579 def OnButtonEdit(self
, evt
):
580 if self
.textModified
: # text has newer value
582 self
.value
= eval(self
.text
.GetValue())
584 wxLogError('Syntax error in parameter value: ' + self
.GetName())
586 dlg
= ContentDialog(self
, self
.value
)
587 if dlg
.ShowModal() == wxID_OK
:
589 for i
in range(dlg
.list.GetCount()):
590 value
.append(dlg
.list.GetString(i
))
594 self
.textModified
= False
598 class ParamContentCheckList(ParamContent
):
599 def __init__(self
, parent
, name
):
600 ParamContent
.__init
__(self
, parent
, name
)
601 def OnButtonEdit(self
, evt
):
602 if self
.textModified
: # text has newer value
604 self
.value
= eval(self
.text
.GetValue())
606 wxLogError('Syntax error in parameter value: ' + self
.GetName())
608 dlg
= ContentCheckListDialog(self
, self
.value
)
609 if dlg
.ShowModal() == wxID_OK
:
611 for i
in range(dlg
.list.GetCount()):
612 value
.append((dlg
.list.GetString(i
), dlg
.list.IsChecked(i
)))
616 self
.textModified
= False
619 class IntListDialog(wxDialog
):
620 def __init__(self
, parent
, value
):
622 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_INTLIST')
624 self
._setOORInfo
(self
)
625 self
.list = self
.FindWindowByName('LIST')
629 if type(v
) != IntType
:
630 wxLogError('Invalid item type')
632 self
.list.Append(str(v
))
633 self
.SetAutoLayout(True)
634 self
.GetSizer().Fit(self
)
636 self
.ID_BUTTON_ADD
= XRCID('BUTTON_ADD')
637 self
.ID_BUTTON_REMOVE
= XRCID('BUTTON_REMOVE')
638 EVT_BUTTON(self
, self
.ID_BUTTON_ADD
, self
.OnButtonAppend
)
639 EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
640 EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
641 def OnButtonAppend(self
, evt
):
642 s
= wxGetTextFromUser('Enter new number:', 'Add', '', self
)
644 # Check that it's unique
647 s
= str(v
) # to be sure
648 i
= self
.list.FindString(s
)
649 if i
== -1: # ignore non-unique
650 # Find place to insert
652 for i
in range(self
.list.GetCount()):
653 if int(self
.list.GetString(i
)) > v
:
656 if found
: self
.list.InsertItems([s
], i
)
657 else: self
.list.Append(s
)
659 wxLogError('List item is not an int!')
660 def OnButtonRemove(self
, evt
):
661 self
.list.Delete(self
.list.GetSelection())
662 def OnUpdateUI(self
, evt
):
663 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
664 evt
.Enable(self
.list.GetSelection() != -1)
667 class ParamIntList(ParamContent
):
668 def __init__(self
, parent
, name
):
669 ParamContent
.__init
__(self
, parent
, name
)
670 def OnButtonEdit(self
, evt
):
671 if self
.textModified
: # text has newer value
673 self
.value
= eval(self
.text
.GetValue())
675 wxLogError('Syntax error in parameter value: ' + self
.GetName())
677 dlg
= IntListDialog(self
, self
.value
)
678 if dlg
.ShowModal() == wxID_OK
:
680 for i
in range(dlg
.list.GetCount()):
681 value
.append(int(dlg
.list.GetString(i
)))
685 self
.textModified
= False
689 class RadioBox(PPanel
):
690 def __init__(self
, parent
, id, choices
,
691 pos
=wxDefaultPosition
, name
='radiobox'):
692 PPanel
.__init
__(self
, parent
, name
)
693 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
694 self
.choices
= choices
695 topSizer
= wxBoxSizer()
697 button
= wxRadioButton(self
, -1, i
, size
=(-1,buttonSize
[1]), name
=i
)
698 topSizer
.Add(button
, 0, wxRIGHT
, 5)
699 EVT_RADIOBUTTON(self
, button
.GetId(), self
.OnRadioChoice
)
700 self
.SetAutoLayout(True)
701 self
.SetSizer(topSizer
)
703 def SetStringSelection(self
, value
):
705 for i
in self
.choices
:
706 self
.FindWindowByName(i
).SetValue(i
== value
)
709 def OnRadioChoice(self
, evt
):
710 if self
.freeze
: return
711 if evt
.GetSelection():
712 self
.value
= evt
.GetEventObject().GetName()
714 def GetStringSelection(self
):
717 class ParamBool(RadioBox
):
718 values
= {'yes': '1', 'no': '0'}
719 seulav
= {'1': 'yes', '0': 'no'}
720 def __init__(self
, parent
, name
):
721 RadioBox
.__init
__(self
, parent
, -1, choices
= self
.values
.keys(), name
=name
)
723 return self
.values
[self
.GetStringSelection()]
724 def SetValue(self
, value
):
725 if not value
: value
= '1'
726 self
.SetStringSelection(self
.seulav
[value
])
728 class ParamOrient(RadioBox
):
729 values
= {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'}
730 seulav
= {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'}
731 def __init__(self
, parent
, name
):
732 RadioBox
.__init
__(self
, parent
, -1, choices
= self
.values
.keys(), name
=name
)
734 return self
.values
[self
.GetStringSelection()]
735 def SetValue(self
, value
):
736 if not value
: value
= 'wxHORIZONTAL'
737 self
.SetStringSelection(self
.seulav
[value
])
739 class ParamFile(PPanel
):
740 def __init__(self
, parent
, name
):
741 PPanel
.__init
__(self
, parent
, name
)
742 self
.ID_TEXT_CTRL
= wxNewId()
743 self
.ID_BUTTON_BROWSE
= wxNewId()
744 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
746 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(200,-1))
747 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
748 self
.button
= wxButton(self
, self
.ID_BUTTON_BROWSE
, 'Browse...',size
=buttonSize
)
749 sizer
.Add(self
.button
, 0, wxALIGN_CENTER_VERTICAL
)
750 self
.SetAutoLayout(True)
753 self
.textModified
= False
754 EVT_BUTTON(self
, self
.ID_BUTTON_BROWSE
, self
.OnButtonBrowse
)
755 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
756 def OnChange(self
, evt
):
757 PPanel
.OnChange(self
, evt
)
758 self
.textModified
= True
760 if self
.textModified
: # text has newer value
761 return self
.text
.GetValue()
763 def SetValue(self
, value
):
766 self
.text
.SetValue(value
) # update text ctrl
768 def OnButtonBrowse(self
, evt
):
769 if self
.textModified
: # text has newer value
770 self
.value
= self
.text
.GetValue()
771 dlg
= wxFileDialog(self
,
772 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
)),
773 defaultFile
= os
.path
.basename(self
.value
))
774 if dlg
.ShowModal() == wxID_OK
:
775 # Get common part of selected path and current
777 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
779 curpath
= os
.path
.join(os
.getcwd(), '')
780 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
781 self
.SetValue(dlg
.GetPath()[len(common
):])
783 self
.textModified
= False
786 class ParamBitmap(PPanel
):
787 def __init__(self
, parent
, name
):
789 g
.frame
.res
.LoadOnPanel(pre
, parent
, 'PANEL_BITMAP')
791 self
._setOORInfo
(self
)
792 self
.modified
= self
.freeze
= False
793 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
794 self
.radio_std
= self
.FindWindowByName('RADIO_STD')
795 self
.radio_file
= self
.FindWindowByName('RADIO_FILE')
796 self
.combo
= self
.FindWindowByName('COMBO_STD')
797 self
.text
= self
.FindWindowByName('TEXT_FILE')
798 self
.button
= self
.FindWindowByName('BUTTON_BROWSE')
799 self
.textModified
= False
800 self
.SetAutoLayout(True)
801 self
.GetSizer().SetMinSize((260, -1))
802 self
.GetSizer().Fit(self
)
803 EVT_RADIOBUTTON(self
, XRCID('RADIO_STD'), self
.OnRadioStd
)
804 EVT_RADIOBUTTON(self
, XRCID('RADIO_FILE'), self
.OnRadioFile
)
805 EVT_BUTTON(self
, XRCID('BUTTON_BROWSE'), self
.OnButtonBrowse
)
806 EVT_COMBOBOX(self
, XRCID('COMBO_STD'), self
.OnCombo
)
807 EVT_TEXT(self
, XRCID('COMBO_STD'), self
.OnChange
)
808 EVT_TEXT(self
, XRCID('TEXT_FILE'), self
.OnChange
)
809 def OnRadioStd(self
, evt
):
811 self
.SetValue(['wxART_MISSING_IMAGE',''])
812 def OnRadioFile(self
, evt
):
814 self
.SetValue(['',''])
815 def updateRadios(self
):
817 self
.radio_std
.SetValue(True)
818 self
.radio_file
.SetValue(False)
819 self
.text
.Enable(False)
820 self
.button
.Enable(False)
821 self
.combo
.Enable(True)
823 self
.radio_std
.SetValue(False)
824 self
.radio_file
.SetValue(True)
825 self
.text
.Enable(True)
826 self
.button
.Enable(True)
827 self
.combo
.Enable(False)
828 def OnChange(self
, evt
):
829 PPanel
.OnChange(self
, evt
)
830 self
.textModified
= True
831 def OnCombo(self
, evt
):
832 PPanel
.OnChange(self
, evt
)
833 self
.value
[0] = self
.combo
.GetValue()
835 if self
.textModified
: # text has newer value
836 return [self
.combo
.GetValue(), self
.text
.GetValue()]
838 def SetValue(self
, value
):
841 self
.value
= ['', '']
844 self
.combo
.SetValue(self
.value
[0])
845 self
.text
.SetValue(self
.value
[1]) # update text ctrl
848 def OnButtonBrowse(self
, evt
):
849 if self
.textModified
: # text has newer value
850 self
.value
[1] = self
.text
.GetValue()
851 dlg
= wxFileDialog(self
,
852 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
[1])),
853 defaultFile
= os
.path
.basename(self
.value
[1]))
854 if dlg
.ShowModal() == wxID_OK
:
855 # Get common part of selected path and current
857 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
859 curpath
= os
.path
.join(os
.getcwd(), '')
860 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
861 self
.SetValue(['', dlg
.GetPath()[len(common
):]])
863 self
.textModified
= False
868 'style': ParamStyle
, 'exstyle': ParamExStyle
,
869 'pos': ParamPosSize
, 'size': ParamPosSize
,
870 'border': ParamUnit
, 'cols': ParamInt
, 'rows': ParamInt
,
871 'vgap': ParamUnit
, 'hgap': ParamUnit
,
872 'checkable': ParamBool
, 'checked': ParamBool
, 'radio': ParamBool
,
874 'label': ParamMultilineText
, 'title': ParamText
, 'value': ParamText
,
875 'content': ParamContent
, 'selection': ParamInt
,
876 'min': ParamInt
, 'max': ParamInt
,
877 'fg': ParamColour
, 'bg': ParamColour
, 'font': ParamFont
,
878 'enabled': ParamBool
, 'focused': ParamBool
, 'hidden': ParamBool
,
879 'tooltip': ParamText
, 'bitmap': ParamBitmap
, 'icon': ParamBitmap
,
880 'encoding': ParamEncoding