Skip to content

Commit

Permalink
wml tools GUI: fixed shortcuts being reported as Ctrl+key instead of …
Browse files Browse the repository at this point in the history
…Command+key on Mac OS

The actual bindings will be fixed in the next commit.
  • Loading branch information
Elvish-Hunter committed Feb 26, 2015
1 parent 3b16f13 commit 205673d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions data/tools/GUI.pyw
Expand Up @@ -154,29 +154,35 @@ If the widget isn't active, some options do not appear"""
else:
Menu.__init__(self,None,tearoff=0)
self.widget=widget
# MacOS uses a key called Command, instead of the usual Control used by Windows and Linux
# so prepare the accelerator strings accordingly
# For future reference, Mac also uses Option instead of Alt
# also, a little known fact about Python is that it *does* support using the ternary operator
# like in this case
control_key = "Command" if self.tk.call('tk', 'windowingsystem') == "aqua" else "Ctrl"
# str is necessary because in some instances a Tcl_Obj is returned instead of a string
if str(widget.cget('state')) in (ACTIVE,NORMAL): # do not add if state is readonly or disabled
self.add_command(label="Cut",
image=ICONS['cut'],
compound=LEFT,
accelerator='Ctrl+X',
accelerator='%s+X' % (control_key),
command=lambda: self.widget.event_generate("<<Cut>>"))
self.add_command(label="Copy",
image=ICONS['copy'],
compound=LEFT,
accelerator='Ctrl+C',
accelerator='%s+C' % (control_key),
command=lambda: self.widget.event_generate("<<Copy>>"))
if str(widget.cget('state')) in (ACTIVE,NORMAL):
self.add_command(label="Paste",
image=ICONS['paste'],
compound=LEFT,
accelerator='Ctrl+V',
accelerator='%s+V' % (control_key),
command=lambda: self.widget.event_generate("<<Paste>>"))
self.add_separator()
self.add_command(label="Select all",
image=ICONS['select_all'],
compound=LEFT,
accelerator='Ctrl+A',
accelerator='%s+A' % (control_key),
command=self.on_select_all)
self.tk_popup(x,y) # self.post does not destroy the menu when clicking out of it
def on_select_all(self):
Expand Down

0 comments on commit 205673d

Please sign in to comment.