diff options
author | Guido van Rossum <guido@python.org> | 1998-10-13 03:45:15 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-10-13 03:45:15 (GMT) |
commit | b341888971cfe75f273138dae9907889c83433fc (patch) | |
tree | b42bb316de331da689681a0b8c36a79a0e19a54f /Tools/idle/EditorWindow.py | |
parent | 5af7a72d8bc0b7308e2342bdd97bda6d0d190222 (diff) | |
download | cpython-b341888971cfe75f273138dae9907889c83433fc.zip cpython-b341888971cfe75f273138dae9907889c83433fc.tar.gz cpython-b341888971cfe75f273138dae9907889c83433fc.tar.bz2 |
Add new command, "Open module". You select or type a module name,
and it opens the source.
Diffstat (limited to 'Tools/idle/EditorWindow.py')
-rw-r--r-- | Tools/idle/EditorWindow.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Tools/idle/EditorWindow.py b/Tools/idle/EditorWindow.py index b122c2f..977be6b 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("<<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: |