Kaydet (Commit) 85a36a5f authored tarafından Guido van Rossum's avatar Guido van Rossum

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.
üst f64f8a08
...@@ -208,10 +208,9 @@ class EditorWindow: ...@@ -208,10 +208,9 @@ class EditorWindow:
def postwindowsmenu(self): def postwindowsmenu(self):
# Only called when Windows menu exists # Only called when Windows menu exists
# XXX Actually, this Just-In-Time updating interferes # XXX Actually, this Just-In-Time updating interferes badly
# XXX badly with the tear-off feature. It would be better # XXX with the tear-off feature. It would be better to update
# XXX to update all Windows menus whenever the list of windows # XXX all Windows menus whenever the list of windows changes.
# XXX changes.
menu = self.menudict['windows'] menu = self.menudict['windows']
end = menu.index("end") end = menu.index("end")
if end is None: if end is None:
...@@ -530,8 +529,8 @@ class EditorWindow: ...@@ -530,8 +529,8 @@ class EditorWindow:
apply(text.event_add, (event,) + tuple(keylist)) apply(text.event_add, (event,) + tuple(keylist))
def fill_menus(self, defs=None, keydefs=None): def fill_menus(self, defs=None, keydefs=None):
# Fill the menus. # Fill the menus. Menus that are absent or None in
# Menus that are absent or None in self.menudict are ignored. # self.menudict are ignored.
if defs is None: if defs is None:
defs = self.Bindings.menudefs defs = self.Bindings.menudefs
if keydefs is None: if keydefs is None:
...@@ -584,23 +583,33 @@ class EditorWindow: ...@@ -584,23 +583,33 @@ class EditorWindow:
# flavor of widget. # flavor of widget.
# Is character at text_index in a Python string? Return 0 for # Is character at text_index in a Python string? Return 0 for
# "guaranteed no", true for anything else. This info is expensive to # "guaranteed no", true for anything else. This info is expensive
# compute ab initio, but is probably already known by the platform's # to compute ab initio, but is probably already known by the
# colorizer. # platform's colorizer.
def is_char_in_string(self, text_index): def is_char_in_string(self, text_index):
if self.color: if self.color:
# return true iff colorizer hasn't (re)gotten this far yet, or # Return true iff colorizer hasn't (re)gotten this far
# the character is tagged as being in a string # yet, or the character is tagged as being in a string
return self.text.tag_prevrange("TODO", text_index) or \ return self.text.tag_prevrange("TODO", text_index) or \
"STRING" in self.text.tag_names(text_index) "STRING" in self.text.tag_names(text_index)
else: else:
# the colorizer is missing: assume the worst # The colorizer is missing: assume the worst
return 1 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): def prepstr(s):
# Helper to extract the underscore from a string, # Helper to extract the underscore from a string, e.g.
# e.g. prepstr("Co_py") returns (2, "Copy"). # prepstr("Co_py") returns (2, "Copy").
i = string.find(s, '_') i = string.find(s, '_')
if i >= 0: if i >= 0:
s = s[:i] + s[i+1:] s = s[:i] + s[i+1:]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment