From 5050b626e57ef73d12f975ddcab15faf61ad3e2b Mon Sep 17 00:00:00 2001 From: Roman Rolinsky Date: Fri, 16 Mar 2007 14:19:53 +0000 Subject: [PATCH] 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 --- wxPython/wx/tools/XRCed/xrced.py | 74 ++++++++++- wxPython/wx/tools/XRCed/xrced.xrc | 207 +++++++++++++++++++++--------- wxPython/wx/tools/XRCed/xxx.py | 1 - 3 files changed, 215 insertions(+), 67 deletions(-) diff --git a/wxPython/wx/tools/XRCed/xrced.py b/wxPython/wx/tools/XRCed/xrced.py index 70e5a3298a..c41e9592cc 100644 --- a/wxPython/wx/tools/XRCed/xrced.py +++ b/wxPython/wx/tools/XRCed/xrced.py @@ -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 diff --git a/wxPython/wx/tools/XRCed/xrced.xrc b/wxPython/wx/tools/XRCed/xrced.xrc index 16ba037d94..29601a4f97 100644 --- a/wxPython/wx/tools/XRCed/xrced.xrc +++ b/wxPython/wx/tools/XRCed/xrced.xrc @@ -10,6 +10,7 @@ wxHORIZONTAL + 250,100 @@ -22,23 +23,17 @@ wxEXPAND - - wxEXPAND - - - - wxHORIZONTAL - + + - - 1 + + - wxRIGHT - 10 - + - + + @@ -191,24 +186,21 @@ wxEXPAND - - - wxEXPAND + + 0,10 - - wxHORIZONTAL - + + - - 1 + + - wxRIGHT - 10 - + - + + @@ -233,24 +225,21 @@ wxALL|wxEXPAND 5 - - - wxEXPAND + + 0,10 - - wxHORIZONTAL - + + - - 1 + + - wxRIGHT - 10 - + - + + @@ -261,7 +250,7 @@ - Window styles + Window Styles 1 wxVERTICAL @@ -299,24 +288,21 @@ wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND 5 - - - wxEXPAND + + 0,10 - - wxHORIZONTAL - + + - - 1 + + - wxRIGHT - 10 - + - + + @@ -381,25 +367,23 @@ wxEXPAND + 0 + + + 0,10 - - wxEXPAND - - - - wxHORIZONTAL - + + - - 1 + + - wxRIGHT - 10 - + - + + @@ -619,4 +603,101 @@ + + XRCed Preferences + + wxVERTICAL + + + + wxVERTICAL + + + 2 + 2 + + + + + + + + 50,-1 + + + + + + + + + + 150,-1 + + + 10 + + + + wxALL + 5 + + + + + wxVERTICAL + + + 2 + 2 + + + + + + + + 50,-1 + + + + + + + + + + 150,-1 + + + 10 + + + + wxALL + 5 + + + 0,10 + + + + + + + + + + + + + + + + + wxALL|wxALIGN_CENTRE_HORIZONTAL + 10 + + + \ No newline at end of file diff --git a/wxPython/wx/tools/XRCed/xxx.py b/wxPython/wx/tools/XRCed/xxx.py index e1f213d44d..de19e8910b 100644 --- a/wxPython/wx/tools/XRCed/xxx.py +++ b/wxPython/wx/tools/XRCed/xxx.py @@ -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():