Skip to content
Snippets Groups Projects
Commit 78d8b842 authored by David's avatar David
Browse files

Added feature of a gesture executing a command

parent b2a39aee
No related branches found
No related tags found
No related merge requests found
......@@ -30,4 +30,6 @@ The design pattern used for this project is Facade. I used this to abstract the
The tool for reading the config file is configparser, a python library. The syntax of configs can be seen in the example file.
Syntax of config is very straightforwards and easy to use.
Note that for every gesture, a new section name (name in `[]`) should be created. All options are required to be filled out or an error would be thrown when executing the gesture. Comments must be placed after a line, in line comments will also be read into the config
The gesture can either be a command or a keyboard shortcut, this is specified in `action_type` field of the config file.
For a list of valid keys, see [documentation of pyautogui](https://pyautogui.readthedocs.io/en/latest/keyboard.html)
For more information refer to [configparser's documentation page](https://docs.python.org/3/library/configparser.html)
......@@ -35,36 +35,42 @@ KEYPRESSLIST = ['\t', '\n', '\r', ' ', '!', '"', '#', '$', '%', '&', "'", '(',
class Gesture():
def __init__(self, name: str, action: list, fingers_up: int, direction: str) -> None:
def __init__(self, name: str, action: list, action_type: str, fingers_up: int, direction: str) -> None:
self.name = name
self.action = action
self.action_type = action_type
self.fingers_up = fingers_up
self.direction = direction
def exec_action(self):
for keypress in self.action:
if keypress not in KEYPRESSLIST:
raise ConfigError
if self.action_type == "keyboard":
global error_log
try:
if len(self.action) < 2:
for key in self.action:
press(key)
elif len(self.action) > 2:
for key in self.action:
keyDown(key)
for key in self.action:
keyUp(key)
for keypress in self.action:
if keypress not in KEYPRESSLIST:
raise ConfigError
except BaseException as e:
print("Error: ", e)
error_log.append(e)
if e == None:
return True
else:
return error_log
global error_log
try:
if len(self.action) < 2:
for key in self.action:
press(key)
elif len(self.action) > 2:
for key in self.action:
keyDown(key)
for key in self.action:
keyUp(key)
except BaseException as e:
print("Error: ", e)
error_log.append(e)
if e == None:
return True
else:
return error_log
elif self.action_type == "command":
for action in self.action:
os.system(action)
......@@ -18,8 +18,9 @@ class GestureGenerator:
gesture_action = config[section]["action"]
gesture_fingers_up = config[section]["fingers_up"]
gesture_direction = config[section]["direction"]
gesture_action_type = config[section]["action_type"]
print(gesture_action.split(","))
GestureList.append(Gesture.Gesture(str(gesture_name), gesture_action.split(","),
GestureList.append(Gesture.Gesture(str(gesture_name), gesture_action.split(","), str(gesture_action_type),
int(gesture_fingers_up), str(gesture_direction)))
except KeyError:
print("Check your config for errors!")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment