Added Preferences dialog (and defaults for some parameters)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44850 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
552240ce17
commit
5050b626e5
@ -130,6 +130,9 @@ class Frame(wx.Frame):
|
||||
menu.Append(self.ID_GENERATE_PYTHON, '&Generate Python...',
|
||||
'Generate a Python module that uses this XRC')
|
||||
menu.AppendSeparator()
|
||||
self.ID_PREFS = wx.NewId()
|
||||
menu.Append(self.ID_PREFS, 'Preferences...', 'Change XRCed settings')
|
||||
menu.AppendSeparator()
|
||||
menu.Append(wx.ID_EXIT, '&Quit\tCtrl-Q', 'Exit application')
|
||||
|
||||
menuBar.Append(menu, '&File')
|
||||
@ -164,7 +167,7 @@ class Frame(wx.Frame):
|
||||
self.ID_REFRESH = wx.NewId()
|
||||
menu.Append(self.ID_REFRESH, '&Refresh\tCtrl-R', 'Refresh test window')
|
||||
self.ID_AUTO_REFRESH = wx.NewId()
|
||||
menu.Append(self.ID_AUTO_REFRESH, '&Auto-refresh\tCtrl-A',
|
||||
menu.Append(self.ID_AUTO_REFRESH, '&Auto-refresh\tAlt-A',
|
||||
'Toggle auto-refresh mode', True)
|
||||
menu.Check(self.ID_AUTO_REFRESH, conf.autoRefresh)
|
||||
self.ID_TEST_HIDE = wx.NewId()
|
||||
@ -250,6 +253,7 @@ class Frame(wx.Frame):
|
||||
wx.EVT_MENU(self, wx.ID_SAVE, self.OnSaveOrSaveAs)
|
||||
wx.EVT_MENU(self, wx.ID_SAVEAS, self.OnSaveOrSaveAs)
|
||||
wx.EVT_MENU(self, self.ID_GENERATE_PYTHON, self.OnGeneratePython)
|
||||
wx.EVT_MENU(self, self.ID_PREFS, self.OnPrefs)
|
||||
wx.EVT_MENU(self, wx.ID_EXIT, self.OnExit)
|
||||
# Edit
|
||||
wx.EVT_MENU(self, wx.ID_UNDO, self.OnUndo)
|
||||
@ -470,7 +474,17 @@ class Frame(wx.Frame):
|
||||
dlg = PythonOptions(self, conf.localconf, self.dataFile)
|
||||
dlg.ShowModal()
|
||||
dlg.Destroy()
|
||||
|
||||
|
||||
def OnPrefs(self, evt):
|
||||
dlg = PrefsDialog(self)
|
||||
if dlg.ShowModal() == wx.ID_OK:
|
||||
# Fetch new preferences
|
||||
for id,cdp in dlg.checkControls.items():
|
||||
c,d,p = cdp
|
||||
if dlg.FindWindowById(id).IsChecked():
|
||||
d[p] = str(c.GetValue())
|
||||
elif p in d: del d[p]
|
||||
dlg.Destroy()
|
||||
|
||||
def OnExit(self, evt):
|
||||
self.Close()
|
||||
@ -1568,7 +1582,60 @@ class PythonOptions(wx.Dialog):
|
||||
|
||||
self.EndModal(wx.ID_OK)
|
||||
|
||||
|
||||
################################################################################
|
||||
|
||||
class PrefsDialog(wx.Dialog):
|
||||
|
||||
def __init__(self, parent):
|
||||
pre = wx.PreDialog()
|
||||
g.frame.res.LoadOnDialog(pre, parent, "DIALOG_PREFS")
|
||||
self.PostCreate(pre)
|
||||
self.checkControls = {} # map of check IDs to (control,dict,param)
|
||||
|
||||
xxx = sys.modules['xxx']
|
||||
d = xxx.xxxSizerItem.defaults_panel
|
||||
|
||||
self.check_proportion_panel = xrc.XRCCTRL(self, 'check_proportion_panel')
|
||||
id = self.check_proportion_panel.GetId()
|
||||
wx.EVT_CHECKBOX(self, id, self.OnCheck)
|
||||
self.checkControls[id] = (xrc.XRCCTRL(self, 'spin_proportion_panel'),
|
||||
d, 'option')
|
||||
|
||||
self.check_flag_panel = xrc.XRCCTRL(self, 'check_flag_panel')
|
||||
id = self.check_flag_panel.GetId()
|
||||
wx.EVT_CHECKBOX(self, id, self.OnCheck)
|
||||
self.checkControls[id] = (xrc.XRCCTRL(self, 'text_flag_panel'),
|
||||
d, 'flag')
|
||||
|
||||
d = xxx.xxxSizerItem.defaults_control
|
||||
|
||||
self.check_proportion_panel = xrc.XRCCTRL(self, 'check_proportion_control')
|
||||
id = self.check_proportion_panel.GetId()
|
||||
wx.EVT_CHECKBOX(self, id, self.OnCheck)
|
||||
self.checkControls[id] = (xrc.XRCCTRL(self, 'spin_proportion_control'),
|
||||
d, 'option')
|
||||
|
||||
self.check_flag_panel = xrc.XRCCTRL(self, 'check_flag_control')
|
||||
id = self.check_flag_panel.GetId()
|
||||
wx.EVT_CHECKBOX(self, id, self.OnCheck)
|
||||
self.checkControls[id] = (xrc.XRCCTRL(self, 'text_flag_control'),
|
||||
d, 'flag')
|
||||
|
||||
for id,cdp in self.checkControls.items():
|
||||
c,d,p = cdp
|
||||
try:
|
||||
if isinstance(c, wx.SpinCtrl):
|
||||
c.SetValue(int(d[p]))
|
||||
else:
|
||||
c.SetValue(d[p])
|
||||
self.FindWindowById(id).SetValue(True)
|
||||
except KeyError:
|
||||
c.Enable(False)
|
||||
|
||||
def OnCheck(self, evt):
|
||||
self.checkControls[evt.GetId()][0].Enable(evt.IsChecked())
|
||||
evt.Skip()
|
||||
|
||||
################################################################################
|
||||
|
||||
# Parse string in form var1=val1[,var2=val2]* as dictionary
|
||||
@ -1706,6 +1773,7 @@ Please upgrade wxWidgets to %d.%d.%d or higher.''' % MinWxVersion)
|
||||
wc.WriteInt('nopanic', True)
|
||||
wc.Write('recentFiles', '|'.join(conf.recentfiles.values()[-5:]))
|
||||
# Preferences
|
||||
wc.DeleteGroup('Prefs')
|
||||
v = sys.modules['xxx'].xxxSizerItem.defaults_panel
|
||||
if v: wc.Write('Prefs/sizeritem_defaults_panel', DictToString(v))
|
||||
v = sys.modules['xxx'].xxxSizerItem.defaults_control
|
||||
|
@ -10,6 +10,7 @@
|
||||
<orient>wxHORIZONTAL</orient>
|
||||
<object class="sizeritem">
|
||||
<object class="wxTextCtrl" name="TEXT">
|
||||
<value></value>
|
||||
<size>250,100</size>
|
||||
<style>wxTE_MULTILINE</style>
|
||||
</object>
|
||||
@ -22,23 +23,17 @@
|
||||
<flag>wxEXPAND</flag>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStaticLine"/>
|
||||
<flag>wxEXPAND</flag>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxBoxSizer">
|
||||
<orient>wxHORIZONTAL</orient>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStdDialogButtonSizer">
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_OK">
|
||||
<label>OK</label>
|
||||
<default>1</default>
|
||||
<label></label>
|
||||
<label>&Ok</label>
|
||||
</object>
|
||||
<flag>wxRIGHT</flag>
|
||||
<border>10</border>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_CANCEL">
|
||||
<label>Cancel</label>
|
||||
<label></label>
|
||||
<label>&Cancel</label>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
@ -191,24 +186,21 @@
|
||||
<option>1</option>
|
||||
<flag>wxEXPAND</flag>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStaticLine"/>
|
||||
<flag>wxEXPAND</flag>
|
||||
<object class="spacer">
|
||||
<size>0,10</size>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxBoxSizer">
|
||||
<orient>wxHORIZONTAL</orient>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStdDialogButtonSizer">
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_OK">
|
||||
<label>OK</label>
|
||||
<default>1</default>
|
||||
<label></label>
|
||||
<label>&Ok</label>
|
||||
</object>
|
||||
<flag>wxRIGHT</flag>
|
||||
<border>10</border>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_CANCEL">
|
||||
<label>Cancel</label>
|
||||
<label></label>
|
||||
<label>&Cancel</label>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
@ -233,24 +225,21 @@
|
||||
<flag>wxALL|wxEXPAND</flag>
|
||||
<border>5</border>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStaticLine"/>
|
||||
<flag>wxEXPAND</flag>
|
||||
<object class="spacer">
|
||||
<size>0,10</size>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxBoxSizer">
|
||||
<orient>wxHORIZONTAL</orient>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStdDialogButtonSizer">
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_OK">
|
||||
<label>OK</label>
|
||||
<default>1</default>
|
||||
<label></label>
|
||||
<label>&Ok</label>
|
||||
</object>
|
||||
<flag>wxRIGHT</flag>
|
||||
<border>10</border>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_CANCEL">
|
||||
<label>Cancel</label>
|
||||
<label></label>
|
||||
<label>&Cancel</label>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
@ -261,7 +250,7 @@
|
||||
<style>wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</style>
|
||||
</object>
|
||||
<object class="wxDialog" name="DIALOG_STYLES">
|
||||
<title>Window styles</title>
|
||||
<title>Window Styles</title>
|
||||
<centered>1</centered>
|
||||
<object class="wxBoxSizer">
|
||||
<orient>wxVERTICAL</orient>
|
||||
@ -299,24 +288,21 @@
|
||||
<flag>wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND</flag>
|
||||
<border>5</border>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStaticLine"/>
|
||||
<flag>wxEXPAND</flag>
|
||||
<object class="spacer">
|
||||
<size>0,10</size>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxBoxSizer">
|
||||
<orient>wxHORIZONTAL</orient>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStdDialogButtonSizer">
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_OK">
|
||||
<label>OK</label>
|
||||
<default>1</default>
|
||||
<label></label>
|
||||
<label>&Ok</label>
|
||||
</object>
|
||||
<flag>wxRIGHT</flag>
|
||||
<border>10</border>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_CANCEL">
|
||||
<label>Cancel</label>
|
||||
<label></label>
|
||||
<label>&Cancel</label>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
@ -381,25 +367,23 @@
|
||||
</object>
|
||||
<option>1</option>
|
||||
<flag>wxEXPAND</flag>
|
||||
<border>0</border>
|
||||
</object>
|
||||
<object class="spacer">
|
||||
<size>0,10</size>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStaticLine"/>
|
||||
<flag>wxEXPAND</flag>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxBoxSizer">
|
||||
<orient>wxHORIZONTAL</orient>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStdDialogButtonSizer">
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_OK">
|
||||
<label>OK</label>
|
||||
<default>1</default>
|
||||
<label></label>
|
||||
<label>&Ok</label>
|
||||
</object>
|
||||
<flag>wxRIGHT</flag>
|
||||
<border>10</border>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_CANCEL">
|
||||
<label>Cancel</label>
|
||||
<label></label>
|
||||
<label>&Cancel</label>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
@ -619,4 +603,101 @@
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="wxDialog" name="DIALOG_PREFS">
|
||||
<title>XRCed Preferences</title>
|
||||
<object class="wxBoxSizer">
|
||||
<orient>wxVERTICAL</orient>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStaticBoxSizer">
|
||||
<label>Defaults for new containes</label>
|
||||
<orient>wxVERTICAL</orient>
|
||||
<object class="sizeritem">
|
||||
<object class="wxFlexGridSizer">
|
||||
<cols>2</cols>
|
||||
<rows>2</rows>
|
||||
<object class="sizeritem">
|
||||
<object class="wxCheckBox" name="check_proportion_panel">
|
||||
<label>proportion</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxSpinCtrl" name="spin_proportion_panel">
|
||||
<size>50,-1</size>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxCheckBox" name="check_flag_panel">
|
||||
<label>flag</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxTextCtrl" name="text_flag_panel">
|
||||
<size>150,-1</size>
|
||||
</object>
|
||||
</object>
|
||||
<hgap>10</hgap>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<flag>wxALL</flag>
|
||||
<border>5</border>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStaticBoxSizer">
|
||||
<label>Defaults for new controls</label>
|
||||
<orient>wxVERTICAL</orient>
|
||||
<object class="sizeritem">
|
||||
<object class="wxFlexGridSizer">
|
||||
<cols>2</cols>
|
||||
<rows>2</rows>
|
||||
<object class="sizeritem">
|
||||
<object class="wxCheckBox" name="check_proportion_control">
|
||||
<label>proportion</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxSpinCtrl" name="spin_proportion_control">
|
||||
<size>50,-1</size>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxCheckBox" name="check_flag_control">
|
||||
<label>flag</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxTextCtrl" name="text_flag_control">
|
||||
<size>150,-1</size>
|
||||
</object>
|
||||
</object>
|
||||
<hgap>10</hgap>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<flag>wxALL</flag>
|
||||
<border>5</border>
|
||||
</object>
|
||||
<object class="spacer">
|
||||
<size>0,10</size>
|
||||
</object>
|
||||
<object class="sizeritem">
|
||||
<object class="wxStdDialogButtonSizer">
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_OK">
|
||||
<label></label>
|
||||
<label>&Ok</label>
|
||||
</object>
|
||||
</object>
|
||||
<object class="button">
|
||||
<object class="wxButton" name="wxID_CANCEL">
|
||||
<label></label>
|
||||
<label>&Cancel</label>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<flag>wxALL|wxALIGN_CENTRE_HORIZONTAL</flag>
|
||||
<border>10</border>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</resource>
|
@ -859,7 +859,6 @@ class xxxSizerItem(xxxChildContainer):
|
||||
# Set defaults for some children types
|
||||
if isinstance(self.child, xxxContainer) and not self.child.isSizer:
|
||||
for param,v in self.defaults_panel.items():
|
||||
print param,v
|
||||
self.set(param, v)
|
||||
elif isinstance(self.child, xxxObject):
|
||||
for param,v in self.defaults_control.items():
|
||||
|
Loading…
Reference in New Issue
Block a user