]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/tools/XRCed/xrced.py
regenerated after wxSelectDispatcher addition (patch 1618976)
[wxWidgets.git] / wxPython / wx / tools / XRCed / xrced.py
index dda3b7c5b7cedcd70eefc6ed4a725fb7321f9e53..c2a5b36dafcb31dd649c5a98fa7990681dba707b 100644 (file)
@@ -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)
@@ -339,9 +343,6 @@ class Frame(wx.Frame):
         self.SetAutoLayout(True)
         self.SetSizer(sizer)
 
-        # Initialize
-        self.Clear()
-
         # Other events
         wx.EVT_IDLE(self, self.OnIdle)
         wx.EVT_CLOSE(self, self.OnCloseWindow)
@@ -473,7 +474,18 @@ 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]
+            g.conf.allowExec = ('ask', 'yes', 'no')[dlg.radio_allow_exec.GetSelection()]
+        dlg.Destroy()
         
     def OnExit(self, evt):
         self.Close()
@@ -482,10 +494,14 @@ class Frame(wx.Frame):
         # Extra check to not mess with idle updating
         if undoMan.CanUndo():
             undoMan.Undo()
+            g.panel.SetModified(False)
+            if not undoMan.CanUndo():
+                self.SetModified(False)
 
     def OnRedo(self, evt):
         if undoMan.CanRedo():
             undoMan.Redo()
+            self.SetModified(True)
 
     def OnCopy(self, evt):
         selected = tree.selection
@@ -1355,13 +1371,11 @@ Homepage: http://xrced.sourceforge.net\
                 conf.panelWidth, conf.panelHeight = self.miniFrame.GetSize()
         evt.Skip()
 
-
     def CreateLocalConf(self, path):
         name = os.path.splitext(path)[0]
         name += '.xcfg'
         return wx.FileConfig(localFilename=name)
 
-
     def Clear(self):
         self.dataFile = ''
         conf.localconf = None
@@ -1378,9 +1392,13 @@ Homepage: http://xrced.sourceforge.net\
                    xxxMenuBar, xxxMenu, xxxToolBar,
                    xxxWizard, xxxBitmap, xxxIcon]:
             self.maxIDs[cl] = 0
-        # Handlers
-        clearHandlers()
-        g.pullDownMenu.clearCustom()
+        # Restore handlers, menu, etc. to initial
+        setHandlers(self.handlers[:])
+        g.pullDownMenu.custom = self.custom[:]
+        # Remove modules imported from comment directives
+        map(sys.modules.pop, [m for m in sys.modules if m not in self.modules])
+        xxxParamComment.locals = {}     # clear local namespace
+        xxxParamComment.allow = None    # clear execution state
 
     def SetModified(self, state=True):
         self.modified = state
@@ -1498,9 +1516,6 @@ Homepage: http://xrced.sourceforge.net\
             return True
         return False
 
-    def SaveUndo(self):
-        pass                            # !!!
-
 ################################################################################
 
 class PythonOptions(wx.Dialog):
@@ -1567,9 +1582,81 @@ 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)
+
+        self.radio_allow_exec = xrc.XRCCTRL(self, 'radio_allow_exec')
+        try:
+            radio = {'ask': 0, 'yes':1, 'no':2}[g.conf.allowExec]
+        except KeyError:
+            radio = 0
+        self.radio_allow_exec.SetSelection(radio)
+
+    def OnCheck(self, evt):
+        self.checkControls[evt.GetId()][0].Enable(evt.IsChecked())
+        evt.Skip()
+
+################################################################################
+
+# Parse string in form var1=val1[,var2=val2]* as dictionary
+def ReadDictFromString(s):
+    d = {}
+    for vv in s.split(','):
+        var,val = vv.split(':')
+        d[var.strip()] = val
+    return d
+
+# Transform dictionary with strings into one string
+def DictToString(d):
+    return ','.join(map(':'.join, d.items()))
+
 def usage():
     print >> sys.stderr, 'usage: xrced [-dhiv] [file]'
 
@@ -1626,11 +1713,46 @@ Please upgrade wxWidgets to %d.%d.%d or higher.''' % MinWxVersion)
         conf.panelWidth = conf.ReadInt('panelWidth', 200)
         conf.panelHeight = conf.ReadInt('panelHeight', 200)
         conf.panic = not conf.HasEntry('nopanic')
+        # Preferences
+        conf.allowExec = conf.Read('Prefs/allowExec', 'ask')
+        p = 'Prefs/sizeritem_defaults_panel'
+        if conf.HasEntry(p):
+            sys.modules['xxx'].xxxSizerItem.defaults_panel = ReadDictFromString(conf.Read(p))
+        p = 'Prefs/sizeritem_defaults_control'
+        if conf.HasEntry(p):
+            sys.modules['xxx'].xxxSizerItem.defaults_control = ReadDictFromString(conf.Read(p))
+
         # Add handlers
         wx.FileSystem.AddHandler(wx.MemoryFSHandler())
         # Create main frame
         frame = Frame(pos, size)
         frame.Show(True)
+        
+        # Load plugins
+        plugins = os.getenv('XRCEDPATH')
+        if plugins:
+            cwd = os.getcwd()
+            try:
+                for dir in plugins.split(':'):
+                    if os.path.isdir(dir) and \
+                       os.path.isfile(os.path.join(dir, '__init__.py')):
+                        # Normalize
+                        dir = os.path.abspath(os.path.normpath(dir))
+                        sys.path = sys_path + [os.path.dirname(dir)]
+                        try:
+                            os.chdir(dir)
+                            __import__(os.path.basename(dir), globals(), locals(), ['*'])
+                        except:
+                            print traceback.print_exc()
+            finally:
+                os.chdir(cwd)
+        # Store important data
+        frame.handlers = getHandlers()[:]
+        frame.custom = g.pullDownMenu.custom[:]
+        frame.modules = set(sys.modules.keys())
+
+        # Initialize
+        frame.Clear()
 
         # Load file after showing
         if args:
@@ -1656,8 +1778,16 @@ Please upgrade wxWidgets to %d.%d.%d or higher.''' % MinWxVersion)
         wc.WriteInt('sashPos', conf.sashPos)
         wc.WriteInt('panelWidth', conf.panelWidth)
         wc.WriteInt('panelHeight', conf.panelHeight)
-        wc.WriteInt('nopanic', True)
+        wc.WriteInt('nopanic', 1)
         wc.Write('recentFiles', '|'.join(conf.recentfiles.values()[-5:]))
+        # Preferences
+        wc.DeleteGroup('Prefs')
+        wc.Write('Prefs/allowExec', conf.allowExec)
+        v = sys.modules['xxx'].xxxSizerItem.defaults_panel
+        if v: wc.Write('Prefs/sizeritem_defaults_panel', DictToString(v))
+        v = sys.modules['xxx'].xxxSizerItem.defaults_control
+        if v: wc.Write('Prefs/sizeritem_defaults_control', DictToString(v))
+        
         wc.Flush()
 
 def main():