Preferences for default "sizeritem" parameters for new panels and
controls can be configured ("File">"Preferences..."). Implemented comment object for including simple one-line comments and comment directives as tree nodes. No validation is performed for a valid XML string so comments must not contain "-->". Comment directive is a special comment starting with '%' character, followed by a line of python code. It is executed using 'exec' when the resource file is opened. This is useful to import plugin modules containing custom handlers which are specific to the resource file, hovewer this is of course a security hole if you use foreign XRC files. A warning is displayed if the preference option 'ask' is selected (by default). Added support for custom controls and plugin modules. Refer to this wxPythonWiki for the details: http://wiki.wxpython.org/index.cgi/XRCed#custom Tool panel sections can be collapsed/expanded by clicking on the label of a tool group. Some undo/redo and other fixes. Fixes for wxMSW (notebook highlighting, control sizes, tree Unselect). Notebook page highlighting fix. Highlight resizes when the window is resized. ParamUnit spin button detects event handler re-entry (wxGTK probably has a bug in wxSpinButton with repeated events). Fix for dealing with empty 'growable' property, using MiniFrame for properties panel, the panel is restored together with the main window. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@44949 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -25,7 +25,10 @@ genericExStyles = [
|
||||
'wxWS_EX_PROCESS_UI_UPDATES'
|
||||
]
|
||||
|
||||
buttonSize = (35,-1) # in dialog units, transformed to pixels in panel ctor
|
||||
# Global var initialized in Panel.__init__ for button size in screen pixels
|
||||
buttonSize = None
|
||||
# Button size in dialog units
|
||||
buttonSizeD = (35,-1)
|
||||
|
||||
# Class that can properly disable children
|
||||
class PPanel(wx.Panel):
|
||||
@@ -33,13 +36,14 @@ class PPanel(wx.Panel):
|
||||
wx.Panel.__init__(self, parent, -1, name=name)
|
||||
self.modified = self.freeze = False
|
||||
def Enable(self, value):
|
||||
self.enabled = value
|
||||
# Something strange is going on with enable so we make sure...
|
||||
for w in self.GetChildren():
|
||||
w.Enable(value)
|
||||
#wx.Panel.Enable(self, value)
|
||||
def SetModified(self):
|
||||
self.modified = True
|
||||
g.panel.SetModified(True)
|
||||
def SetModified(self, state=True):
|
||||
self.modified = state
|
||||
if state: g.panel.SetModified(True)
|
||||
# Common method to set modified state
|
||||
def OnChange(self, evt):
|
||||
if self.freeze: return
|
||||
@@ -56,9 +60,7 @@ class ParamBinaryOr(PPanel):
|
||||
sizer.Add(self.text, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
self.button = wx.Button(self, self.ID_BUTTON_CHOICES, 'Edit...', size=buttonSize)
|
||||
sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
wx.EVT_BUTTON(self, self.ID_BUTTON_CHOICES, self.OnButtonChoices)
|
||||
wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
|
||||
def GetValue(self):
|
||||
@@ -191,9 +193,7 @@ class ParamColour(PPanel):
|
||||
sizer.Add(self.text, 0, wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.BOTTOM, 2)
|
||||
self.button = wx.Panel(self, self.ID_BUTTON, wx.DefaultPosition, wx.Size(20, 20))
|
||||
sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT, 5)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
self.textModified = False
|
||||
wx.EVT_PAINT(self.button, self.OnPaintButton)
|
||||
wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
|
||||
@@ -253,9 +253,7 @@ class ParamFont(PPanel):
|
||||
sizer.Add(self.text, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
self.button = wx.Button(self, self.ID_BUTTON_SELECT, 'Select...', size=buttonSize)
|
||||
sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
self.textModified = False
|
||||
wx.EVT_BUTTON(self, self.ID_BUTTON_SELECT, self.OnButtonSelect)
|
||||
wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
|
||||
@@ -320,7 +318,6 @@ class ParamFont(PPanel):
|
||||
dlg = wx.FontDialog(self, data)
|
||||
if dlg.ShowModal() == wx.ID_OK:
|
||||
font = dlg.GetFontData().GetChosenFont()
|
||||
print font.GetEncoding()
|
||||
if font.GetEncoding() == wx.FONTENCODING_SYSTEM:
|
||||
encName = ''
|
||||
else:
|
||||
@@ -348,9 +345,7 @@ class ParamInt(PPanel):
|
||||
self.spin = wx.SpinCtrl(self, self.ID_SPIN_CTRL, size=(60,-1))
|
||||
self.spin.SetRange(-2147483648, 2147483647) # min/max integers
|
||||
sizer.Add(self.spin)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
wx.EVT_SPINCTRL(self, self.ID_SPIN_CTRL, self.OnChange)
|
||||
def GetValue(self):
|
||||
return str(self.spin.GetValue())
|
||||
@@ -369,9 +364,7 @@ class ParamIntNN(PPanel):
|
||||
self.spin = wx.SpinCtrl(self, self.ID_SPIN_CTRL, size=(60,-1))
|
||||
self.spin.SetRange(0, 10000) # min/max integers
|
||||
sizer.Add(self.spin)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
wx.EVT_SPINCTRL(self, self.ID_SPIN_CTRL, self.OnChange)
|
||||
def GetValue(self):
|
||||
return str(self.spin.GetValue())
|
||||
@@ -388,26 +381,23 @@ class ParamUnit(PPanel):
|
||||
self.ID_TEXT_CTRL = wx.NewId()
|
||||
self.ID_SPIN_BUTTON = wx.NewId()
|
||||
sizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
self.spin = wx.SpinButton(self, self.ID_SPIN_BUTTON, style = wx.SP_VERTICAL, size=(-1,1))
|
||||
self.spin = wx.SpinButton(self, self.ID_SPIN_BUTTON, style = wx.SP_VERTICAL, size=(-1,0))
|
||||
textW = 60 - self.spin.GetSize()[0]
|
||||
self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=(textW,-1))
|
||||
self.spin.SetRange(-10000, 10000)
|
||||
sizer.Add(self.text, 0, wx.EXPAND)
|
||||
sizer.Add(self.spin, 0, wx.EXPAND)
|
||||
#sizer.SetMinSize((50,-1))
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
wx.EVT_SPIN_UP(self, self.ID_SPIN_BUTTON, self.OnSpinUp)
|
||||
wx.EVT_SPIN_DOWN(self, self.ID_SPIN_BUTTON, self.OnSpinDown)
|
||||
self.spin.Bind(wx.EVT_SPIN_UP, self.OnSpinUp)
|
||||
self.spin.Bind(wx.EVT_SPIN_DOWN, self.OnSpinDown)
|
||||
def GetValue(self):
|
||||
return self.text.GetValue()
|
||||
def SetValue(self, value):
|
||||
self.freeze = True
|
||||
if not value: value = '0'
|
||||
if not value: value = '0'
|
||||
self.text.SetValue(value)
|
||||
self.freeze = False
|
||||
self.Change(0)
|
||||
def Change(self, x):
|
||||
self.freeze = True
|
||||
# Check if we are working with dialog units
|
||||
value = self.text.GetValue()
|
||||
units = ''
|
||||
@@ -417,14 +407,19 @@ class ParamUnit(PPanel):
|
||||
try:
|
||||
intValue = int(value) + x
|
||||
self.spin.SetValue(intValue)
|
||||
self.text.SetValue(str(intValue) + units)
|
||||
self.SetModified()
|
||||
if x: # 0 can be passed to update spin value only
|
||||
self.text.SetValue(str(intValue) + units)
|
||||
self.SetModified()
|
||||
except:
|
||||
# !!! Strange, if I use wx.LogWarning, event is re-generated
|
||||
print 'incorrect unit format'
|
||||
print 'ERROR: incorrect unit format'
|
||||
self.freeze = False
|
||||
def OnSpinUp(self, evt):
|
||||
self.freeze = True
|
||||
self.Change(1)
|
||||
def OnSpinDown(self, evt):
|
||||
if self.freeze: return
|
||||
self.freeze = True
|
||||
self.Change(-1)
|
||||
|
||||
class ParamMultilineText(PPanel):
|
||||
@@ -437,9 +432,7 @@ class ParamMultilineText(PPanel):
|
||||
sizer.Add(self.text, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
self.button = wx.Button(self, self.ID_BUTTON_EDIT, 'Edit...', size=buttonSize)
|
||||
sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
self.SetSizerAndFit(sizer)
|
||||
wx.EVT_BUTTON(self, self.ID_BUTTON_EDIT, self.OnButtonEdit)
|
||||
wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
|
||||
def GetValue(self):
|
||||
@@ -458,18 +451,16 @@ class ParamMultilineText(PPanel):
|
||||
dlg.Destroy()
|
||||
|
||||
class ParamText(PPanel):
|
||||
def __init__(self, parent, name, textWidth=-1):
|
||||
def __init__(self, parent, name, textWidth=-1, style=0):
|
||||
PPanel.__init__(self, parent, name)
|
||||
self.ID_TEXT_CTRL = wx.NewId()
|
||||
# We use sizer even here to have the same size of text control
|
||||
sizer = wx.BoxSizer()
|
||||
self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=wx.Size(textWidth,-1))
|
||||
self.text = wx.TextCtrl(self, self.ID_TEXT_CTRL, size=wx.Size(textWidth,-1), style=style)
|
||||
if textWidth == -1: option = 1
|
||||
else: option = 0
|
||||
sizer.Add(self.text, option, wx.ALIGN_CENTER_VERTICAL | wx.TOP | wx.BOTTOM, 2)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
|
||||
def GetValue(self):
|
||||
return self.text.GetValue()
|
||||
@@ -494,6 +485,11 @@ class ParamEncoding(ParamText):
|
||||
def __init__(self, parent, name):
|
||||
ParamText.__init__(self, parent, name, 100)
|
||||
|
||||
class ParamComment(ParamText):
|
||||
def __init__(self, parent, name):
|
||||
ParamText.__init__(self, parent, name, 330 + buttonSize[0],
|
||||
style=wx.TE_PROCESS_ENTER)
|
||||
|
||||
class ContentDialog(wx.Dialog):
|
||||
def __init__(self, parent, value):
|
||||
# Load from resource
|
||||
@@ -612,9 +608,7 @@ class ParamContent(PPanel):
|
||||
sizer.Add(self.text, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
self.button = wx.Button(self, self.ID_BUTTON_EDIT, 'Edit...', size=buttonSize)
|
||||
sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
self.textModified = False
|
||||
wx.EVT_BUTTON(self, self.ID_BUTTON_EDIT, self.OnButtonEdit)
|
||||
wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
|
||||
@@ -625,8 +619,7 @@ class ParamContent(PPanel):
|
||||
if self.textModified: # text has newer value
|
||||
try:
|
||||
return self.text.GetValue().split('|')
|
||||
except SyntaxError:
|
||||
wx.LogError('Syntax error in parameter value: ' + self.GetName())
|
||||
except ValueError:
|
||||
return []
|
||||
return self.value
|
||||
def SetValue(self, value):
|
||||
@@ -648,6 +641,9 @@ class ParamContent(PPanel):
|
||||
self.SetModified()
|
||||
self.textModified = False
|
||||
dlg.Destroy()
|
||||
def SetModified(self, state=True):
|
||||
PPanel.SetModified(self, state)
|
||||
self.textModified = False
|
||||
|
||||
# CheckList content
|
||||
class ParamContentCheckList(ParamContent):
|
||||
@@ -728,8 +724,7 @@ class ParamIntList(ParamContent):
|
||||
if self.textModified: # text has newer value
|
||||
try:
|
||||
self.value = map(int, self.text.GetValue().split('|'))
|
||||
except SyntaxError:
|
||||
wx.LogError('Syntax error in parameter value: ' + self.GetName())
|
||||
except ValueError:
|
||||
self.value = []
|
||||
dlg = IntListDialog(self, self.value)
|
||||
if dlg.ShowModal() == wx.ID_OK:
|
||||
@@ -752,9 +747,7 @@ class RadioBox(PPanel):
|
||||
button = wx.RadioButton(self, -1, i, size=(-1,buttonSize[1]), name=i)
|
||||
topSizer.Add(button, 0, wx.RIGHT, 5)
|
||||
wx.EVT_RADIOBUTTON(self, button.GetId(), self.OnRadioChoice)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(topSizer)
|
||||
topSizer.Fit(self)
|
||||
def SetStringSelection(self, value):
|
||||
self.freeze = True
|
||||
for i in self.choices:
|
||||
@@ -812,9 +805,7 @@ class ParamFile(PPanel):
|
||||
sizer.Add(self.text, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 5)
|
||||
self.button = wx.Button(self, self.ID_BUTTON_BROWSE, 'Browse...',size=buttonSize)
|
||||
sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL)
|
||||
self.SetAutoLayout(True)
|
||||
self.SetSizer(sizer)
|
||||
sizer.Fit(self)
|
||||
self.textModified = False
|
||||
wx.EVT_BUTTON(self, self.ID_BUTTON_BROWSE, self.OnButtonBrowse)
|
||||
wx.EVT_TEXT(self, self.ID_TEXT_CTRL, self.OnChange)
|
||||
@@ -941,5 +932,6 @@ paramDict = {
|
||||
'fg': ParamColour, 'bg': ParamColour, 'font': ParamFont,
|
||||
'enabled': ParamBool, 'focused': ParamBool, 'hidden': ParamBool,
|
||||
'tooltip': ParamText, 'bitmap': ParamBitmap, 'icon': ParamBitmap,
|
||||
'encoding': ParamEncoding, 'borders': ParamUnit
|
||||
'encoding': ParamEncoding, 'borders': ParamUnit,
|
||||
'comment': ParamComment
|
||||
}
|
||||
|
Reference in New Issue
Block a user