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

guilherme.polo python-checkins at python.org
Sat Aug 2 16:13:42 CEST 2008


Author: guilherme.polo
Date: Sat Aug  2 16:13:41 2008
New Revision: 65411

Log:
Moved more code to editorpage to reduce dependence on self.text of EditorWindow

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

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	Sat Aug  2 16:13:41 2008
@@ -11,8 +11,6 @@
 import macosxSupport
 import Bindings
 import WindowList
-import PathBrowser
-import ClassBrowser
 from editorpage import EditorPage, classifyws, filename_to_unicode
 from tabbedpages import get_tabbedpage
 from configHandler import idleConf
@@ -91,11 +89,11 @@
         except AttributeError:
             sys.ps1 = '>>> '
         self.menubar = Menu(root)
-        self.top = top = WindowList.ListedToplevel(root, menu=self.menubar)
+        self.top = WindowList.ListedToplevel(root, menu=self.menubar)
         if flist:
             self.tkinter_vars = flist.vars
-            #self.top.instance_dict makes flist.inversedict avalable to
-            #configDialog.py so it can access all EditorWindow instaces
+            # self.top.instance_dict makes flist.inversedict avalable to
+            # configDialog.py so it can access all EditorWindow instaces
             self.top.instance_dict = flist.inversedict
         else:
             self.tkinter_vars = {}  # keys: Tkinter event names
@@ -106,7 +104,7 @@
 
         # create a Notebook where the text pages for this EditorWindow will
         # reside
-        self.text_notebook = TabbedPageSet(top)
+        self.text_notebook = TabbedPageSet(self.top)
         self.text_notebook.bind('<<NotebookTabChanged>>',
             self._update_controls)
         self.new_tab(filename=filename)
@@ -129,13 +127,9 @@
             flist.inversedict[self] = key
             if key:
                 flist.dict[key] = self
-            text.bind("<<open-new-window>>", self._new_callback)
-            text.bind("<<close-all-windows>>", self.flist.close_all_callback)
-            text.bind("<<open-class-browser>>", self._open_class_browser)
-            text.bind("<<open-path-browser>>", self._open_path_browser)
 
         self._create_statusbar()
-        top.after_idle(self.set_line_and_column)
+        self.top.after_idle(self.set_line_and_column)
 
         # usetabs true  -> literal tab characters are used by indent and
         #                  dedent cmds, possibly mixed with spaces if
@@ -259,6 +253,11 @@
 
         return "break"
 
+    def new_callback(self, event, page):
+        dirname, basename = page.io.defaultfilename()
+        self.flist.new(dirname)
+        return "break"
+
     def set_line_and_column(self, event=None):
         # Used by PyShell too
         line, column = self.current_page.text.index(INSERT).split('.')
@@ -696,27 +695,6 @@
                                          command=command,
                                          accelerator=accelerator)
 
-    def _new_callback(self, event):
-        dirname, basename = self.current_page.io.defaultfilename()
-        self.flist.new(dirname)
-        return "break"
-
-    def _open_class_browser(self, event=None):
-        filename = self.io.filename
-        if not filename:
-            tkMessageBox.showerror(
-                "No filename",
-                "This buffer has no associated filename",
-                master=self.text_notebook)
-            self.current_page.text.focus_set()
-            return None
-        head, tail = os.path.split(filename)
-        base, ext = os.path.splitext(tail)
-        ClassBrowser.ClassBrowser(self.flist, base, [head])
-
-    def _open_path_browser(self, event=None):
-        PathBrowser.PathBrowser(self.flist)
-
     def __recent_file_callback(self, file_name):
         def open_recent_file(fn_closure=file_name):
             self.io.open(editFile=fn_closure)

Modified: sandbox/trunk/ttk-gsoc/src/idlelib/editorpage.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/idlelib/editorpage.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/idlelib/editorpage.py	Sat Aug  2 16:13:41 2008
@@ -6,6 +6,7 @@
 import tkSimpleDialog
 from Tkinter import Text, Menu, TclError
 
