Skip to content

Commit

Permalink
wml tools GUI: the Ctrl+A accelerator (select all) finally works
Browse files Browse the repository at this point in the history
  • Loading branch information
Elvish-Hunter committed Feb 10, 2015
1 parent 3f3e0ce commit 63cac8e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions data/tools/GUI.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,11 @@ If the widget isn't active, some options do not appear"""
# adding a SEL tag to a chunk of text causes it to be selected
self.widget.tag_add(SEL,"1.0",END)
elif isinstance(self.widget,Entry) or \
isinstance(self.widget,Spinbox) or \
isinstance(self.widget,Combobox):
# if the widget is active or readonly, just fire the correct event
self.widget.event_generate("<<SelectAll>>")
# apparently, the <<SelectAll>> event doesn't fire correctly if the widget is readonly
self.widget.select_range(0,END)
elif isinstance(self.widget,Spinbox):
self.widget.selection("range",0,END)

class EntryContext(Entry):
def __init__(self,parent,**kwargs):
Expand Down Expand Up @@ -221,6 +222,9 @@ Use like any other Entry widget"""
self.bind("<Button-3>",self.on_context_menu)
self.bind("<KeyPress-Menu>",self.on_context_menu)
self.bind("<Shift-KeyPress-F10>",self.on_context_menu)
# for some weird reason, using a KeyPress binding to set the selection on
# a readonly Entry or disabled Text doesn't work, but a KeyRelease does
self.bind("<Control-KeyRelease-a>", lambda event: self.select_range(0,END))
def on_context_menu(self,event):
if str(self.cget('state')) != DISABLED:
ContextMenu(event.x_root,event.y_root,event.widget)
Expand All @@ -246,6 +250,7 @@ Use like any other Spinbox widget"""
self.bind("<Button-3>",self.on_context_menu)
self.bind("<KeyPress-Menu>",self.on_context_menu)
self.bind("<Shift-KeyPress-F10>",self.on_context_menu)
self.bind("<Control-KeyRelease-a>", lambda event: self.selection("range",0,END))
def on_context_menu(self,event):
if str(self.cget('state')) != DISABLED:
ContextMenu(event.x_root,event.y_root,event.widget)
Expand All @@ -271,6 +276,7 @@ Use it like any other Text widget"""
self.bind("<Button-3>",self.on_context_menu)
self.bind("<KeyPress-Menu>",self.on_context_menu)
self.bind("<Shift-KeyPress-F10>",self.on_context_menu)
self.bind("<Control-KeyRelease-a>", lambda event: self.tag_add(SEL,"1.0",END))
def on_context_menu(self,event):
# the disabled state in a Text widget is pretty much
# like the readonly state in Entry, hence no state check
Expand Down

0 comments on commit 63cac8e

Please sign in to comment.