+ self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(60,-1))
+ sizer.Add(self.text, 0, wxRIGHT, 10)
+ self.button = wxPanel(self, self.ID_BUTTON, wxDefaultPosition, wxSize(40, -1))
+ sizer.Add(self.button, 0, wxGROW)
+ self.SetAutoLayout(true)
+ self.SetSizer(sizer)
+ sizer.Fit(self)
+ self.textModified = false
+ EVT_PAINT(self.button, self.OnPaintButton)
+ EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
+ EVT_LEFT_DOWN(self.button, self.OnLeftDown)
+ def GetValue(self):
+ return self.value
+ def SetValue(self, value):
+ self.freeze = true
+ if not value: value = '#FFFFFF'
+ self.value = value
+ self.text.SetValue(str(value)) # update text ctrl
+ colour = wxColour(int(value[1:3], 16), int(value[3:5], 16), int(value[5:7], 16))
+ self.button.SetBackgroundColour(colour)
+ self.button.Refresh()
+ self.freeze = false
+ def OnChange(self, evt):
+ if self.freeze: return
+ self.SetModified()
+ self.textModified = true
+ evt.Skip()
+ def OnPaintButton(self, evt):
+ dc = wxPaintDC(self.button)
+ dc.SetBrush(wxTRANSPARENT_BRUSH)
+ if self.IsEnabled(): dc.SetPen(wxBLACK_PEN)
+ else: dc.SetPen(wxGREY_PEN)
+ size = self.button.GetSize()
+ dc.DrawRectangle(0, 0, size.x, size.y)
+ def OnLeftDown(self, evt):
+ dlg = wxColourDialog(self)
+ if dlg.ShowModal() == wxID_OK:
+ self.SetValue('#%02X%02X%02X' % dlg.GetColourData().GetColour().Get())
+ self.SetModified()
+ self.textModified = false
+ dlg.Destroy()
+
+################################################################################
+
+# Mapping from wx constants ro XML strings
+fontFamiliesWx2Xml = {wxDEFAULT: 'default', wxDECORATIVE: 'decorative',
+ wxROMAN: 'roman', wxSCRIPT: 'script', wxSWISS: 'swiss',
+ wxMODERN: 'modern'}
+fontStylesWx2Xml = {wxNORMAL: 'normal', wxSLANT: 'slant', wxITALIC: 'italic'}
+fontWeightsWx2Xml = {wxNORMAL: 'normal', wxLIGHT: 'light', wxBOLD: 'bold'}
+def ReverseMap(m):
+ rm = {}
+ for k,v in m.items(): rm[v] = k
+ return rm
+fontFamiliesXml2wx = ReverseMap(fontFamiliesWx2Xml)
+fontStylesXml2wx = ReverseMap(fontStylesWx2Xml)
+fontWeightsXml2wx = ReverseMap(fontWeightsWx2Xml)
+
+class ParamFont(PPanel):
+ def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
+ PPanel.__init__(self, parent, id, name)
+ self.ID_TEXT_CTRL = wxNewId()
+ self.ID_BUTTON_SELECT = wxNewId()
+ self.SetBackgroundColour(panel.GetBackgroundColour())
+ sizer = wxBoxSizer()
+ self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(200,-1))
+ sizer.Add(self.text, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, 10)
+ self.button = wxButton(self, self.ID_BUTTON_SELECT, 'Select...')
+ sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL)
+ self.SetAutoLayout(true)
+ self.SetSizer(sizer)
+ sizer.Fit(self)
+ self.textModified = false
+ EVT_BUTTON(self, self.ID_BUTTON_SELECT, self.OnButtonSelect)
+ EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
+ def OnChange(self, evt):
+ if self.freeze: return
+ self.SetModified()
+ self.textModified = true
+ evt.Skip()
+ def GetValue(self):
+ if self.textModified: # text has newer value
+ return eval(self.text.GetValue())
+ return self.value
+ def SetValue(self, value):
+ self.freeze = true # disable other handlers
+ if not value: value = [''] * 7
+ self.value = value
+ self.text.SetValue(str(value)) # update text ctrl
+ self.freeze = false
+ def OnButtonSelect(self, evt):
+ if self.textModified: # text has newer value
+ self.value = eval(self.text.GetValue())
+ # Make initial font
+ try: size = int(self.value[0])
+ except ValueError: size = 12
+ try: family = fontFamiliesXml2wx[self.value[1]]
+ except KeyError: family = wxDEFAULT
+ try: style = fontStylesXml2wx[self.value[2]]
+ except KeyError: style = wxNORMAL
+ try: weight = fontWeightsXml2wx[self.value[3]]
+ except KeyError: weight = wxNORMAL
+ try: underlined = int(self.value[4])
+ except ValueError: underlined = 0
+ face = self.value[5]
+ mapper = wxFontMapper()
+ enc = wxFONTENCODING_DEFAULT
+ if not self.value[6]: enc = mapper.CharsetToEncoding(self.value[6])
+ if enc == wxFONTENCODING_DEFAULT: enc = wxFONTENCODING_SYSTEM
+ font = wxFont(size, family, style, weight, underlined, face, enc)
+ data = wxFontData()
+ data.SetInitialFont(font)
+ dlg = wxFontDialog(self, data)
+ if dlg.ShowModal() == wxID_OK:
+ font = dlg.GetFontData().GetChosenFont()
+ value = [str(font.GetPointSize()), fontFamiliesWx2Xml[font.GetFamily()],
+ fontStylesWx2Xml[font.GetStyle()],
+ fontWeightsWx2Xml[font.GetWeight()],
+ str(font.GetUnderlined()), font.GetFaceName(),
+ wxFontMapper_GetEncodingName(font.GetEncoding())]
+ # Add ignored flags
+ self.SetValue(value)
+ self.SetModified()
+ self.textModified = false
+ dlg.Destroy()
+
+################################################################################
+
+class ParamInt(PPanel):
+ def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
+ PPanel.__init__(self, parent, id, name)
+ self.ID_SPIN_CTRL = wxNewId()
+ sizer = wxBoxSizer()
+ self.spin = wxSpinCtrl(self, self.ID_SPIN_CTRL, size=wxSize(50,-1))