Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #126 from gabrielfoo/settings_refactor
Browse files Browse the repository at this point in the history
Refactored a function in settings.py to fix an annoying issue
  • Loading branch information
kelltom authored Feb 4, 2023
2 parents 45071e4 + c89c6bb commit c61d823
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/utilities/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,28 @@ def get(key):


def keybind_to_text(current_keys):
keys_to_display = []
hotkeys = []
for key in current_keys:
if key == keyboard.Key.enter:
keys_to_display.append("↵")
elif key == keyboard.Key.space:
keys_to_display.append("␣")
elif key in [keyboard.Key.ctrl, keyboard.Key.ctrl_l, keyboard.Key.ctrl_r]:
keys_to_display.append("^")
elif key in [keyboard.Key.alt, keyboard.Key.alt_l, keyboard.Key.alt_r]:
keys_to_display.append("⌥")
elif key in [keyboard.Key.shift, keyboard.Key.shift_l, keyboard.Key.shift_r]:
keys_to_display.append("⇧")
elif key in [keyboard.Key.cmd, keyboard.Key.cmd_l, keyboard.Key.cmd_r]:
keys_to_display.append("⌘")
elif key in [keyboard.Key.caps_lock]:
keys_to_display.append("⇪")
elif key in [keyboard.Key.tab]:
keys_to_display.append("⇥")
elif key in [keyboard.Key.backspace]:
keys_to_display.append("⌫")
else:
keys_to_display.append(key)
return " + ".join([str(key).replace("'", "") for key in keys_to_display])
match key:
case keyboard.Key.enter:
hotkeys.append("↵")
case keyboard.Key.space:
hotkeys.append("␣")
case keyboard.Key.ctrl | keyboard.Key.ctrl_l | keyboard.Key.ctrl_r:
hotkeys.append("^")
case keyboard.Key.alt | keyboard.Key.alt_l | keyboard.Key.alt_r:
hotkeys.append("⌥")
case keyboard.Key.shift | keyboard.Key.shift_l | keyboard.Key.shift_r:
hotkeys.append("⇧")
case keyboard.Key.cmd | keyboard.Key.cmd_l | keyboard.Key.cmd_r:
hotkeys.append("⌘")
case keyboard.Key.caps_lock:
hotkeys.append("⇪")
case keyboard.Key.tab:
hotkeys.append("⇥")
case keyboard.Key.backspace:
hotkeys.append("⌫")
case _:
hotkeys.append(key)

return " + ".join(map(str, hotkeys)).replace("'", "")

0 comments on commit c61d823

Please sign in to comment.