[Python-checkins] r65470 - in sandbox/trunk/ttk-gsoc/src/idlelib: CodeContext.py EditorWindow.py

guilherme.polo python-checkins at python.org
Mon Aug 4 03:16:25 CEST 2008


Author: guilherme.polo
Date: Mon Aug  4 03:16:25 2008
New Revision: 65470

Log:
Fixed CodeContext extension to work with tabs

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

Modified: sandbox/trunk/ttk-gsoc/src/idlelib/CodeContext.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/CodeContext.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/CodeContext.py	Mon Aug  4 03:16:25 2008
@@ -23,7 +23,7 @@
 getspacesfirstword =\
                    lambda s, c=re.compile(r"^(\s*)(\w*)"): c.match(s).groups()
 
-class CodeContext:
+class CodeContext(object):
     menudefs = [('options', [('!Code Conte_xt', '<<toggle-code-context>>')])]
     context_depth = idleConf.GetOption("extensions", "CodeContext",
                                        "numlines", type="int", default=3)
@@ -31,10 +31,10 @@
                                  "bgcolor", type="str", default="LightGray")
     fgcolor = idleConf.GetOption("extensions", "CodeContext",
                                  "fgcolor", type="str", default="Black")
-    def __init__(self, editwin):
-        self.editwin = editwin
-        self.text = editwin.text
-        self.textfont = self.text["font"]
+
+    def __init__(self, editpage):
+        self.editpage = editpage
+        self.editwin = editpage.editwin
         self.label = None
         # self.info is a list of (line number, indent level, line text, block
         # keyword) tuples providing the block structure associated with
@@ -43,14 +43,11 @@
         # starts the toplevel 'block' of the module.
         self.info = [(0, -1, "", False)]
         self.topvisible = 1
-        visible = idleConf.GetOption("extensions", "CodeContext",
-                                     "visible", type="bool", default=False)
+        visible = idleConf.GetOption("extensions", "CodeContext", "visible",
+            type="bool", default=False)
         if visible:
             self.toggle_code_context_event()
             self.editwin.setvar('<<toggle-code-context>>', True)
-        # Start two update cycles, one for context lines, one for font changes.
-        self.text.after(UPDATEINTERVAL, self.timer_event)
-        self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)
 
     def toggle_code_context_event(self, event=None):
         if not self.label:
@@ -126,15 +123,12 @@
         return lines, lastindent
 
     def update_code_context(self):
-        """Update context information and lines visible in the context pane.
-
-        """
+        """Update context information and lines visible in the context pane."""
         new_topvisible = int(self.text.index("@0,0").split('.')[0])
         if self.topvisible == new_topvisible:      # haven't scrolled
             return
         if self.topvisible < new_topvisible:       # scroll down
-            lines, lastindent = self.get_context(new_topvisible,
-                                                 self.topvisible)
+            lines, lastindent = self.get_context(new_topvisible, self.topvisible)
             # retain only context info applicable to the region
             # between topvisible and new_topvisible:
             while self.info[-1][1] >= lastindent:
@@ -147,8 +141,7 @@
                 stopindent = self.info[-1][1]
                 del self.info[-1]
             lines, lastindent = self.get_context(new_topvisible,
-                                                 self.info[-1][0]+1,
-                                                 stopindent)
+                self.info[-1][0] + 1, stopindent)
         self.info.extend(lines)
         self.topvisible = new_topvisible
         # empty lines in context pane:
@@ -168,3 +161,18 @@
             self.textfont = newtextfont
             self.label["font"] = self.textfont
         self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)
+
+    # Private methods
+
+    def _get_editpage(self):
+        return self._editpage
+
+    def _set_editpage(self, page):
+        self._editpage = page
+        self.text = page.text
+        self.textfont = self.text["font"]
+        # Start two update cycles, one for context lines, one for font changes.
+        self.text.after(UPDATEINTERVAL, self.timer_event)
+        self.text.after(FONTUPDATEINTERVAL, self.font_timer_event)
+
+    editpage = property(_get_editpage, _set_editpage)

Modified: sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/EditorWindow.py	Mon Aug  4 03:16:25 2008
@@ -505,7 +505,10 @@
             self.close_hook()
 
     def load_extension(self, name, tab):
-        #print "load extension", name, tab
+        load_only_once = ['CodeContext']
+        if name in load_only_once and self.extensions.get(name, None):
+            return
+
         try:
             mod = __import__(name, globals(), locals(), [])
         except ImportError:
@@ -651,6 +654,11 @@
         curr_page.text.focus_set()
         self.set_line_and_column()
 
+        # update references in extensions that are loaded only once
+        if 'CodeContext' in self.extensions:
+            ext = self.extensions['CodeContext'][0]
+            ext.editpage = curr_page
+
     def _create_statusbar(self):
         self.status_bar = MultiStatusBar(self.top)
         if macosxSupport.runningAsOSXApp():


More information about the Python-checkins mailing list