+import utils
 import textView
 import aboutDialog
 import configDialog
@@ -13,6 +14,8 @@
 import PyParse
 import IOBinding
 import GrepDialog
+import PathBrowser
+import ClassBrowser
 import SearchDialog
 import ReplaceDialog
 from configHandler import idleConf
@@ -323,31 +326,27 @@
 
     def _setup_bindings(self):
         text = self.text
+        def bind_them(to_bind, prefix='_%s'):
+            for tb in to_bind:
+                prefix_size = tb.count('<')
+                method_name = tb[prefix_size:-prefix_size].replace('-', '_')
+                text.bind(tb, getattr(self, prefix % method_name.lower()))
+            
         actions = ('<<close-tab>>', '<<help>>', '<<python-docs>>',
             '<<about-idle>>', '<<open-config-dialog>>', '<<open-module>>',
             '<<cut>>', '<<copy>>', '<<paste>>', '<<select-all>>',
             '<<remove-selection>>', '<<del-word-left>>', '<<del-word-right>>',
             '<<beginning-of-line>>')
-
-        for action in actions:
-            prefix_size = action.count('<')
-            method_name = action[prefix_size:-prefix_size].replace('-', '_')
-            text.bind(action, getattr(self, "_%s" % method_name.lower()))
-
         events = ('<<find>>', '<<center-insert>>', '<<find-again>>',
             '<<find-in-files>>', '<<find-selection>>', '<<replace>>',
             '<<goto-line>>', '<<smart-backspace>>', '<<smart-indent>>',
             '<<indent-region>>', '<<dedent-region>>', '<<comment-region>>',
             '<<tabify-region>>', '<<untabify-region>>', '<<toggle-tabs>>',
             '<<change-indentwidth>>')
-
-        for event in events:
-            prefix_size = event.count('<')
-            method_name = event[prefix_size:-prefix_size].replace('-', '_')
-            text.bind(event, getattr(self, "_%s_event" % method_name.lower()))
-
         parent_actions = ('<<new-tab>>', '<<next-tab>>', '<<prev-tab>>')
 
+        bind_them(actions)
+        bind_them(events, prefix="_%s_event")
         for action in parent_actions:
             prefix_size = action.count('<')
             method_name = action[prefix_size:-prefix_size].replace('-', '_')
@@ -362,6 +361,14 @@
         text.event_add("<<set-line-and-column>>",
                                     "<KeyRelease>", "<ButtonRelease>")
 
+        if self.editwin.flist:
+            text.bind("<<open-new-window>>",
+                utils.callback(self.editwin.new_callback, self))
+            text.bind("<<close-all-windows>>",
+                self.editwin.flist.close_all_callback)
+            text.bind("<<open-class-browser>>", self._open_class_browser)
+            text.bind("<<open-path-browser>>", self._open_path_browser)
+
         if macosxSupport.runningAsOSXApp():
             # Command-W on editorwindows doesn't work without this.
             text.bind('<<close-window>>', self.editwin.close_event)
@@ -385,6 +392,21 @@
     def _about_idle(self, event=None):
         aboutDialog.AboutDialog(self.text, 'About IDLE')
 
+    def _open_class_browser(self, event=None):
+        filename = self.io.filename
+        if not filename:
+            tkMessageBox.showerror("No filename",
+                "This buffer has no associated filename",
+                master=self.text)
+            self.text.focus_set()
+            return None
+        head, tail = os.path.split(filename)
+        base, ext = os.path.splitext(tail)
+        ClassBrowser.ClassBrowser(self.editwin.flist, base, [head])
+
+    def _open_path_browser(self, event=None):
+        PathBrowser.PathBrowser(self.editwin.flist)
+
     def _open_config_dialog(self, event=None):
         # When changing colors and saving it, it requires the attribute
         # instance_dict making necessary to pass self.editwin.top as the


More information about the Python-checkins mailing list