summaryrefslogtreecommitdiffstats
path: root/Tools/idle/EditorWindow.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-06-10 17:43:17 (GMT)
committerGuido van Rossum <guido@python.org>1999-06-10 17:43:17 (GMT)
commit85a36a5ff1b0f306b95c8ed9d3aef48e0100ee7c (patch)
tree6cf3fddcf435f6e8e304e6ae74c69486867dfe09 /Tools/idle/EditorWindow.py
parentf64f8a0877ff3ecda81eb34accadb6a9defa2233 (diff)
downloadcpython-85a36a5ff1b0f306b95c8ed9d3aef48e0100ee7c.zip
cpython-85a36a5ff1b0f306b95c8ed9d3aef48e0100ee7c.tar.gz
cpython-85a36a5ff1b0f306b95c8ed9d3aef48e0100ee7c.tar.bz2
Added abstraction get_selection_index() (Mark Hammond). Also
reformatted some comment blocks to show off a cool feature I'm about to check in next.
Diffstat (limited to 'Tools/idle/EditorWindow.py')
-rw-r--r--Tools/idle/EditorWindow.py37
1 files changed, 23 insertions, 14 deletions
diff --git a/Tools/idle/EditorWindow.py b/Tools/idle/EditorWindow.py
index 18bedc2..bc4edde 100644
--- a/Tools/idle/EditorWindow.py
+++ b/Tools/idle/EditorWindow.py
@@ -208,10 +208,9 @@ class EditorWindow:
def postwindowsmenu(self):
# Only called when Windows menu exists
- # XXX Actually, this Just-In-Time updating interferes
- # XXX badly with the tear-off feature. It would be better
- # XXX to update all Windows menus whenever the list of windows
- # XXX changes.
+ # XXX Actually, this Just-In-Time updating interferes badly
+ # XXX with the tear-off feature. It would be better to update
+ # XXX all Windows menus whenever the list of windows changes.
menu = self.menudict['windows']
end = menu.index("end")
if end is None:
@@ -530,8 +529,8 @@ class EditorWindow:
apply(text.event_add, (event,) + tuple(keylist))
def fill_menus(self, defs=None, keydefs=None):
- # Fill the menus.
- # Menus that are absent or None in self.menudict are ignored.
+ # Fill the menus. Menus that are absent or None in
+ # self.menudict are ignored.
if defs is None:
defs = self.Bindings.menudefs
if keydefs is None:
@@ -584,23 +583,33 @@ class EditorWindow:
# flavor of widget.
# Is character at text_index in a Python string? Return 0 for
- # "guaranteed no", true for anything else. This info is expensive to
- # compute ab initio, but is probably already known by the platform's
- # colorizer.
+ # "guaranteed no", true for anything else. This info is expensive
+ # to compute ab initio, but is probably already known by the
+ # platform's colorizer.
def is_char_in_string(self, text_index):
if self.color:
- # return true iff colorizer hasn't (re)gotten this far yet, or
- # the character is tagged as being in a string
+ # Return true iff colorizer hasn't (re)gotten this far
+ # yet, or the character is tagged as being in a string
return self.text.tag_prevrange("TODO", text_index) or \
"STRING" in self.text.tag_names(text_index)
else:
- # the colorizer is missing: assume the worst
+ # The colorizer is missing: assume the worst
return 1
+ # If a selection is defined in the text widget, return (start,
+ # end) as Tkinter text indices, otherwise return (None, None)
+ def get_selection_index(self):
+ try:
+ first = self.text.index("sel.first")
+ last = self.text.index("sel.last")
+ return first, last
+ except TclError:
+ return None, None
+
def prepstr(s):
- # Helper to extract the underscore from a string,
- # e.g. prepstr("Co_py") returns (2, "Copy").
+ # Helper to extract the underscore from a string, e.g.
+ # prepstr("Co_py") returns (2, "Copy").
i = string.find(s, '_')
if i >= 0:
s = s[:i] + s[i+1:]