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
= (30,-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
.Number()):
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
, 5)
144 self
.button
= wxPanel(self
, self
.ID_BUTTON
, wxDefaultPosition
, wxSize(20, 20))
145 sizer
.Add(self
.button
, 0, wxGROW
)
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
.x
, size
.y
)
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
=wxSize(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()),
278 wxFontMapper_GetEncodingName(font
.GetEncoding())
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
=wxSize(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
=wxSize(35,-1))
316 self
.spin
= wxSpinButton(self
, self
.ID_SPIN_BUTTON
, style
= wxSP_VERTICAL
)
317 self
.spin
.SetRange(-10000, 10000)
318 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
319 sizer
.Add(self
.text
, 0, wxEXPAND | wxRIGHT
, 2)
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 class ParamText(PPanel
):
354 def __init__(self
, parent
, name
, textWidth
=-1):
355 PPanel
.__init
__(self
, parent
, name
)
356 self
.ID_TEXT_CTRL
= wxNewId()
357 # We use sizer even here to have the same size of text control
359 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
360 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(textWidth
,-1))
361 if textWidth
== -1: option
= 1
363 sizer
.Add(self
.text
, option
, wxALIGN_CENTER_VERTICAL
)
364 self
.SetAutoLayout(True)
367 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
369 return self
.text
.GetValue()
370 def SetValue(self
, value
):
371 self
.freeze
= True # disable other handlers
372 self
.text
.SetValue(value
)
373 self
.freeze
= False # disable other handlers
375 class ParamAccel(ParamText
):
376 def __init__(self
, parent
, name
):
377 ParamText
.__init
__(self
, parent
, name
, 100)
379 class ParamPosSize(ParamText
):
380 def __init__(self
, parent
, name
):
381 ParamText
.__init
__(self
, parent
, name
, 80)
383 class ParamLabel(ParamText
):
384 def __init__(self
, parent
, name
):
385 ParamText
.__init
__(self
, parent
, name
, 200)
387 class ParamEncoding(ParamText
):
388 def __init__(self
, parent
, name
):
389 ParamText
.__init
__(self
, parent
, name
, 100)
391 class ContentDialog(wxDialogPtr
):
392 def __init__(self
, parent
, value
):
394 w
= g
.frame
.res
.LoadDialog(parent
, 'DIALOG_CONTENT')
395 # Perform initialization with class pointer
396 wxDialogPtr
.__init
__(self
, w
.this
)
399 self
.list = self
.FindWindowByName('LIST')
403 self
.SetAutoLayout(True)
404 self
.GetSizer().Fit(self
)
406 self
.ID_BUTTON_APPEND
= XMLID('BUTTON_APPEND')
407 self
.ID_BUTTON_REMOVE
= XMLID('BUTTON_REMOVE')
408 self
.ID_BUTTON_UP
= XMLID('BUTTON_UP')
409 self
.ID_BUTTON_DOWN
= XMLID('BUTTON_DOWN')
410 EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
411 EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
412 EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
413 EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
414 EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
415 EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
416 EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
417 def OnButtonUp(self
, evt
):
418 i
= self
.list.GetSelection()
419 str = self
.list.GetString(i
)
421 self
.list.InsertItems([str], i
-1)
422 self
.list.SetSelection(i
-1)
423 def OnButtonDown(self
, evt
):
424 i
= self
.list.GetSelection()
425 str = self
.list.GetString(i
)
427 self
.list.InsertItems([str], i
+1)
428 self
.list.SetSelection(i
+1)
429 def OnButtonAppend(self
, evt
):
430 str = wxGetTextFromUser('Enter new item:', 'Append', '', self
)
431 self
.list.Append(str)
432 def OnButtonRemove(self
, evt
):
433 self
.list.Delete(self
.list.GetSelection())
434 def OnUpdateUI(self
, evt
):
435 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
436 evt
.Enable(self
.list.GetSelection() != -1)
437 elif evt
.GetId() == self
.ID_BUTTON_UP
:
438 evt
.Enable(self
.list.GetSelection() > 0)
439 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
440 evt
.Enable(self
.list.GetSelection() != -1 and \
441 self
.list.GetSelection() < self
.list.Number() - 1)
443 class ContentCheckListDialog(wxDialogPtr
):
444 def __init__(self
, parent
, value
):
445 w
= g
.frame
.res
.LoadDialog(parent
, 'DIALOG_CONTENT_CHECK_LIST')
446 wxDialogPtr
.__init
__(self
, w
.this
)
449 self
.list = self
.FindWindowByName('CHECK_LIST')
454 self
.list.Check(i
, ch
)
456 self
.SetAutoLayout(True)
457 self
.GetSizer().Fit(self
)
459 self
.ID_BUTTON_APPEND
= XMLID('BUTTON_APPEND')
460 self
.ID_BUTTON_REMOVE
= XMLID('BUTTON_REMOVE')
461 self
.ID_BUTTON_UP
= XMLID('BUTTON_UP')
462 self
.ID_BUTTON_DOWN
= XMLID('BUTTON_DOWN')
463 EVT_CHECKLISTBOX(self
, self
.list.GetId(), self
.OnCheck
)
464 EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
465 EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
466 EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
467 EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
468 EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
469 EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
470 EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
471 def OnCheck(self
, evt
):
472 # !!! Wrong wxGTK (wxMSW?) behavior: toggling selection if checking
473 self
.list.Deselect(evt
.GetSelection())
474 def OnButtonUp(self
, evt
):
475 i
= self
.list.GetSelection()
476 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
478 self
.list.InsertItems([str], i
-1)
479 self
.list.Check(i
-1, ch
)
480 self
.list.SetSelection(i
-1)
481 def OnButtonDown(self
, evt
):
482 i
= self
.list.GetSelection()
483 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
485 self
.list.InsertItems([str], i
+1)
486 self
.list.Check(i
+1, ch
)
487 self
.list.SetSelection(i
+1)
488 def OnButtonAppend(self
, evt
):
489 str = wxGetTextFromUser('Enter new item:', 'Append', '', self
)
490 self
.list.Append(str)
491 def OnButtonRemove(self
, evt
):
492 self
.list.Delete(self
.list.GetSelection())
493 def OnUpdateUI(self
, evt
):
494 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
495 evt
.Enable(self
.list.GetSelection() != -1)
496 elif evt
.GetId() == self
.ID_BUTTON_UP
:
497 evt
.Enable(self
.list.GetSelection() > 0)
498 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
499 evt
.Enable(self
.list.GetSelection() != -1 and \
500 self
.list.GetSelection() < self
.list.Number() - 1)
502 class ParamContent(PPanel
):
503 def __init__(self
, parent
, name
):
504 PPanel
.__init
__(self
, parent
, name
)
505 self
.ID_TEXT_CTRL
= wxNewId()
506 self
.ID_BUTTON_EDIT
= wxNewId()
507 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
509 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(200,-1))
510 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
511 self
.button
= wxButton(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
512 sizer
.Add(self
.button
, 0, wxALIGN_CENTER_VERTICAL
)
513 self
.SetAutoLayout(True)
516 self
.textModified
= False
517 EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
518 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
519 def OnChange(self
, evt
):
520 PPanel
.OnChange(self
, evt
)
521 self
.textModified
= True
523 if self
.textModified
: # text has newer value
525 return eval(self
.text
.GetValue())
527 wxLogError('Syntax error in parameter value: ' + self
.GetName())
530 def SetValue(self
, value
):
532 if not value
: value
= []
534 self
.text
.SetValue(str(value
)) # update text ctrl
536 def OnButtonEdit(self
, evt
):
537 if self
.textModified
: # text has newer value
539 self
.value
= eval(self
.text
.GetValue())
541 wxLogError('Syntax error in parameter value: ' + self
.GetName())
543 dlg
= ContentDialog(self
, self
.value
)
544 if dlg
.ShowModal() == wxID_OK
:
546 for i
in range(dlg
.list.Number()):
547 value
.append(dlg
.list.GetString(i
))
551 self
.textModified
= False
555 class ParamContentCheckList(ParamContent
):
556 def __init__(self
, parent
, name
):
557 ParamContent
.__init
__(self
, parent
, name
)
558 def OnButtonEdit(self
, evt
):
559 if self
.textModified
: # text has newer value
561 self
.value
= eval(self
.text
.GetValue())
563 wxLogError('Syntax error in parameter value: ' + self
.GetName())
565 dlg
= ContentCheckListDialog(self
, self
.value
)
566 if dlg
.ShowModal() == wxID_OK
:
568 for i
in range(dlg
.list.Number()):
569 value
.append((dlg
.list.GetString(i
), dlg
.list.IsChecked(i
)))
573 self
.textModified
= False
576 class IntListDialog(wxDialogPtr
):
577 def __init__(self
, parent
, value
):
579 w
= g
.frame
.res
.LoadDialog(parent
, 'DIALOG_INTLIST')
580 wxDialogPtr
.__init
__(self
, w
.this
)
583 self
.list = self
.FindWindowByName('LIST')
587 if type(v
) != IntType
:
588 wxLogError('Invalid item type')
590 self
.list.Append(str(v
))
591 self
.SetAutoLayout(True)
592 self
.GetSizer().Fit(self
)
594 self
.ID_BUTTON_ADD
= XMLID('BUTTON_ADD')
595 self
.ID_BUTTON_REMOVE
= XMLID('BUTTON_REMOVE')
596 EVT_BUTTON(self
, self
.ID_BUTTON_ADD
, self
.OnButtonAppend
)
597 EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
598 EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
599 def OnButtonAppend(self
, evt
):
600 s
= wxGetTextFromUser('Enter new number:', 'Add', '', self
)
601 # Check that it's unique
604 s
= str(v
) # to be sure
605 i
= self
.list.FindString(s
)
606 if i
== -1: # ignore non-unique
607 # Find place to insert
609 for i
in range(self
.list.Number()):
610 if int(self
.list.GetString(i
)) > v
:
613 if found
: self
.list.InsertItems([s
], i
)
614 else: self
.list.Append(s
)
616 wxLogError('List item is not an int!')
617 def OnButtonRemove(self
, evt
):
618 self
.list.Delete(self
.list.GetSelection())
619 def OnUpdateUI(self
, evt
):
620 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
621 evt
.Enable(self
.list.GetSelection() != -1)
624 class ParamIntList(ParamContent
):
625 def __init__(self
, parent
, name
):
626 ParamContent
.__init
__(self
, parent
, name
)
627 def OnButtonEdit(self
, evt
):
628 if self
.textModified
: # text has newer value
630 self
.value
= eval(self
.text
.GetValue())
632 wxLogError('Syntax error in parameter value: ' + self
.GetName())
634 dlg
= IntListDialog(self
, self
.value
)
635 if dlg
.ShowModal() == wxID_OK
:
637 for i
in range(dlg
.list.Number()):
638 value
.append(int(dlg
.list.GetString(i
)))
642 self
.textModified
= False
646 class RadioBox(PPanel
):
647 def __init__(self
, parent
, id, choices
,
648 pos
=wxDefaultPosition
, name
='radiobox'):
649 PPanel
.__init
__(self
, parent
, name
)
650 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
651 self
.choices
= choices
652 topSizer
= wxBoxSizer()
654 button
= wxRadioButton(self
, -1, i
, name
=i
)
656 EVT_RADIOBUTTON(self
, button
.GetId(), self
.OnRadioChoice
)
657 self
.SetAutoLayout(True)
658 self
.SetSizer(topSizer
)
660 def SetStringSelection(self
, value
):
662 for i
in self
.choices
:
663 self
.FindWindowByName(i
).SetValue(i
== value
)
666 def OnRadioChoice(self
, evt
):
667 if self
.freeze
: return
668 if evt
.GetSelection():
669 self
.value
= evt
.GetEventObject().GetName()
671 def GetStringSelection(self
):
674 class ParamBool(RadioBox
):
675 values
= {'yes': '1', 'no': '0'}
676 seulav
= {'1': 'yes', '0': 'no'}
677 def __init__(self
, parent
, name
):
678 RadioBox
.__init
__(self
, parent
, -1, choices
= self
.values
.keys(), name
=name
)
680 return self
.values
[self
.GetStringSelection()]
681 def SetValue(self
, value
):
682 if not value
: value
= '1'
683 self
.SetStringSelection(self
.seulav
[value
])
685 class ParamOrient(RadioBox
):
686 values
= {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'}
687 seulav
= {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'}
688 def __init__(self
, parent
, name
):
689 RadioBox
.__init
__(self
, parent
, -1, choices
= self
.values
.keys(), name
=name
)
691 return self
.values
[self
.GetStringSelection()]
692 def SetValue(self
, value
):
693 if not value
: value
= 'wxHORIZONTAL'
694 self
.SetStringSelection(self
.seulav
[value
])
696 class ParamFile(PPanel
):
697 def __init__(self
, parent
, name
):
698 PPanel
.__init
__(self
, parent
, name
)
699 self
.ID_TEXT_CTRL
= wxNewId()
700 self
.ID_BUTTON_BROWSE
= wxNewId()
701 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
703 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(200,-1))
704 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
705 self
.button
= wxButton(self
, self
.ID_BUTTON_BROWSE
, 'Browse...',size
=buttonSize
)
706 sizer
.Add(self
.button
, 0, wxALIGN_CENTER_VERTICAL
)
707 self
.SetAutoLayout(True)
710 self
.textModified
= False
711 EVT_BUTTON(self
, self
.ID_BUTTON_BROWSE
, self
.OnButtonBrowse
)
712 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
713 def OnChange(self
, evt
):
714 PPanel
.OnChange(self
, evt
)
715 self
.textModified
= True
717 if self
.textModified
: # text has newer value
718 return self
.text
.GetValue()
720 def SetValue(self
, value
):
723 self
.text
.SetValue(value
) # update text ctrl
725 def OnButtonBrowse(self
, evt
):
726 if self
.textModified
: # text has newer value
727 self
.value
= self
.text
.GetValue()
728 dlg
= wxFileDialog(self
,
729 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
)),
730 defaultFile
= os
.path
.basename(self
.value
))
731 if dlg
.ShowModal() == wxID_OK
:
732 # Get common part of selected path and current
734 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
736 curpath
= os
.path
.join(os
.getcwd(), '')
737 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
738 self
.SetValue(dlg
.GetPath()[len(common
):])
740 self
.textModified
= False
743 class ParamBitmap(PPanel
):
744 def __init__(self
, parent
, name
):
746 w
= g
.frame
.res
.LoadPanel(parent
, 'PANEL_BITMAP')
747 # Perform initialization with class pointer
748 wxPanelPtr
.__init
__(self
, w
.this
)
750 self
.modified
= self
.freeze
= False
751 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
752 self
.radio_std
= self
.FindWindowByName('RADIO_STD')
753 self
.radio_file
= self
.FindWindowByName('RADIO_FILE')
754 self
.combo
= self
.FindWindowByName('COMBO_STD')
755 self
.text
= self
.FindWindowByName('TEXT_FILE')
756 self
.button
= self
.FindWindowByName('BUTTON_BROWSE')
757 self
.textModified
= False
758 self
.SetAutoLayout(True)
759 self
.GetSizer().SetMinSize((260, -1))
760 self
.GetSizer().Fit(self
)
761 EVT_RADIOBUTTON(self
, XMLID('RADIO_STD'), self
.OnRadioStd
)
762 EVT_RADIOBUTTON(self
, XMLID('RADIO_FILE'), self
.OnRadioFile
)
763 EVT_BUTTON(self
, XMLID('BUTTON_BROWSE'), self
.OnButtonBrowse
)
764 EVT_COMBOBOX(self
, XMLID('COMBO_STD'), self
.OnCombo
)
765 EVT_TEXT(self
, XMLID('COMBO_STD'), self
.OnChange
)
766 EVT_TEXT(self
, XMLID('TEXT_FILE'), self
.OnChange
)
767 def OnRadioStd(self
, evt
):
769 self
.SetValue(['wxART_MISSING_IMAGE',''])
770 def OnRadioFile(self
, evt
):
772 self
.SetValue(['',''])
773 def updateRadios(self
):
775 self
.radio_std
.SetValue(True)
776 self
.text
.Enable(False)
777 self
.button
.Enable(False)
778 self
.combo
.Enable(True)
780 self
.radio_file
.SetValue(True)
781 self
.text
.Enable(True)
782 self
.button
.Enable(True)
783 self
.combo
.Enable(False)
784 def OnChange(self
, evt
):
785 PPanel
.OnChange(self
, evt
)
786 self
.textModified
= True
787 def OnCombo(self
, evt
):
788 PPanel
.OnChange(self
, evt
)
789 self
.value
[0] = self
.combo
.GetValue()
791 if self
.textModified
: # text has newer value
792 return [self
.combo
.GetValue(), self
.text
.GetValue()]
794 def SetValue(self
, value
):
797 self
.value
= ['', '']
800 self
.combo
.SetValue(self
.value
[0])
801 self
.text
.SetValue(self
.value
[1]) # update text ctrl
804 def OnButtonBrowse(self
, evt
):
805 if self
.textModified
: # text has newer value
806 self
.value
[1] = self
.text
.GetValue()
807 dlg
= wxFileDialog(self
,
808 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
[1])),
809 defaultFile
= os
.path
.basename(self
.value
[1]))
810 if dlg
.ShowModal() == wxID_OK
:
811 # Get common part of selected path and current
813 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
815 curpath
= os
.path
.join(os
.getcwd(), '')
816 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
817 self
.SetValue(['', dlg
.GetPath()[len(common
):]])
819 self
.textModified
= False
824 'style': ParamStyle
, 'exstyle': ParamExStyle
,
825 'pos': ParamPosSize
, 'size': ParamPosSize
,
826 'border': ParamUnit
, 'cols': ParamInt
, 'rows': ParamInt
,
827 'vgap': ParamUnit
, 'hgap': ParamUnit
,
828 'checkable': ParamBool
, 'checked': ParamBool
, 'radio': ParamBool
,
830 'label': ParamText
, 'title': ParamText
, 'value': ParamText
,
831 'content': ParamContent
, 'selection': ParamInt
,
832 'min': ParamInt
, 'max': ParamInt
,
833 'fg': ParamColour
, 'bg': ParamColour
, 'font': ParamFont
,
834 'enabled': ParamBool
, 'focused': ParamBool
, 'hidden': ParamBool
,
835 'tooltip': ParamText
, 'bitmap': ParamBitmap
, 'icon': ParamBitmap
,
836 'label': ParamLabel
, 'encoding': ParamEncoding