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
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_CHOICES')
64 listBox
= XRCCTRL(dlg
, 'CHECK_LIST')
65 listBox
.InsertItems(self
.values
, 0)
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 if dlg
.ShowModal() == wxID_OK
:
81 for i
in range(listBox
.GetCount()):
82 if listBox
.IsChecked(i
):
83 value
.append(self
.values
[i
])
87 self
.SetValue(reduce(lambda a
,b
: a
+'|'+b
, value
))
93 class ParamFlag(ParamBinaryOr
):
94 values
= ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL',
95 'wxEXPAND', 'wxGROW', 'wxSHAPED', 'wxALIGN_CENTRE', 'wxALIGN_RIGHT',
96 'wxALIGN_BOTTOM', 'wxALIGN_CENTRE_VERTICAL',
97 'wxALIGN_CENTRE_HORIZONTAL']
98 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE',
99 'wxALIGN_CENTER_VERTICAL': 'wxALIGN_CENTRE_VERTICAL',
100 'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL'}
101 def __init__(self
, parent
, name
):
102 ParamBinaryOr
.__init
__(self
, parent
, name
)
104 class ParamStyle(ParamBinaryOr
):
105 equal
= {'wxALIGN_CENTER': 'wxALIGN_CENTRE'}
106 def __init__(self
, parent
, name
):
107 self
.values
= g
.currentXXX
.winStyles
+ genericStyles
108 ParamBinaryOr
.__init
__(self
, parent
, name
)
110 class ParamNonGenericStyle(ParamBinaryOr
):
111 def __init__(self
, parent
, name
):
112 self
.values
= g
.currentXXX
.winStyles
113 ParamBinaryOr
.__init
__(self
, parent
, name
)
115 class ParamExStyle(ParamBinaryOr
):
116 def __init__(self
, parent
, name
):
118 self
.values
= g
.currentXXX
.exStyles
# constant at the moment
121 ParamBinaryOr
.__init
__(self
, parent
, name
)
123 class ParamColour(PPanel
):
124 def __init__(self
, parent
, name
):
125 PPanel
.__init
__(self
, parent
, name
)
126 self
.ID_TEXT_CTRL
= wxNewId()
127 self
.ID_BUTTON
= wxNewId()
128 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
130 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(65,-1))
131 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
132 self
.button
= wxPanel(self
, self
.ID_BUTTON
, wxDefaultPosition
, wxSize(20, 1))
133 sizer
.Add(self
.button
, 0, wxGROW | wxALIGN_CENTER_VERTICAL
)
134 self
.SetAutoLayout(True)
137 self
.textModified
= False
138 EVT_PAINT(self
.button
, self
.OnPaintButton
)
139 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
140 EVT_LEFT_DOWN(self
.button
, self
.OnLeftDown
)
142 return self
.text
.GetValue()
143 def SetValue(self
, value
):
145 if not value
: value
= '#FFFFFF'
146 self
.text
.SetValue(str(value
)) # update text ctrl
147 colour
= wxColour(int(value
[1:3], 16), int(value
[3:5], 16), int(value
[5:7], 16))
148 self
.button
.SetBackgroundColour(colour
)
149 self
.button
.Refresh()
151 def OnPaintButton(self
, evt
):
152 dc
= wxPaintDC(self
.button
)
153 dc
.SetBrush(wxTRANSPARENT_BRUSH
)
154 if self
.IsEnabled(): dc
.SetPen(wxBLACK_PEN
)
155 else: dc
.SetPen(wxGREY_PEN
)
156 size
= self
.button
.GetSize()
157 dc
.DrawRectangle((0, 0), size
)
158 def OnLeftDown(self
, evt
):
159 data
= wxColourData()
160 data
.SetColour(self
.GetValue())
161 dlg
= wxColourDialog(self
, data
)
162 if dlg
.ShowModal() == wxID_OK
:
163 self
.SetValue('#%02X%02X%02X' % dlg
.GetColourData().GetColour().Get())
167 ################################################################################
169 # Mapping from wx constants ro XML strings
170 fontFamiliesWx2Xml
= {wxDEFAULT
: 'default', wxDECORATIVE
: 'decorative',
171 wxROMAN
: 'roman', wxSCRIPT
: 'script', wxSWISS
: 'swiss',
173 fontStylesWx2Xml
= {wxNORMAL: 'normal', wxSLANT: 'slant', wxITALIC: 'italic'}
174 fontWeightsWx2Xml
= {wxNORMAL: 'normal', wxLIGHT: 'light', wxBOLD: 'bold'}
177 for k
,v
in m
.items(): rm
[v
] = k
179 fontFamiliesXml2wx
= ReverseMap(fontFamiliesWx2Xml
)
180 fontStylesXml2wx
= ReverseMap(fontStylesWx2Xml
)
181 fontWeightsXml2wx
= ReverseMap(fontWeightsWx2Xml
)
183 class ParamFont(PPanel
):
184 def __init__(self
, parent
, name
):
185 PPanel
.__init
__(self
, parent
, name
)
186 self
.ID_TEXT_CTRL
= wxNewId()
187 self
.ID_BUTTON_SELECT
= wxNewId()
188 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
190 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(200,-1))
191 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
192 self
.button
= wxButton(self
, self
.ID_BUTTON_SELECT
, 'Select...', size
=buttonSize
)
193 sizer
.Add(self
.button
, 0, wxALIGN_CENTER_VERTICAL
)
194 self
.SetAutoLayout(True)
197 self
.textModified
= False
198 EVT_BUTTON(self
, self
.ID_BUTTON_SELECT
, self
.OnButtonSelect
)
199 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
200 def OnChange(self
, evt
):
201 PPanel
.OnChange(self
, evt
)
202 self
.textModified
= True
203 def _defaultValue(self
):
204 return ['12', 'default', 'normal', 'normal', '0', '', '']
206 if self
.textModified
: # text has newer value
208 return eval(self
.text
.GetValue())
210 wxLogError('Syntax error in parameter value: ' + self
.GetName())
211 return self
._defaultValue
()
213 def SetValue(self
, value
):
214 self
.freeze
= True # disable other handlers
215 if not value
: value
= self
._defaultValue
()
217 self
.text
.SetValue(str(value
)) # update text ctrl
219 def OnButtonSelect(self
, evt
):
220 if self
.textModified
: # text has newer value
222 self
.value
= eval(self
.text
.GetValue())
224 wxLogError('Syntax error in parameter value: ' + self
.GetName())
225 self
.value
= self
._defaultValue
()
230 style
= weight
= wxNORMAL
233 enc
= wxFONTENCODING_DEFAULT
234 # Fall back to default if exceptions
237 try: size
= int(self
.value
[0])
238 except ValueError: error
= True
239 try: family
= fontFamiliesXml2wx
[self
.value
[1]]
240 except KeyError: error
= True
241 try: style
= fontStylesXml2wx
[self
.value
[2]]
242 except KeyError: error
= True
243 try: weight
= fontWeightsXml2wx
[self
.value
[3]]
244 except KeyError: error
= True
245 try: underlined
= int(self
.value
[4])
246 except ValueError: error
= True
248 mapper
= wxFontMapper()
249 if not self
.value
[6]: enc
= mapper
.CharsetToEncoding(self
.value
[6])
252 if error
: wxLogError('Invalid font specification')
253 if enc
== wxFONTENCODING_DEFAULT
: enc
= wxFONTENCODING_SYSTEM
254 font
= wxFont(size
, family
, style
, weight
, underlined
, face
, enc
)
256 data
.SetInitialFont(font
)
257 dlg
= wxFontDialog(self
, data
)
258 if dlg
.ShowModal() == wxID_OK
:
259 font
= dlg
.GetFontData().GetChosenFont()
260 value
= [str(font
.GetPointSize()),
261 fontFamiliesWx2Xml
.get(font
.GetFamily(), "default"),
262 fontStylesWx2Xml
.get(font
.GetStyle(), "normal"),
263 fontWeightsWx2Xml
.get(font
.GetWeight(), "normal"),
264 str(font
.GetUnderlined()),
265 font
.GetFaceName().encode(),
266 wxFontMapper_GetEncodingName(font
.GetEncoding()).encode()
271 self
.textModified
= False
274 ################################################################################
276 class ParamInt(PPanel
):
277 def __init__(self
, parent
, name
):
278 PPanel
.__init
__(self
, parent
, name
)
279 self
.ID_SPIN_CTRL
= wxNewId()
281 self
.spin
= wxSpinCtrl(self
, self
.ID_SPIN_CTRL
, size
=(50,-1))
282 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
284 self
.SetAutoLayout(True)
287 EVT_SPINCTRL(self
, self
.ID_SPIN_CTRL
, self
.OnChange
)
289 return str(self
.spin
.GetValue())
290 def SetValue(self
, value
):
292 if not value
: value
= 0
293 self
.spin
.SetValue(int(value
))
296 # Same as int but allows dialog units (XXXd)
297 class ParamUnit(PPanel
):
298 def __init__(self
, parent
, name
):
299 PPanel
.__init
__(self
, parent
, name
)
300 self
.ID_TEXT_CTRL
= wxNewId()
301 self
.ID_SPIN_BUTTON
= wxNewId()
303 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=(35,-1))
304 self
.spin
= wxSpinButton(self
, self
.ID_SPIN_BUTTON
, style
= wxSP_VERTICAL
, size
=(-1,1))
305 self
.spin
.SetRange(-10000, 10000)
306 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
307 sizer
.Add(self
.text
, 0, wxEXPAND | wxRIGHT
, 2)
308 sizer
.Add(self
.spin
, 0, wxEXPAND
)
309 self
.SetAutoLayout(True)
312 EVT_SPIN_UP(self
, self
.ID_SPIN_BUTTON
, self
.OnSpinUp
)
313 EVT_SPIN_DOWN(self
, self
.ID_SPIN_BUTTON
, self
.OnSpinDown
)
315 return self
.text
.GetValue()
316 def SetValue(self
, value
):
318 if not value
: value
= '0'
319 self
.text
.SetValue(value
)
322 # Check if we are working with dialog units
323 value
= self
.text
.GetValue()
325 if value
[-1].upper() == 'D':
329 intValue
= int(value
) + x
330 self
.spin
.SetValue(intValue
)
331 self
.text
.SetValue(str(intValue
) + units
)
334 # !!! Strange, if I use wxLogWarning, event is re-generated
335 print 'incorrect unit format'
336 def OnSpinUp(self
, evt
):
338 def OnSpinDown(self
, evt
):
341 class ParamMultilineText(PPanel
):
342 def __init__(self
, parent
, name
, textWidth
=-1):
343 PPanel
.__init
__(self
, parent
, name
)
344 self
.ID_TEXT_CTRL
= wxNewId()
345 self
.ID_BUTTON_EDIT
= wxNewId()
346 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
348 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
349 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(200,-1))
350 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
351 self
.button
= wxButton(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
352 sizer
.Add(self
.button
, 0, wxALIGN_CENTER_VERTICAL
)
353 self
.SetAutoLayout(True)
356 EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
357 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
359 return self
.text
.GetValue()
360 def SetValue(self
, value
):
361 self
.freeze
= True # disable other handlers
362 self
.text
.SetValue(value
)
363 self
.freeze
= False # disable other handlers
364 def OnButtonEdit(self
, evt
):
365 dlg
= g
.frame
.res
.LoadDialog(self
, 'DIALOG_TEXT')
366 textCtrl
= XRCCTRL(dlg
, 'TEXT')
367 textCtrl
.SetValue(self
.text
.GetValue())
368 if dlg
.ShowModal() == wxID_OK
:
369 self
.text
.SetValue(textCtrl
.GetValue())
373 class ParamText(PPanel
):
374 def __init__(self
, parent
, name
, textWidth
=-1):
375 PPanel
.__init
__(self
, parent
, name
)
376 self
.ID_TEXT_CTRL
= wxNewId()
377 # We use sizer even here to have the same size of text control
379 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
380 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(textWidth
,-1))
381 if textWidth
== -1: option
= 1
383 sizer
.Add(self
.text
, option
, wxALIGN_CENTER_VERTICAL
)
384 self
.SetAutoLayout(True)
387 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
389 return self
.text
.GetValue()
390 def SetValue(self
, value
):
391 self
.freeze
= True # disable other handlers
392 self
.text
.SetValue(value
)
393 self
.freeze
= False # disable other handlers
395 class ParamAccel(ParamText
):
396 def __init__(self
, parent
, name
):
397 ParamText
.__init
__(self
, parent
, name
, 100)
399 class ParamPosSize(ParamText
):
400 def __init__(self
, parent
, name
):
401 ParamText
.__init
__(self
, parent
, name
, 80)
403 class ParamLabel(ParamText
):
404 def __init__(self
, parent
, name
):
405 ParamText
.__init
__(self
, parent
, name
, 200)
407 class ParamEncoding(ParamText
):
408 def __init__(self
, parent
, name
):
409 ParamText
.__init
__(self
, parent
, name
, 100)
411 class ContentDialog(wxDialog
):
412 def __init__(self
, parent
, value
):
415 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT')
417 self
._setOORInfo
(self
)
418 self
.list = XRCCTRL(self
, 'LIST')
422 self
.SetAutoLayout(True)
423 self
.GetSizer().Fit(self
)
425 self
.ID_BUTTON_APPEND
= XRCID('BUTTON_APPEND')
426 self
.ID_BUTTON_REMOVE
= XRCID('BUTTON_REMOVE')
427 self
.ID_BUTTON_UP
= XRCID('BUTTON_UP')
428 self
.ID_BUTTON_DOWN
= XRCID('BUTTON_DOWN')
429 EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
430 EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
431 EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
432 EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
433 EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
434 EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
435 EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
436 def OnButtonUp(self
, evt
):
437 i
= self
.list.GetSelection()
438 str = self
.list.GetString(i
)
440 self
.list.InsertItems([str], i
-1)
441 self
.list.SetSelection(i
-1)
442 def OnButtonDown(self
, evt
):
443 i
= self
.list.GetSelection()
444 str = self
.list.GetString(i
)
446 self
.list.InsertItems([str], i
+1)
447 self
.list.SetSelection(i
+1)
448 def OnButtonAppend(self
, evt
):
449 str = wxGetTextFromUser('Enter new item:', 'Append', '', self
)
450 self
.list.Append(str)
451 def OnButtonRemove(self
, evt
):
452 self
.list.Delete(self
.list.GetSelection())
453 def OnUpdateUI(self
, evt
):
454 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
455 evt
.Enable(self
.list.GetSelection() != -1)
456 elif evt
.GetId() == self
.ID_BUTTON_UP
:
457 evt
.Enable(self
.list.GetSelection() > 0)
458 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
459 evt
.Enable(self
.list.GetSelection() != -1 and \
460 self
.list.GetSelection() < self
.list.GetCount() - 1)
462 class ContentCheckListDialog(wxDialog
):
463 def __init__(self
, parent
, value
):
465 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_CONTENT_CHECK_LIST')
467 self
._setOORInfo
(self
)
468 self
.list = XRCCTRL(self
, 'CHECK_LIST')
473 self
.list.Check(i
, ch
)
475 self
.SetAutoLayout(True)
476 self
.GetSizer().Fit(self
)
478 self
.ID_BUTTON_APPEND
= XRCID('BUTTON_APPEND')
479 self
.ID_BUTTON_REMOVE
= XRCID('BUTTON_REMOVE')
480 self
.ID_BUTTON_UP
= XRCID('BUTTON_UP')
481 self
.ID_BUTTON_DOWN
= XRCID('BUTTON_DOWN')
482 EVT_CHECKLISTBOX(self
, self
.list.GetId(), self
.OnCheck
)
483 EVT_BUTTON(self
, self
.ID_BUTTON_UP
, self
.OnButtonUp
)
484 EVT_BUTTON(self
, self
.ID_BUTTON_DOWN
, self
.OnButtonDown
)
485 EVT_BUTTON(self
, self
.ID_BUTTON_APPEND
, self
.OnButtonAppend
)
486 EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
487 EVT_UPDATE_UI(self
, self
.ID_BUTTON_UP
, self
.OnUpdateUI
)
488 EVT_UPDATE_UI(self
, self
.ID_BUTTON_DOWN
, self
.OnUpdateUI
)
489 EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
490 def OnCheck(self
, evt
):
491 # !!! Wrong wxGTK (wxMSW?) behavior: toggling selection if checking
492 self
.list.Deselect(evt
.GetSelection())
493 def OnButtonUp(self
, evt
):
494 i
= self
.list.GetSelection()
495 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
497 self
.list.InsertItems([str], i
-1)
498 self
.list.Check(i
-1, ch
)
499 self
.list.SetSelection(i
-1)
500 def OnButtonDown(self
, evt
):
501 i
= self
.list.GetSelection()
502 str, ch
= self
.list.GetString(i
), self
.list.IsChecked(i
)
504 self
.list.InsertItems([str], i
+1)
505 self
.list.Check(i
+1, ch
)
506 self
.list.SetSelection(i
+1)
507 def OnButtonAppend(self
, evt
):
508 str = wxGetTextFromUser('Enter new item:', 'Append', '', self
)
509 self
.list.Append(str)
510 def OnButtonRemove(self
, evt
):
511 self
.list.Delete(self
.list.GetSelection())
512 def OnUpdateUI(self
, evt
):
513 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
514 evt
.Enable(self
.list.GetSelection() != -1)
515 elif evt
.GetId() == self
.ID_BUTTON_UP
:
516 evt
.Enable(self
.list.GetSelection() > 0)
517 elif evt
.GetId() == self
.ID_BUTTON_DOWN
:
518 evt
.Enable(self
.list.GetSelection() != -1 and \
519 self
.list.GetSelection() < self
.list.GetCount() - 1)
521 class ParamContent(PPanel
):
522 def __init__(self
, parent
, name
):
523 PPanel
.__init
__(self
, parent
, name
)
524 self
.ID_TEXT_CTRL
= wxNewId()
525 self
.ID_BUTTON_EDIT
= wxNewId()
526 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
528 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(200,-1))
529 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
530 self
.button
= wxButton(self
, self
.ID_BUTTON_EDIT
, 'Edit...', size
=buttonSize
)
531 sizer
.Add(self
.button
, 0, wxALIGN_CENTER_VERTICAL
)
532 self
.SetAutoLayout(True)
535 self
.textModified
= False
536 EVT_BUTTON(self
, self
.ID_BUTTON_EDIT
, self
.OnButtonEdit
)
537 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
538 def OnChange(self
, evt
):
539 PPanel
.OnChange(self
, evt
)
540 self
.textModified
= True
542 if self
.textModified
: # text has newer value
544 return eval(self
.text
.GetValue())
546 wxLogError('Syntax error in parameter value: ' + self
.GetName())
549 def SetValue(self
, value
):
551 if not value
: value
= []
553 self
.text
.SetValue(str(value
)) # update text ctrl
555 def OnButtonEdit(self
, evt
):
556 if self
.textModified
: # text has newer value
558 self
.value
= eval(self
.text
.GetValue())
560 wxLogError('Syntax error in parameter value: ' + self
.GetName())
562 dlg
= ContentDialog(self
, self
.value
)
563 if dlg
.ShowModal() == wxID_OK
:
565 for i
in range(dlg
.list.GetCount()):
566 value
.append(dlg
.list.GetString(i
))
570 self
.textModified
= False
574 class ParamContentCheckList(ParamContent
):
575 def __init__(self
, parent
, name
):
576 ParamContent
.__init
__(self
, parent
, name
)
577 def OnButtonEdit(self
, evt
):
578 if self
.textModified
: # text has newer value
580 self
.value
= eval(self
.text
.GetValue())
582 wxLogError('Syntax error in parameter value: ' + self
.GetName())
584 dlg
= ContentCheckListDialog(self
, self
.value
)
585 if dlg
.ShowModal() == wxID_OK
:
587 for i
in range(dlg
.list.GetCount()):
588 value
.append((dlg
.list.GetString(i
), dlg
.list.IsChecked(i
)))
592 self
.textModified
= False
595 class IntListDialog(wxDialog
):
596 def __init__(self
, parent
, value
):
598 g
.frame
.res
.LoadOnDialog(pre
, parent
, 'DIALOG_INTLIST')
600 self
._setOORInfo
(self
)
601 self
.list = XRCCTRL(self
, 'LIST')
605 if type(v
) != IntType
:
606 wxLogError('Invalid item type')
608 self
.list.Append(str(v
))
609 self
.SetAutoLayout(True)
610 self
.GetSizer().Fit(self
)
612 self
.ID_BUTTON_ADD
= XRCID('BUTTON_ADD')
613 self
.ID_BUTTON_REMOVE
= XRCID('BUTTON_REMOVE')
614 EVT_BUTTON(self
, self
.ID_BUTTON_ADD
, self
.OnButtonAppend
)
615 EVT_BUTTON(self
, self
.ID_BUTTON_REMOVE
, self
.OnButtonRemove
)
616 EVT_UPDATE_UI(self
, self
.ID_BUTTON_REMOVE
, self
.OnUpdateUI
)
617 def OnButtonAppend(self
, evt
):
618 s
= wxGetTextFromUser('Enter new number:', 'Add', '', self
)
620 # Check that it's unique
623 s
= str(v
) # to be sure
624 i
= self
.list.FindString(s
)
625 if i
== -1: # ignore non-unique
626 # Find place to insert
628 for i
in range(self
.list.GetCount()):
629 if int(self
.list.GetString(i
)) > v
:
632 if found
: self
.list.InsertItems([s
], i
)
633 else: self
.list.Append(s
)
635 wxLogError('List item is not an int!')
636 def OnButtonRemove(self
, evt
):
637 self
.list.Delete(self
.list.GetSelection())
638 def OnUpdateUI(self
, evt
):
639 if evt
.GetId() == self
.ID_BUTTON_REMOVE
:
640 evt
.Enable(self
.list.GetSelection() != -1)
643 class ParamIntList(ParamContent
):
644 def __init__(self
, parent
, name
):
645 ParamContent
.__init
__(self
, parent
, name
)
646 def OnButtonEdit(self
, evt
):
647 if self
.textModified
: # text has newer value
649 self
.value
= eval(self
.text
.GetValue())
651 wxLogError('Syntax error in parameter value: ' + self
.GetName())
653 dlg
= IntListDialog(self
, self
.value
)
654 if dlg
.ShowModal() == wxID_OK
:
656 for i
in range(dlg
.list.GetCount()):
657 value
.append(int(dlg
.list.GetString(i
)))
661 self
.textModified
= False
665 class RadioBox(PPanel
):
666 def __init__(self
, parent
, id, choices
,
667 pos
=wxDefaultPosition
, name
='radiobox'):
668 PPanel
.__init
__(self
, parent
, name
)
669 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
670 self
.choices
= choices
671 topSizer
= wxBoxSizer()
673 button
= wxRadioButton(self
, -1, i
, size
=(-1,buttonSize
[1]), name
=i
)
674 topSizer
.Add(button
, 0, wxRIGHT
, 5)
675 EVT_RADIOBUTTON(self
, button
.GetId(), self
.OnRadioChoice
)
676 self
.SetAutoLayout(True)
677 self
.SetSizer(topSizer
)
679 def SetStringSelection(self
, value
):
681 for i
in self
.choices
:
682 self
.FindWindowByName(i
).SetValue(i
== value
)
685 def OnRadioChoice(self
, evt
):
686 if self
.freeze
: return
687 if evt
.GetSelection():
688 self
.value
= evt
.GetEventObject().GetName()
690 def GetStringSelection(self
):
693 class ParamBool(RadioBox
):
694 values
= {'yes': '1', 'no': '0'}
695 seulav
= {'1': 'yes', '0': 'no'}
696 def __init__(self
, parent
, name
):
697 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
699 return self
.values
[self
.GetStringSelection()]
700 def SetValue(self
, value
):
701 if not value
: value
= '1'
702 self
.SetStringSelection(self
.seulav
[value
])
704 class ParamOrient(RadioBox
):
705 values
= {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'}
706 seulav
= {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'}
707 def __init__(self
, parent
, name
):
708 RadioBox
.__init
__(self
, parent
, -1, choices
=self
.values
.keys(), name
=name
)
710 return self
.values
[self
.GetStringSelection()]
711 def SetValue(self
, value
):
712 if not value
: value
= 'wxHORIZONTAL'
713 self
.SetStringSelection(self
.seulav
[value
])
715 class ParamFile(PPanel
):
716 def __init__(self
, parent
, name
):
717 PPanel
.__init
__(self
, parent
, name
)
718 self
.ID_TEXT_CTRL
= wxNewId()
719 self
.ID_BUTTON_BROWSE
= wxNewId()
720 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
722 self
.text
= wxTextCtrl(self
, self
.ID_TEXT_CTRL
, size
=wxSize(200,-1))
723 sizer
.Add(self
.text
, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL
, 5)
724 self
.button
= wxButton(self
, self
.ID_BUTTON_BROWSE
, 'Browse...',size
=buttonSize
)
725 sizer
.Add(self
.button
, 0, wxALIGN_CENTER_VERTICAL
)
726 self
.SetAutoLayout(True)
729 self
.textModified
= False
730 EVT_BUTTON(self
, self
.ID_BUTTON_BROWSE
, self
.OnButtonBrowse
)
731 EVT_TEXT(self
, self
.ID_TEXT_CTRL
, self
.OnChange
)
732 def OnChange(self
, evt
):
733 PPanel
.OnChange(self
, evt
)
734 self
.textModified
= True
736 if self
.textModified
: # text has newer value
737 return self
.text
.GetValue()
739 def SetValue(self
, value
):
742 self
.text
.SetValue(value
) # update text ctrl
744 def OnButtonBrowse(self
, evt
):
745 if self
.textModified
: # text has newer value
746 self
.value
= self
.text
.GetValue()
747 dlg
= wxFileDialog(self
,
748 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
)),
749 defaultFile
= os
.path
.basename(self
.value
))
750 if dlg
.ShowModal() == wxID_OK
:
751 # Get common part of selected path and current
753 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
755 curpath
= os
.path
.join(os
.getcwd(), '')
756 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
757 self
.SetValue(dlg
.GetPath()[len(common
):])
759 self
.textModified
= False
762 class ParamBitmap(PPanel
):
763 def __init__(self
, parent
, name
):
765 g
.frame
.res
.LoadOnPanel(pre
, parent
, 'PANEL_BITMAP')
767 self
._setOORInfo
(self
)
768 self
.modified
= self
.freeze
= False
769 self
.SetBackgroundColour(g
.panel
.GetBackgroundColour())
770 self
.radio_std
= XRCCTRL(self
, 'RADIO_STD')
771 self
.radio_file
= XRCCTRL(self
, 'RADIO_FILE')
772 self
.combo
= XRCCTRL(self
, 'COMBO_STD')
773 self
.text
= XRCCTRL(self
, 'TEXT_FILE')
774 self
.button
= XRCCTRL(self
, 'BUTTON_BROWSE')
775 self
.textModified
= False
776 self
.SetAutoLayout(True)
777 self
.GetSizer().SetMinSize((260, -1))
778 self
.GetSizer().Fit(self
)
779 EVT_RADIOBUTTON(self
, XRCID('RADIO_STD'), self
.OnRadioStd
)
780 EVT_RADIOBUTTON(self
, XRCID('RADIO_FILE'), self
.OnRadioFile
)
781 EVT_BUTTON(self
, XRCID('BUTTON_BROWSE'), self
.OnButtonBrowse
)
782 EVT_COMBOBOX(self
, XRCID('COMBO_STD'), self
.OnCombo
)
783 EVT_TEXT(self
, XRCID('COMBO_STD'), self
.OnChange
)
784 EVT_TEXT(self
, XRCID('TEXT_FILE'), self
.OnChange
)
785 def OnRadioStd(self
, evt
):
787 self
.SetValue(['wxART_MISSING_IMAGE',''])
788 def OnRadioFile(self
, evt
):
790 self
.SetValue(['',''])
791 def updateRadios(self
):
793 self
.radio_std
.SetValue(True)
794 self
.radio_file
.SetValue(False)
795 self
.text
.Enable(False)
796 self
.button
.Enable(False)
797 self
.combo
.Enable(True)
799 self
.radio_std
.SetValue(False)
800 self
.radio_file
.SetValue(True)
801 self
.text
.Enable(True)
802 self
.button
.Enable(True)
803 self
.combo
.Enable(False)
804 def OnChange(self
, evt
):
805 PPanel
.OnChange(self
, evt
)
806 self
.textModified
= True
807 def OnCombo(self
, evt
):
808 PPanel
.OnChange(self
, evt
)
809 self
.value
[0] = self
.combo
.GetValue()
811 if self
.textModified
: # text has newer value
812 return [self
.combo
.GetValue(), self
.text
.GetValue()]
814 def SetValue(self
, value
):
817 self
.value
= ['', '']
820 self
.combo
.SetValue(self
.value
[0])
821 self
.text
.SetValue(self
.value
[1]) # update text ctrl
824 def OnButtonBrowse(self
, evt
):
825 if self
.textModified
: # text has newer value
826 self
.value
[1] = self
.text
.GetValue()
827 dlg
= wxFileDialog(self
,
828 defaultDir
= os
.path
.abspath(os
.path
.dirname(self
.value
[1])),
829 defaultFile
= os
.path
.basename(self
.value
[1]))
830 if dlg
.ShowModal() == wxID_OK
:
831 # Get common part of selected path and current
833 curpath
= os
.path
.abspath(g
.frame
.dataFile
)
835 curpath
= os
.path
.join(os
.getcwd(), '')
836 common
= os
.path
.commonprefix([curpath
, dlg
.GetPath()])
837 self
.SetValue(['', dlg
.GetPath()[len(common
):]])
839 self
.textModified
= False
844 'style': ParamStyle
, 'exstyle': ParamExStyle
,
845 'pos': ParamPosSize
, 'size': ParamPosSize
,
846 'border': ParamUnit
, 'cols': ParamInt
, 'rows': ParamInt
,
847 'vgap': ParamUnit
, 'hgap': ParamUnit
,
848 'checkable': ParamBool
, 'checked': ParamBool
, 'radio': ParamBool
,
850 'label': ParamMultilineText
, 'title': ParamText
, 'value': ParamText
,
851 'content': ParamContent
, 'selection': ParamInt
,
852 'min': ParamInt
, 'max': ParamInt
,
853 'fg': ParamColour
, 'bg': ParamColour
, 'font': ParamFont
,
854 'enabled': ParamBool
, 'focused': ParamBool
, 'hidden': ParamBool
,
855 'tooltip': ParamText
, 'bitmap': ParamBitmap
, 'icon': ParamBitmap
,
856 'encoding': ParamEncoding