From b341888971cfe75f273138dae9907889c83433fc Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Tue, 13 Oct 1998 03:45:15 +0000 Subject: [PATCH] Add new command, "Open module". You select or type a module name, and it opens the source. --- Tools/idle/Bindings.py | 2 ++ Tools/idle/EditorWindow.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/Tools/idle/Bindings.py b/Tools/idle/Bindings.py index 4f833c67b3d..795d837d77a 100644 --- a/Tools/idle/Bindings.py +++ b/Tools/idle/Bindings.py @@ -57,6 +57,8 @@ emacs_bindings = [ "<>", ""), ("file", "Open...", "C-x C-f", "<>", ""), + ("file", "Open module...", "C-x C-m", + "<>", ""), ("file", None, None), ("file", "Save", "C-x C-s", diff --git a/Tools/idle/EditorWindow.py b/Tools/idle/EditorWindow.py index b122c2f215f..977be6bf029 100644 --- a/Tools/idle/EditorWindow.py +++ b/Tools/idle/EditorWindow.py @@ -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("<>", self.center_insert_event) self.text.bind("<>", self.help_dialog) self.text.bind("<>", self.about_dialog) + self.text.bind("<>", 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: