mirror of https://github.com/python/cpython
Add new command, "Open module". You select or type a module name,
and it opens the source.
This commit is contained in:
parent
5af7a72d8b
commit
b341888971
|
@ -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",
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue