From bdcb06af1bf8f2b01007bd5397c6be1a67c64e3a Mon Sep 17 00:00:00 2001 From: oscons Date: Fri, 30 Aug 2019 06:00:35 +0200 Subject: [PATCH] Add macOS key bindings --- src/interface/interface.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/interface/interface.py b/src/interface/interface.py index 97995cf..cda3987 100644 --- a/src/interface/interface.py +++ b/src/interface/interface.py @@ -199,6 +199,7 @@ def __init__(self, client, title, language, logging=False): # Key bindings CtrlKey = "Command" if SYSTEM == MAC_OS else "Control" + AltKey = "Option" if SYSTEM == MAC_OS else "Alt" # Disable by default @@ -212,17 +213,39 @@ def __init__(self, client, title, language, logging=False): self.text.bind("escape", disable) + drop_event = lambda fun: lambda event: fun() + + # Basic mappings + + if SYSTEM == MAC_OS: + self.text.bind("", drop_event(self.key_home)) + self.text.bind("", drop_event(self.key_end)) + # Evaluating code self.text.bind("", self.key_press) self.text.bind("<{}-Return>".format(CtrlKey), self.evaluate) - self.text.bind("", self.single_line_evaluate) + self.text.bind("<{}-Return>".format(AltKey), self.single_line_evaluate) + self.text.bind("", self.single_line_evaluate) + + if SYSTEM == MAC_OS: + self.text.bind("<{}-Right>".format(AltKey), self.key_ctrl_right) + self.text.bind("<{}-Left>".format(AltKey), self.key_ctrl_left) + else: + self.text.bind("<{}-Right>".format(CtrlKey), self.key_ctrl_right) + self.text.bind("<{}-Left>".format(CtrlKey), self.key_ctrl_left) - self.text.bind("<{}-Right>".format(CtrlKey), self.key_ctrl_right) - self.text.bind("<{}-Left>".format(CtrlKey), self.key_ctrl_left) + if SYSTEM == MAC_OS: + self.text.bind("<{}-Right>".format(CtrlKey), drop_event(self.key_end)) + self.text.bind("<{}-Left>".format(CtrlKey), drop_event(self.key_home)) + + self.text.bind("<{}-Up>".format(CtrlKey), self.key_ctrl_home) + self.text.bind("<{}-Down>".format(CtrlKey), self.key_ctrl_end) + self.text.bind("<{}-Home>".format(CtrlKey), self.key_ctrl_home) self.text.bind("<{}-End>".format(CtrlKey), self.key_ctrl_end) + self.text.bind("<{}-period>".format(CtrlKey), self.stop_sound) self.text.bind("<{}-BackSpace>".format(CtrlKey), self.key_ctrl_backspace) @@ -242,6 +265,11 @@ def __init__(self, client, title, language, logging=False): self.text.bind("", self.select_down) self.text.bind("", self.select_end) self.text.bind("", self.select_home) + + if SYSTEM == MAC_OS: + self.text.bind("<{}-Shift-Right>".format(CtrlKey), self.select_end) + self.text.bind("<{}-Shift-Left>".format(CtrlKey), self.select_home) + self.text.bind("<{}-a>".format(CtrlKey), self.select_all) # Copy and paste key bindings