summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKurt B. Kaiser <kbk@shore.net>2002-09-16 02:13:15 (GMT)
committerKurt B. Kaiser <kbk@shore.net>2002-09-16 02:13:15 (GMT)
commit220ecbc731bf600fe977e1721f2f5c1aec7b033c (patch)
tree36ea4f7d5089eb094fe5fa5cf210ec9b6b936315
parentc0a0e0810b8d17cc8733a3aa967bd2d4e4f12fb4 (diff)
downloadcpython-220ecbc731bf600fe977e1721f2f5c1aec7b033c.zip
cpython-220ecbc731bf600fe977e1721f2f5c1aec7b033c.tar.gz
cpython-220ecbc731bf600fe977e1721f2f5c1aec7b033c.tar.bz2
Merge Py Idle changes:
Rev 1.39 GvR Properly fix SF bug #507298 (Gregor Lingl): shellpython2.2 -Qnew smart indent error Use // where int division is intended. (This breaks IDLE for use with previous Python versions -- I don't care.) Rev 1.40 tim_one Convert a pile of obvious "yes/no" functions to return bool. Rev 1.41 foffani/loewis (already merged) - MS html help Rev 1.42 (skip, done differently in Idlefork) Rev 1.43 tzot/rhettinger Extended IDLE's open module menu item to handle hierarchical module names. Will look at doing something similar in import.c so that the effort won't have to be repeated elsewhere. Closes SF patch 600152. Rev 1.44 doerwalter (string methods)
-rw-r--r--Lib/idlelib/EditorWindow.py39
1 files changed, 26 insertions, 13 deletions
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py
index b9e44e1..ef8e122 100644
--- a/Lib/idlelib/EditorWindow.py
+++ b/Lib/idlelib/EditorWindow.py
@@ -19,6 +19,20 @@ import aboutDialog, textView, configDialog
# The default tab setting for a Text widget, in average-width characters.
TK_TABWIDTH_DEFAULT = 8
+def _find_module(fullname, path=None):
+ """Version of imp.find_module() that handles hierarchical module names"""
+
+ file = None
+ for tgt in fullname.split('.'):
+ if file is not None:
+ file.close() # close intermediate files
+ (file, filename, descr) = imp.find_module(tgt, path)
+ if descr[2] == imp.PY_SOURCE:
+ break # find but not load the source file
+ module = imp.load_module(tgt, file, filename, descr)
+ path = module.__path__
+ return file, filename, descr
+
class EditorWindow:
from Percolator import Percolator
from ColorDelegator import ColorDelegator
@@ -183,7 +197,7 @@ class EditorWindow:
self.text.after_idle(self.set_line_and_column)
def set_line_and_column(self, event=None):
- line, column = string.split(self.text.index(INSERT), '.')
+ line, column = self.text.index(INSERT).split('.')
self.status_bar.set_label('column', 'Col: %s' % column)
self.status_bar.set_label('line', 'Ln: %s' % line)
@@ -346,20 +360,19 @@ class EditorWindow:
except TclError:
name = ""
else:
- name = string.strip(name)
+ name = name.strip()
if not name:
name = tkSimpleDialog.askstring("Module",
"Enter the name of a Python module\n"
"to search on sys.path and open:",
parent=self.text)
if name:
- name = string.strip(name)
+ name = name.strip()
if not name:
return
- # XXX Ought to support package syntax
# XXX Ought to insert current file's directory in front of path
try:
- (f, file, (suffix, mode, type)) = imp.find_module(name)
+ (f, file, (suffix, mode, type)) = _find_module(name)
except (NameError, ImportError), msg:
tkMessageBox.showerror("Import error", str(msg), parent=self.text)
return
@@ -401,17 +414,17 @@ class EditorWindow:
def ispythonsource(self, filename):
if not filename:
- return 1
+ return True
base, ext = os.path.splitext(os.path.basename(filename))
if os.path.normcase(ext) in (".py", ".pyw"):
- return 1
+ return True
try:
f = open(filename)
line = f.readline()
f.close()
except IOError:
- return 0
- return line[:2] == '#!' and string.find(line, 'python') >= 0
+ return False
+ return line.startswith('#!') and 'python' in line
def close_hook(self):
if self.flist:
@@ -621,7 +634,7 @@ class EditorWindow:
top, bot = self.getwindowlines()
lineno = self.getlineno(mark)
height = bot - top
- newtop = max(1, lineno - height/2)
+ newtop = max(1, lineno - height//2)
text.yview(float(newtop))
def getwindowlines(self):
@@ -712,7 +725,7 @@ class EditorWindow:
if keydefs:
self.apply_bindings(keydefs)
for vevent in keydefs.keys():
- methodname = string.replace(vevent, "-", "_")
+ methodname = vevent.replace("-", "_")
while methodname[:1] == '<':
methodname = methodname[1:]
while methodname[-1:] == '>':
@@ -1300,7 +1313,7 @@ class IndentSearcher:
def prepstr(s):
# Helper to extract the underscore from a string, e.g.
# prepstr("Co_py") returns (2, "Copy").
- i = string.find(s, '_')
+ i = s.find('_')
if i >= 0:
s = s[:i] + s[i+1:]
return i, s
@@ -1317,7 +1330,7 @@ def get_accelerator(keydefs, event):
if not keylist:
return ""
s = keylist[0]
- s = re.sub(r"-[a-z]\b", lambda m: string.upper(m.group()), s)
+ s = re.sub(r"-[a-z]\b", lambda m: m.group().upper(), s)
s = re.sub(r"\b\w+\b", lambda m: keynames.get(m.group(), m.group()), s)
s = re.sub("Key-", "", s)
s = re.sub("Cancel","Ctrl-Break",s) # dscherer@cmu.edu