]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add new command, "Open module". You select or type a module name,
authorGuido van Rossum <guido@python.org>
Tue, 13 Oct 1998 03:45:15 +0000 (03:45 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 13 Oct 1998 03:45:15 +0000 (03:45 +0000)
and it opens the source.

Tools/idle/Bindings.py
Tools/idle/EditorWindow.py

index 4f833c67b3dbb7f6941728afcbbeac9a723c9a25..795d837d77a860e2fbb178b7db1427f1b3a30c6c 100644 (file)
@@ -57,6 +57,8 @@ emacs_bindings = [
      "<<open-new-window>>", "<Control-x><Control-n>"),
     ("file", "Open...", "C-x C-f",
      "<<open-window-from-file>>", "<Control-x><Control-f>"),
+    ("file", "Open module...", "C-x C-m",
+     "<<open-module>>", "<Control-x><Control-m>"),
     ("file", None, None),
 
     ("file", "Save", "C-x C-s",
index b122c2f215fca2f612d0c671940e5711d4d1091e..977be6bf029584bdefc3ecb64e9f58234d62e606 100644 (file)
@@ -1,7 +1,9 @@
 import sys
 import os
 import string
+import imp
 from Tkinter import *
+import tkSimpleDialog
 import tkMessageBox
 
 about_title = "About IDLE"
@@ -42,6 +44,7 @@ class EditorWindow:
         self.text.bind("<<center-insert>>", self.center_insert_event)
         self.text.bind("<<help>>", self.help_dialog)
         self.text.bind("<<about-idle>>", self.about_dialog)
+        self.text.bind("<<open-module>>", self.open_module)
 
         vbar['command'] = text.yview
         vbar.pack(side=RIGHT, fill=Y)
@@ -98,6 +101,34 @@ class EditorWindow:
     def help_dialog(self, event=None):
         from HelpWindow import HelpWindow
         HelpWindow(root=self.root)
+    
+    def open_module(self, event=None):
+        try:
+            name = self.text.get("sel.first", "sel.last")
+        except TclError:
+            name = ""
+        else:
+            name = string.strip(name)
+        if not name:
+            name = tkSimpleDialog.askstring("Module",
+                     "Module name:",
+                     parent=self.text)
+            if name:
+                name = string.strip(name)
+            if not name:
+                return
+        try:
+            (f, file, (suffix, mode, type)) = imp.find_module(name)
+        except ImportError, msg:
+            tkMessageBox.showerror("Import error", str(msg), parent=self.text)
+            return
+        if type != imp.PY_SOURCE:
+            tkMessageBox.showerror("Unsupported type",
+                "%s is not a source module" % name, parent=self.text)
+            return
+        if f:
+            f.close()
+        self.flist.open(file, self)
 
     def gotoline(self, lineno):
         if lineno is not None and lineno > 0: