mirror of https://github.com/python/cpython.git
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.
This commit is contained in:
parent
f64f8a0877
commit
85a36a5ff1
|
@ -208,10 +208,9 @@ def createmenubar(self):
|
||||||
|
|
||||||
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 @@ def apply_bindings(self, keydefs=None):
|
||||||
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 @@ def getrawvar(self, name, vartype=None):
|
||||||
# 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:]
|
||||||
|
|
Loading…
Reference in New Issue