[Python-checkins] r65405 - sandbox/trunk/ttk-gsoc/src/idlelib/OutputWindow.py

guilherme.polo python-checkins at python.org
Sat Aug 2 15:19:29 CEST 2008


Author: guilherme.polo
Date: Sat Aug  2 15:19:29 2008
New Revision: 65405

Log:
Removed unused classes, erradicated the dependency of self.text here

Modified:
   sandbox/trunk/ttk-gsoc/src/idlelib/OutputWindow.py

Modified: sandbox/trunk/ttk-gsoc/src/idlelib/OutputWindow.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/OutputWindow.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/OutputWindow.py	Sat Aug  2 15:19:29 2008
@@ -4,6 +4,11 @@
 import IOBinding
 from EditorWindow import EditorWindow
 
+def _callback(func, *myargs):
+    def w(*args):
+        return func(*(args + myargs))
+    return w
+
 class OutputWindow(EditorWindow):
 
     """An editor window that can serve as an output file.
@@ -14,7 +19,14 @@
 
     def __init__(self, *args):
         EditorWindow.__init__(self, *args)
-        self.text.bind("<<goto-file-line>>", self.goto_file_line)
+        self.top.bind("<<tab-created>>", self.__configure_new_tab)
+        # configure the tab created in EditorWindow.__init__
+        self.__configure_new_tab() 
+
+    def __configure_new_tab(self, event=None):
+        page = self.text_notebook.last_page().editpage
+        page.text.bind("<<goto-file-line>>", _callback(self.goto_file_line,
+            page.text))
 
     # Customize EditorWindow
 
@@ -34,7 +46,8 @@
 
     # Act as output file
 
-    def write(self, s, tags=(), mark="insert"):
+    def write(self, s, tags=(), mark="insert", text=None):
+        assert text is not None
         # Tk assumes that byte strings are Latin-1;
         # we assume that they are in the locale's encoding
         if isinstance(s, str):
@@ -43,12 +56,12 @@
             except UnicodeError:
                 # some other encoding; let Tcl deal with it
                 pass
-        self.text.insert(mark, s, tags)
-        self.text.see(mark)
-        self.text.update()
+        text.insert(mark, s, tags)
+        text.see(mark)
+        text.update()
 
     def writelines(self, l):
-        map(self.write, l)
+        map(self.write, l, text=self.current_page.text)
 
     def flush(self):
         pass
@@ -67,28 +80,26 @@
 
     file_line_progs = None
 
-    def goto_file_line(self, event=None):
+    def goto_file_line(self, event, text):
         if self.file_line_progs is None:
             l = []
             for pat in self.file_line_pats:
                 l.append(re.compile(pat, re.IGNORECASE))
             self.file_line_progs = l
-        # x, y = self.event.x, self.event.y
-        # self.text.mark_set("insert", "@%d,%d" % (x, y))
-        line = self.text.get("insert linestart", "insert lineend")
+        
+        line = text.get("insert linestart", "insert lineend")
         result = self._file_line_helper(line)
         if not result:
             # Try the previous line.  This is handy e.g. in tracebacks,
             # where you tend to right-click on the displayed source line
-            line = self.text.get("insert -1line linestart",
-                                 "insert -1line lineend")
+            line = text.get("insert -1line linestart", "insert -1line ineend")
             result = self._file_line_helper(line)
             if not result:
                 tkMessageBox.showerror(
                     "No special line",
                     "The line you point at doesn't look like "
                     "a valid file name followed by a line number.",
-                    master=self.text)
+                    master=text)
                 return
         filename, lineno = result
         edit = self.flist.open(filename)
@@ -111,47 +122,3 @@
             return filename, int(lineno)
         except TypeError:
             return None
-
-# These classes are currently not used but might come in handy
-
-class OnDemandOutputWindow:
-
-    tagdefs = {
-        # XXX Should use IdlePrefs.ColorPrefs
-        "stdout":  {"foreground": "blue"},
-        "stderr":  {"foreground": "#007700"},
-    }
-
-    def __init__(self, flist):
-        self.flist = flist
-        self.owin = None
-
-    def write(self, s, tags, mark):
-        if not self.owin:
-            self.setup()
-        self.owin.write(s, tags, mark)
-
-    def setup(self):
-        self.owin = owin = OutputWindow(self.flist)
-        text = owin.text
-        for tag, cnf in self.tagdefs.items():
-            if cnf:
-                text.tag_configure(tag, **cnf)
-        text.tag_raise('sel')
-        self.write = self.owin.write
-
-#class PseudoFile:
-#
-#      def __init__(self, owin, tags, mark="end"):
-#          self.owin = owin
-#          self.tags = tags
-#          self.mark = mark
-
-#      def write(self, s):
-#          self.owin.write(s, self.tags, self.mark)
-
-#      def writelines(self, l):
-#          map(self.write, l)
-
-#      def flush(self):
-#          pass


More information about the Python-checkins mailing list