]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/py/crust.py
Implemented xxxComment. Due to different minidom XML types (Comments
[wxWidgets.git] / wxPython / wx / py / crust.py
index 371638f60441144fde62dd976dc80a752b5c9356..df4d830f04371abd97e165a8db6b054afb4bb095 100644 (file)
@@ -35,6 +35,14 @@ class Crust(wx.SplitterWindow):
                  *args, **kwds):
         """Create Crust instance."""
         wx.SplitterWindow.__init__(self, parent, id, pos, size, style, name)
+
+        # Turn off the tab-traversal style that is automatically
+        # turned on by wx.SplitterWindow.  We do this because on
+        # Windows the event for Ctrl-Enter is stolen and used as a
+        # navigation key, but the Shell window uses it to insert lines.
+        style = self.GetWindowStyle()
+        self.SetWindowStyle(style & ~wx.TAB_TRAVERSAL)
+        
         self.shell = Shell(parent=self, introText=intro,
                            locals=locals, InterpClass=InterpClass,
                            startupScript=startupScript,
@@ -63,23 +71,54 @@ class Crust(wx.SplitterWindow):
         self.notebook.AddPage(page=self.calltip, text='Calltip')
         
         self.sessionlisting = SessionListing(parent=self.notebook)
-        self.notebook.AddPage(page=self.sessionlisting, text='Session')
+        self.notebook.AddPage(page=self.sessionlisting, text='History')
         
         self.dispatcherlisting = DispatcherListing(parent=self.notebook)
         self.notebook.AddPage(page=self.dispatcherlisting, text='Dispatcher')
+
         
-        self.SplitHorizontally(self.shell, self.notebook, -self.sashoffset)
+        # Initialize in an unsplit mode, and check later after loading
+        # settings if we should split or not.
+        self.shell.Hide()
+        self.notebook.Hide()
+        self.Initialize(self.shell)
+        self._shouldsplit = True
+        wx.CallAfter(self._CheckShouldSplit)
         self.SetMinimumPaneSize(100)
 
         self.Bind(wx.EVT_SIZE, self.SplitterOnSize)
         self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnChanged)
+        self.Bind(wx.EVT_SPLITTER_DCLICK, self.OnSashDClick)
+
+    def _CheckShouldSplit(self):
+        if self._shouldsplit:
+            self.SplitHorizontally(self.shell, self.notebook, -self.sashoffset)
+            self.lastsashpos = self.GetSashPosition()
+        else:
+            self.lastsashpos = -1
+        self.issplit = self.IsSplit()       
+
+    def ToggleTools(self):
+        """Toggle the display of the filling and other tools"""
+        if self.issplit:
+            self.Unsplit()
+        else:
+            self.SplitHorizontally(self.shell, self.notebook, -self.sashoffset)
+            self.lastsashpos = self.GetSashPosition()
+        self.issplit = self.IsSplit()
+
+    def ToolsShown(self):
+        return self.issplit
 
-    
     def OnChanged(self, event):
         """update sash offset from the bottom of the window"""
         self.sashoffset = self.GetSize().height - event.GetSashPosition()
+        self.lastsashpos = event.GetSashPosition()
         event.Skip()
-        
+
+    def OnSashDClick(self, event):
+        self.Unsplit()
+        self.issplit = False
 
     # Make the splitter expand the top window when resized
     def SplitterOnSize(self, event):
@@ -102,13 +141,17 @@ class Crust(wx.SplitterWindow):
         zoom = config.ReadInt('View/Zoom/Display', -99)
         if zoom != -99:
             self.display.SetZoom(zoom)
-
+        self.issplit = config.ReadInt('Sash/IsSplit', True)
+        if not self.issplit:
+            self._shouldsplit = False
 
     def SaveSettings(self, config):
         self.shell.SaveSettings(config)
         self.filling.SaveSettings(config)
 
-        config.WriteInt('Sash/CrustPos', self.GetSashPosition())
+        if self.lastsashpos != -1:
+            config.WriteInt('Sash/CrustPos', self.lastsashpos)
+        config.WriteInt('Sash/IsSplit', self.issplit)
         config.WriteInt('View/Zoom/Display', self.display.GetZoom())
         
 
@@ -162,6 +205,10 @@ class Calltip(wx.TextCtrl):
         self.SetBackgroundColour(wx.Colour(255, 255, 208))
         dispatcher.connect(receiver=self.display, signal='Shell.calltip')
 
+        df = self.GetFont()
+        font = wx.Font(df.GetPointSize(), wx.TELETYPE, wx.NORMAL, wx.NORMAL)
+        self.SetFont(font)
+
     def display(self, calltip):
         """Receiver for Shell.calltip signal."""
         ## self.SetValue(calltip)  # Caused refresh problem on Windows.
@@ -177,17 +224,29 @@ class SessionListing(wx.TextCtrl):
         style = (wx.TE_MULTILINE | wx.TE_READONLY |
                  wx.TE_RICH2 | wx.TE_DONTWRAP)
         wx.TextCtrl.__init__(self, parent, id, style=style)
-        dispatcher.connect(receiver=self.push, signal='Interpreter.push')
+        dispatcher.connect(receiver=self.addHistory, signal="Shell.addHistory")
+        dispatcher.connect(receiver=self.clearHistory, signal="Shell.clearHistory")
+        dispatcher.connect(receiver=self.loadHistory, signal="Shell.loadHistory")
+
+        df = self.GetFont()
+        font = wx.Font(df.GetPointSize(), wx.TELETYPE, wx.NORMAL, wx.NORMAL)
+        self.SetFont(font)
+
+    def loadHistory(self, history):
+        # preload the existing history, if any
+        hist = history[:]
+        hist.reverse()
+        self.SetValue('\n'.join(hist) + '\n')
+        self.SetInsertionPointEnd()
 
-    def push(self, command, more):
-        """Receiver for Interpreter.push signal."""
-        if command and not more:
+    def addHistory(self, command):
+        if command:
             self.SetInsertionPointEnd()
-            start, end = self.GetSelection()
-            if start != end:
-                self.SetSelection(0, 0)
             self.AppendText(command + '\n')
 
+    def clearHistory(self):
+        self.SetValue("")
+
 
 class DispatcherListing(wx.TextCtrl):
     """Text control containing all dispatches for session."""
@@ -198,6 +257,10 @@ class DispatcherListing(wx.TextCtrl):
         wx.TextCtrl.__init__(self, parent, id, style=style)
         dispatcher.connect(receiver=self.spy)
 
+        df = self.GetFont()
+        font = wx.Font(df.GetPointSize(), wx.TELETYPE, wx.NORMAL, wx.NORMAL)
+        self.SetFont(font)
+
     def spy(self, signal, sender):
         """Receiver for Any signal from Any sender."""
         text = '%r from %s' % (signal, sender)
@@ -279,6 +342,13 @@ class CrustFrame(frame.Frame, frame.ShellFrameMixin):
         dialog.Destroy()
 
 
+    def ToggleTools(self):
+        """Toggle the display of the filling and other tools"""
+        return self.crust.ToggleTools()
+
+    def ToolsShown(self):
+        return self.crust.ToolsShown()
+
     def OnHelp(self, event):
         """Show a help dialog."""
         frame.ShellFrameMixin.OnHelp(self, event)