New XRCed from Roman Rolinsky
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12350 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
from wxPython.wx import *
|
||||
from wxPython.xrc import *
|
||||
import string
|
||||
import os.path
|
||||
|
||||
# Object which is currently processed
|
||||
currentXXX = None
|
||||
@@ -14,40 +15,52 @@ def SetCurrentXXX(xxx):
|
||||
global currentXXX
|
||||
currentXXX = xxx
|
||||
|
||||
genericStyles = ['wxSIMPLE_BORDER', 'wxSUNKEN_BORDER', 'wxRAISED_BORDER',
|
||||
'wxTAB_TRAVERSAL', 'wxWANTS_CHARS', 'wxVSCROLL', 'wxHSCROLL']
|
||||
genericStyles = ['wxSIMPLE_BORDER', 'wxDOUBLE_BORDER',
|
||||
'wxSUNKEN_BORDER', 'wxRAISED_BORDER',
|
||||
'wxSTATIC_BORDER', 'wxNO_BORDER',
|
||||
'wxTRANSPARENT_WINDOW', 'wxWANTS_CHARS',
|
||||
'wxNO_FULL_REPAINT_ON_RESIZE']
|
||||
|
||||
# Class that can properly disable children
|
||||
class PPanel(wxPanel):
|
||||
def __init__(self, parent, id, name):
|
||||
wxPanel.__init__(self, parent, id, name=name)
|
||||
self.modified = self.freeze = false
|
||||
def Enable(self, value):
|
||||
# Something strange is going on with enable so we make sure...
|
||||
for w in self.GetChildren():
|
||||
w.Enable(value)
|
||||
wxPanel.Enable(self, value)
|
||||
def SetModified(self):
|
||||
self.modified = true
|
||||
panel.SetModified(true)
|
||||
|
||||
class ParamBinaryOr(PPanel):
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
def __init__(self, parent, id, size, name):
|
||||
PPanel.__init__(self, parent, id, name)
|
||||
self.ID_TEXT_CTRL = wxNewId()
|
||||
self.ID_BUTTON_CHOICES = wxNewId()
|
||||
self.SetBackgroundColour(panel.GetBackgroundColour())
|
||||
sizer = wxBoxSizer()
|
||||
self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, value, size=wxSize(200,-1))
|
||||
sizer.Add(self.text, 0, wxRIGHT, 10)
|
||||
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_CHOICES, 'Edit...')
|
||||
sizer.Add(self.button)
|
||||
sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL)
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
EVT_BUTTON(self, self.ID_BUTTON_CHOICES, self.OnButtonChoices)
|
||||
EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
|
||||
def OnChange(self, evt):
|
||||
panel.SetModified(true)
|
||||
if self.freeze: return
|
||||
self.SetModified()
|
||||
evt.Skip()
|
||||
def GetValue(self):
|
||||
return self.text.GetValue()
|
||||
def SetValue(self, value):
|
||||
self.freeze = true
|
||||
self.text.SetValue(value)
|
||||
self.freeze = false
|
||||
def OnButtonChoices(self, evt):
|
||||
dlg = wxDialog(self, -1, 'Choices')
|
||||
topSizer = wxBoxSizer(wxVERTICAL)
|
||||
@@ -63,7 +76,7 @@ class ParamBinaryOr(PPanel):
|
||||
if self.equal.has_key(i):
|
||||
listBox.Check(self.values.index(self.equal[i]))
|
||||
else:
|
||||
print 'Unknown flag: %s: ignored.' % i
|
||||
print 'WARNING: unknown flag: %s: ignored.' % i
|
||||
ignored.append(i)
|
||||
topSizer.Add(listBox, 1, wxEXPAND)
|
||||
sizer = wxBoxSizer()
|
||||
@@ -77,15 +90,16 @@ class ParamBinaryOr(PPanel):
|
||||
dlg.SetSizer(topSizer)
|
||||
topSizer.Fit(dlg)
|
||||
dlg.Center()
|
||||
if dlg.ShowModal() != wxID_OK: return
|
||||
value = []
|
||||
for i in range(listBox.Number()):
|
||||
if listBox.IsChecked(i):
|
||||
value.append(self.values[i])
|
||||
# Add ignored flags
|
||||
value.extend(ignored)
|
||||
self.SetValue(reduce(lambda a,b: a+'|'+b, value))
|
||||
panel.SetModified(true)
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
value = []
|
||||
for i in range(listBox.Number()):
|
||||
if listBox.IsChecked(i):
|
||||
value.append(self.values[i])
|
||||
# Add ignored flags
|
||||
value.extend(ignored)
|
||||
self.SetValue(reduce(lambda a,b: a+'|'+b, value))
|
||||
self.SetModified()
|
||||
dlg.Destroy()
|
||||
|
||||
class ParamFlag(ParamBinaryOr):
|
||||
values = ['wxTOP', 'wxBOTTOM', 'wxLEFT', 'wxRIGHT', 'wxALL',
|
||||
@@ -95,58 +109,66 @@ class ParamFlag(ParamBinaryOr):
|
||||
equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE',
|
||||
'wxALIGN_CENTER_VERTICAL': 'wxALIGN_CENTRE_VERTICAL',
|
||||
'wxALIGN_CENTER_HORIZONTAL': 'wxALIGN_CENTRE_HORIZONTAL'}
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
ParamBinaryOr.__init__(self, parent, id, value, size, name)
|
||||
def __init__(self, parent, id, size, name):
|
||||
ParamBinaryOr.__init__(self, parent, id, size, name)
|
||||
|
||||
class ParamStyle(ParamBinaryOr):
|
||||
equal = {'wxALIGN_CENTER': 'wxALIGN_CENTRE'}
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
|
||||
self.values = currentXXX.winStyles + genericStyles
|
||||
ParamBinaryOr.__init__(self, parent, id, value, size, name)
|
||||
ParamBinaryOr.__init__(self, parent, id, size, name)
|
||||
|
||||
class ParamNonGenericStyle(ParamBinaryOr):
|
||||
def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
|
||||
self.values = currentXXX.winStyles
|
||||
ParamBinaryOr.__init__(self, parent, id, size, name)
|
||||
|
||||
class ParamExStyle(ParamBinaryOr):
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
|
||||
if currentXXX:
|
||||
self.values = currentXXX.exStyles # constant at the moment
|
||||
else:
|
||||
self.values = []
|
||||
ParamBinaryOr.__init__(self, parent, id, value, size, name)
|
||||
ParamBinaryOr.__init__(self, parent, id, size, name)
|
||||
|
||||
class ParamColour(PPanel):
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
|
||||
PPanel.__init__(self, parent, id, name)
|
||||
self.ID_TEXT_CTRL = wxNewId()
|
||||
self.ID_BUTTON = wxNewId()
|
||||
self.SetBackgroundColour(panel.GetBackgroundColour())
|
||||
sizer = wxBoxSizer()
|
||||
self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, str(value), size=wxSize(60,-1))
|
||||
sizer.Add(self.text, 0, wxGROW | wxRIGHT, 10)
|
||||
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
|
||||
self.SetValue(value)
|
||||
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
|
||||
self.button.SetBackgroundColour(wxNamedColour(value))
|
||||
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):
|
||||
panel.SetModified(true)
|
||||
if self.freeze: return
|
||||
self.SetModified()
|
||||
self.textModified = true
|
||||
evt.Skip()
|
||||
def OnPaintButton(self, evt):
|
||||
dc = wxPaintDC(self.button)
|
||||
dc.SetBrush(wxTRANSPARENT_BRUSH)
|
||||
if panel.page2.IsEnabled() and self.IsEnabled(): dc.SetPen(wxBLACK_PEN)
|
||||
if self.IsEnabled(): dc.SetPen(wxBLACK_PEN)
|
||||
else: dc.SetPen(wxGREY_PEN)
|
||||
size = self.button.GetSize()
|
||||
dc.DrawRectangle(0, 0, size.x, size.y)
|
||||
@@ -154,7 +176,9 @@ class ParamColour(PPanel):
|
||||
dlg = wxColourDialog(self)
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
self.SetValue('#%02X%02X%02X' % dlg.GetColourData().GetColour().Get())
|
||||
panel.SetModified(true)
|
||||
self.SetModified()
|
||||
self.textModified = false
|
||||
dlg.Destroy()
|
||||
|
||||
################################################################################
|
||||
|
||||
@@ -173,16 +197,16 @@ fontStylesXml2wx = ReverseMap(fontStylesWx2Xml)
|
||||
fontWeightsXml2wx = ReverseMap(fontWeightsWx2Xml)
|
||||
|
||||
class ParamFont(PPanel):
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
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, str(value), size=wxSize(200,-1))
|
||||
sizer.Add(self.text, 0, wxRIGHT, 10)
|
||||
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)
|
||||
sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL)
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
@@ -190,7 +214,8 @@ class ParamFont(PPanel):
|
||||
EVT_BUTTON(self, self.ID_BUTTON_SELECT, self.OnButtonSelect)
|
||||
EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
|
||||
def OnChange(self, evt):
|
||||
panel.SetModified(true)
|
||||
if self.freeze: return
|
||||
self.SetModified()
|
||||
self.textModified = true
|
||||
evt.Skip()
|
||||
def GetValue(self):
|
||||
@@ -198,9 +223,11 @@ class ParamFont(PPanel):
|
||||
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())
|
||||
@@ -224,26 +251,27 @@ class ParamFont(PPanel):
|
||||
data = wxFontData()
|
||||
data.SetInitialFont(font)
|
||||
dlg = wxFontDialog(self, data)
|
||||
if dlg.ShowModal() != wxID_OK: return
|
||||
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)
|
||||
panel.SetModified(true)
|
||||
self.textModified = false
|
||||
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, value, size, name):
|
||||
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, value, size=wxSize(50,-1))
|
||||
self.spin = wxSpinCtrl(self, self.ID_SPIN_CTRL, size=wxSize(50,-1))
|
||||
self.SetBackgroundColour(panel.GetBackgroundColour())
|
||||
sizer.Add(self.spin)
|
||||
self.SetAutoLayout(true)
|
||||
@@ -253,35 +281,46 @@ class ParamInt(PPanel):
|
||||
def GetValue(self):
|
||||
return str(self.spin.GetValue())
|
||||
def SetValue(self, value):
|
||||
self.freeze = true
|
||||
if not value: value = 0
|
||||
self.spin.SetValue(int(value))
|
||||
self.freeze = false
|
||||
def OnChange(self, evt):
|
||||
panel.SetModified(true)
|
||||
if self.freeze: return
|
||||
self.SetModified()
|
||||
evt.Skip()
|
||||
|
||||
class ParamText(wxTextCtrl):
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
wxTextCtrl.__init__(self, parent, id, value, size=wxSize(200,-1), name=name)
|
||||
EVT_TEXT(self, id, self.OnChange)
|
||||
class ParamText(PPanel):
|
||||
def __init__(self, parent, id = -1, size = wxDefaultSize, name = '', textWidth=200):
|
||||
PPanel.__init__(self, parent, id, name)
|
||||
self.ID_TEXT_CTRL = wxNewId()
|
||||
# We use sizer even here to have the same size of text control
|
||||
sizer = wxBoxSizer()
|
||||
self.SetBackgroundColour(panel.GetBackgroundColour())
|
||||
self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, size=wxSize(textWidth,-1))
|
||||
sizer.Add(self.text, 0, wxALIGN_CENTER_VERTICAL)
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
|
||||
def GetValue(self):
|
||||
return self.text.GetValue()
|
||||
def SetValue(self, value):
|
||||
self.freeze = true # disable other handlers
|
||||
self.text.SetValue(value)
|
||||
self.freeze = false # disable other handlers
|
||||
def OnChange(self, evt):
|
||||
panel.SetModified(true)
|
||||
if self.freeze: return
|
||||
self.SetModified()
|
||||
evt.Skip()
|
||||
|
||||
class ParamAccel(wxTextCtrl):
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
wxTextCtrl.__init__(self, parent, id, value, size=wxSize(50,-1), name=name)
|
||||
EVT_TEXT(self, id, self.OnChange)
|
||||
def OnChange(self, evt):
|
||||
panel.SetModified(true)
|
||||
evt.Skip()
|
||||
class ParamAccel(ParamText):
|
||||
def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
|
||||
ParamText.__init__(self, parent, id, size, name, 50)
|
||||
|
||||
class ParamPosSize(wxTextCtrl):
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
wxTextCtrl.__init__(self, parent, id, value, size=wxSize(80,-1), name=name)
|
||||
EVT_TEXT(self, id, self.OnChange)
|
||||
def OnChange(self, evt):
|
||||
panel.SetModified(true)
|
||||
evt.Skip()
|
||||
class ParamPosSize(ParamText):
|
||||
def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
|
||||
ParamText.__init__(self, parent, id, size, name, 80)
|
||||
|
||||
class ContentDialog(wxDialog):
|
||||
def __init__(self, parent, value):
|
||||
@@ -339,16 +378,16 @@ class ContentDialog(wxDialog):
|
||||
self.list.GetSelection() < self.list.Number() - 1)
|
||||
|
||||
class ParamContent(PPanel):
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
|
||||
PPanel.__init__(self, parent, id, name)
|
||||
self.ID_TEXT_CTRL = wxNewId()
|
||||
self.ID_BUTTON_EDIT = wxNewId()
|
||||
self.SetBackgroundColour(panel.GetBackgroundColour())
|
||||
sizer = wxBoxSizer()
|
||||
self.text = wxTextCtrl(self, self.ID_TEXT_CTRL, str(value), size=wxSize(200,-1))
|
||||
sizer.Add(self.text, 0, wxRIGHT, 10)
|
||||
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_EDIT, 'Edit...')
|
||||
sizer.Add(self.button)
|
||||
sizer.Add(self.button, 0, wxALIGN_CENTER_VERTICAL)
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
@@ -356,7 +395,8 @@ class ParamContent(PPanel):
|
||||
EVT_BUTTON(self, self.ID_BUTTON_EDIT, self.OnButtonEdit)
|
||||
EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
|
||||
def OnChange(self, evt):
|
||||
panel.SetModified(true)
|
||||
if self.freeze: return
|
||||
self.SetModified()
|
||||
self.textModified = true
|
||||
evt.Skip()
|
||||
def GetValue(self):
|
||||
@@ -364,58 +404,58 @@ class ParamContent(PPanel):
|
||||
return eval(self.text.GetValue())
|
||||
return self.value
|
||||
def SetValue(self, value):
|
||||
self.freeze = true
|
||||
self.value = value
|
||||
self.text.SetValue(str(value)) # update text ctrl
|
||||
self.freeze = false
|
||||
def OnButtonEdit(self, evt):
|
||||
if self.textModified: # text has newer value
|
||||
self.value = eval(self.text.GetValue())
|
||||
dlg = ContentDialog(self, self.value)
|
||||
if dlg.ShowModal() != wxID_OK: return
|
||||
value = []
|
||||
for i in range(dlg.list.Number()):
|
||||
value.append(dlg.list.GetString(i))
|
||||
# Add ignored flags
|
||||
self.SetValue(value)
|
||||
panel.SetModified(true)
|
||||
self.textModified = false
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
value = []
|
||||
for i in range(dlg.list.Number()):
|
||||
value.append(dlg.list.GetString(i))
|
||||
# Add ignored flags
|
||||
self.SetValue(value)
|
||||
self.SetModified()
|
||||
self.textModified = false
|
||||
dlg.Destroy()
|
||||
|
||||
# Boxless radiobox
|
||||
class RadioBox(PPanel):
|
||||
def __init__(self, parent, id, choices,
|
||||
pos=wxDefaultPosition, size=wxDefaultSize, name='radiobox'):
|
||||
PPanel.__init__(self, parent, id, name)
|
||||
self.ID_RADIO_CHOICE = wxNewId() # economize on IDs, use names
|
||||
self.SetBackgroundColour(panel.GetBackgroundColour())
|
||||
self.choices = choices
|
||||
topSizer = wxBoxSizer()
|
||||
for i in choices:
|
||||
topSizer.Add(wxRadioButton(self, self.ID_RADIO_CHOICE, i, name=i))
|
||||
button = wxRadioButton(self, -1, i, name=i)
|
||||
topSizer.Add(button)
|
||||
EVT_RADIOBUTTON(self, button.GetId(), self.OnRadioChoice)
|
||||
self.SetAutoLayout(true)
|
||||
self.SetSizer(topSizer)
|
||||
topSizer.Fit(self)
|
||||
EVT_RADIOBUTTON(self, self.ID_RADIO_CHOICE, self.OnRadioChoice)
|
||||
def SetStringSelection(self, value):
|
||||
self.value = None
|
||||
self.freeze = true
|
||||
for i in self.choices:
|
||||
w = self.FindWindowByName(i)
|
||||
w.SetValue(i == value)
|
||||
self.FindWindowByName(i).SetValue(i == value)
|
||||
self.value = value
|
||||
self.freeze = false
|
||||
def OnRadioChoice(self, evt):
|
||||
if not self.value: # procedure call
|
||||
evt.Skip()
|
||||
return
|
||||
self.FindWindowByName(self.value).SetValue(false)
|
||||
self.value = evt.GetEventObject().GetName()
|
||||
panel.SetModified(true)
|
||||
if self.freeze: return
|
||||
if evt.GetSelection():
|
||||
self.value = evt.GetEventObject().GetName()
|
||||
self.SetModified()
|
||||
def GetStringSelection(self):
|
||||
return self.value
|
||||
|
||||
class ParamBool(RadioBox):
|
||||
values = {'yes': '1', 'no': '0'}
|
||||
seulav = {'1': 'yes', '0': 'no'}
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
|
||||
RadioBox.__init__(self, parent, id, choices = self.values.keys(), name=name)
|
||||
self.SetValue(value)
|
||||
def GetValue(self):
|
||||
return self.values[self.GetStringSelection()]
|
||||
def SetValue(self, value):
|
||||
@@ -425,15 +465,59 @@ class ParamBool(RadioBox):
|
||||
class ParamOrient(RadioBox):
|
||||
values = {'horizontal': 'wxHORIZONTAL', 'vertical': 'wxVERTICAL'}
|
||||
seulav = {'wxHORIZONTAL': 'horizontal', 'wxVERTICAL': 'vertical'}
|
||||
def __init__(self, parent, id, value, size, name):
|
||||
def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
|
||||
RadioBox.__init__(self, parent, id, choices = self.values.keys(), name=name)
|
||||
self.SetValue(value)
|
||||
def GetValue(self):
|
||||
return self.values[self.GetStringSelection()]
|
||||
def SetValue(self, value):
|
||||
if not value: value = 'wxHORIZONTAL'
|
||||
self.SetStringSelection(self.seulav[value])
|
||||
|
||||
class ParamFile(PPanel):
|
||||
def __init__(self, parent, id = -1, size = wxDefaultSize, name = ''):
|
||||
PPanel.__init__(self, parent, id, name)
|
||||
self.ID_TEXT_CTRL = wxNewId()
|
||||
self.ID_BUTTON_BROWSE = 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_BROWSE, 'Browse...')
|
||||
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_BROWSE, self.OnButtonBrowse)
|
||||
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
|
||||
self.value = value
|
||||
self.text.SetValue(value) # update text ctrl
|
||||
self.freeze = false
|
||||
def OnButtonBrowse(self, evt):
|
||||
if self.textModified: # text has newer value
|
||||
self.value = self.text.GetValue()
|
||||
dlg = wxFileDialog(self,
|
||||
defaultDir = os.path.abspath(os.path.dirname(self.value)),
|
||||
defaultFile = os.path.basename(self.value))
|
||||
if dlg.ShowModal() == wxID_OK:
|
||||
# Make relative
|
||||
common = os.path.commonprefix([frame.dataFile, dlg.GetPath()])
|
||||
self.SetValue(dlg.GetPath()[len(common):])
|
||||
self.SetModified()
|
||||
self.textModified = false
|
||||
dlg.Destroy()
|
||||
|
||||
paramDict = {
|
||||
'flag': ParamFlag,
|
||||
'style': ParamStyle, 'exstyle': ParamExStyle,
|
||||
@@ -446,6 +530,6 @@ paramDict = {
|
||||
'min': ParamInt, 'max': ParamInt,
|
||||
'fg': ParamColour, 'bg': ParamColour, 'font': ParamFont,
|
||||
'enabled': ParamBool, 'focused': ParamBool, 'hidden': ParamBool,
|
||||
'tooltip': ParamText
|
||||
'tooltip': ParamText, 'bitmap': ParamFile, 'icon': ParamFile,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user