From 013b9d3225f839984c53e00491855e45636902fb Mon Sep 17 00:00:00 2001 From: JE-Chen Date: Thu, 30 Dec 2021 22:27:44 +0800 Subject: [PATCH 1/4] refactor keyboard and mouse wrapper now except TypeError will raise repr(TypeError) --- dev_setup.py | 2 +- je_auto_control/wrapper/auto_control_keyboard.py | 12 ++++++------ je_auto_control/wrapper/auto_control_mouse.py | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dev_setup.py b/dev_setup.py index da608c8..6ff7027 100644 --- a/dev_setup.py +++ b/dev_setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="je_auto_control_dev", - version="0.0.04", + version="0.0.05", author="JE-Chen", author_email="zenmailman@gmail.com", description="auto testing", diff --git a/je_auto_control/wrapper/auto_control_keyboard.py b/je_auto_control/wrapper/auto_control_keyboard.py index e07a3a1..4fd990e 100644 --- a/je_auto_control/wrapper/auto_control_keyboard.py +++ b/je_auto_control/wrapper/auto_control_keyboard.py @@ -32,8 +32,8 @@ def press_key(keycode: [int, str], is_shift: bool = False, **kwargs): return str(keycode) except AutoControlKeyboardException: raise AutoControlKeyboardException(keyboard_press_key) - except TypeError: - raise AutoControlKeyboardException(repr(TypeError)) + except TypeError as error: + raise AutoControlKeyboardException(repr(error)) def release_key(keycode: [int, str], is_shift: bool = False, **kwargs): @@ -54,8 +54,8 @@ def release_key(keycode: [int, str], is_shift: bool = False, **kwargs): return str(keycode) except AutoControlKeyboardException: raise AutoControlKeyboardException(keyboard_release_key) - except TypeError: - raise AutoControlKeyboardException(keyboard_type_key) + except TypeError as error: + raise AutoControlKeyboardException(repr(error)) def type_key(keycode: [int, str], is_shift: bool = False, **kwargs): @@ -69,8 +69,8 @@ def type_key(keycode: [int, str], is_shift: bool = False, **kwargs): return str(keycode) except AutoControlKeyboardException: raise AutoControlKeyboardException(keyboard_type_key) - except TypeError: - raise AutoControlKeyboardException(keyboard_type_key) + except TypeError as error: + raise AutoControlKeyboardException(repr(error)) def check_key_is_press(keycode: [int, str], **kwargs): diff --git a/je_auto_control/wrapper/auto_control_mouse.py b/je_auto_control/wrapper/auto_control_mouse.py index 344c682..3d1d364 100644 --- a/je_auto_control/wrapper/auto_control_mouse.py +++ b/je_auto_control/wrapper/auto_control_mouse.py @@ -67,8 +67,8 @@ def press_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwarg return mouse_keycode, x, y except AutoControlMouseException: raise AutoControlMouseException(mouse_press_mouse) - except TypeError: - raise AutoControlMouseException(mouse_release_mouse) + except TypeError as error: + raise AutoControlMouseException(repr(error)) def release_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwargs): @@ -100,8 +100,8 @@ def release_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwa return mouse_keycode, x, y except AutoControlMouseException: raise AutoControlMouseException(mouse_release_mouse) - except TypeError: - raise AutoControlMouseException(mouse_release_mouse) + except TypeError as error: + raise AutoControlMouseException(repr(error)) def click_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwargs): @@ -130,8 +130,8 @@ def click_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwarg return mouse_keycode, x, y except AutoControlMouseException: raise AutoControlMouseException(mouse_click_mouse) - except TypeError: - raise AutoControlMouseException(mouse_click_mouse) + except TypeError as error: + raise AutoControlMouseException(repr(error)) def scroll(scroll_value: int, x: int = None, y: int = None, scroll_direction: str = "scroll_down", **kwargs): @@ -175,5 +175,5 @@ def scroll(scroll_value: int, x: int = None, y: int = None, scroll_direction: st return scroll_value, scroll_direction except AutoControlMouseException: raise AutoControlMouseException(mouse_scroll) - except TypeError: - raise AutoControlMouseException(mouse_scroll) + except TypeError as error: + raise AutoControlMouseException(repr(error)) From 63143a81a03845c3034e6f342d64ec4e789f123a Mon Sep 17 00:00:00 2001 From: JE-Chen Date: Tue, 1 Mar 2022 09:46:50 +0800 Subject: [PATCH 2/4] refactor refactor --- .idea/Python_JEAutoControl.iml | 2 +- .idea/misc.xml | 2 +- .idea/workspace.xml | 151 ++++++++++-------- .../listener/x11_linux_listener.py | 2 +- .../utils/action_executor/action_executor.py | 5 +- .../utils/critical_exit/critcal_exit.py | 2 +- .../mouse/win32_ctype_mouse_control.py | 16 -- je_auto_control/wrapper/auto_control_mouse.py | 64 +++----- 8 files changed, 112 insertions(+), 132 deletions(-) diff --git a/.idea/Python_JEAutoControl.iml b/.idea/Python_JEAutoControl.iml index b494c46..d4912d6 100644 --- a/.idea/Python_JEAutoControl.iml +++ b/.idea/Python_JEAutoControl.iml @@ -5,7 +5,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index 43bd6e9..b132445 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 61eb37b..630886c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,14 @@ - + + + + + + + + - - - - - - - + + + + + + + + + + @@ -52,7 +62,7 @@ - + @@ -227,13 +237,13 @@ + + - - @@ -315,6 +325,12 @@ + + + + + + @@ -331,7 +347,6 @@ - - - - + + + + - - - - + + + - - + + + + + + + + + + + - + + + - + + - - - - - - + - - - + + + - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + + + + + + + + \ No newline at end of file diff --git a/je_auto_control/linux_with_x11/listener/x11_linux_listener.py b/je_auto_control/linux_with_x11/listener/x11_linux_listener.py index 7088100..eb3f57e 100644 --- a/je_auto_control/linux_with_x11/listener/x11_linux_listener.py +++ b/je_auto_control/linux_with_x11/listener/x11_linux_listener.py @@ -23,7 +23,7 @@ class KeypressHandler(Thread): - def __init__(self, default_daemon=True): + def __init__(self, default_daemon: bool = True): """ setDaemon : default damon is true still listener : continue listener keycode ? diff --git a/je_auto_control/utils/action_executor/action_executor.py b/je_auto_control/utils/action_executor/action_executor.py index 19f8dad..658ff3f 100644 --- a/je_auto_control/utils/action_executor/action_executor.py +++ b/je_auto_control/utils/action_executor/action_executor.py @@ -22,6 +22,7 @@ from je_auto_control import write from je_auto_control.utils.exception.exception_tag import action_is_null_error from je_auto_control.utils.exception.exception_tag import cant_execute_action_error +from je_auto_control.utils.exception.exceptions import AutoControlActionException event_dict = { # mouse @@ -53,14 +54,14 @@ } -def execute_event(action): +def execute_event(action: list): event = event_dict.get(action[0]) if len(action) == 2: event(**action[1]) elif len(action) == 1: event() else: - pass + raise AutoControlActionException(cant_execute_action_error) def execute_action(action_list: list): diff --git a/je_auto_control/utils/critical_exit/critcal_exit.py b/je_auto_control/utils/critical_exit/critcal_exit.py index 1588fdf..b321a23 100644 --- a/je_auto_control/utils/critical_exit/critcal_exit.py +++ b/je_auto_control/utils/critical_exit/critcal_exit.py @@ -10,7 +10,7 @@ class CriticalExit(Thread): - def __init__(self, default_daemon=True): + def __init__(self, default_daemon: bool = True): super().__init__() self.setDaemon(default_daemon) self._exit_check_key = keys_table.get("f7") diff --git a/je_auto_control/windows/mouse/win32_ctype_mouse_control.py b/je_auto_control/windows/mouse/win32_ctype_mouse_control.py index 054370a..7f7dcae 100644 --- a/je_auto_control/windows/mouse/win32_ctype_mouse_control.py +++ b/je_auto_control/windows/mouse/win32_ctype_mouse_control.py @@ -107,20 +107,4 @@ def scroll(scroll_value: int, x: int = None, y: int = None): :param x scroll x :param y scroll y """ - now_cursor_x, now_cursor_y = position() - width, height = size() - if x is None: - x = now_cursor_x - else: - if x < 0: - x = 0 - elif x >= width: - x = width - 1 - if y is None: - y = now_cursor_y - else: - if y < 0: - y = 0 - elif y >= height: - y = height - 1 mouse_event(win32_WHEEL, x, y, dwData=scroll_value) diff --git a/je_auto_control/wrapper/auto_control_mouse.py b/je_auto_control/wrapper/auto_control_mouse.py index 3d1d364..85394c1 100644 --- a/je_auto_control/wrapper/auto_control_mouse.py +++ b/je_auto_control/wrapper/auto_control_mouse.py @@ -17,6 +17,25 @@ from je_auto_control.wrapper.platform_wrapper import special_table +def mouse_preprocess(mouse_keycode: [int, str], x: int, y: int): + try: + if type(mouse_keycode) is str: + mouse_keycode = mouse_table.get(mouse_keycode) + else: + pass + except AutoControlCantFindKeyException: + raise AutoControlCantFindKeyException(table_cant_find_key) + try: + now_x, now_y = position() + if x is None: + x = now_x + if y is None: + y = now_y + except AutoControlMouseException: + raise AutoControlMouseException(mouse_get_position) + return mouse_keycode, x, y + + def position(): """ get mouse current position @@ -47,19 +66,8 @@ def press_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwarg :param x event x :param y event y """ + mouse_keycode, x, y = mouse_preprocess(mouse_keycode, x, y) try: - if type(mouse_keycode) is str: - mouse_keycode = mouse_table.get(mouse_keycode) - else: - pass - except AutoControlCantFindKeyException: - raise AutoControlCantFindKeyException(table_cant_find_key) - try: - now_x, now_y = position() - if x is None: - x = now_x - if y is None: - y = now_y if sys.platform in ["win32", "cygwin", "msys", "linux", "linux2"]: mouse.press_mouse(mouse_keycode) elif sys.platform in ["darwin"]: @@ -77,21 +85,7 @@ def release_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwa :param x event x :param y event y """ - try: - if type(mouse_keycode) is str: - mouse_keycode = mouse_table.get(mouse_keycode) - else: - pass - except AutoControlCantFindKeyException: - raise AutoControlCantFindKeyException(table_cant_find_key) - try: - now_x, now_y = position() - if x is None: - x = now_x - if y is None: - y = now_y - except AutoControlMouseException: - raise AutoControlMouseException(mouse_get_position) + mouse_keycode, x, y = mouse_preprocess(mouse_keycode, x, y) try: if sys.platform in ["win32", "cygwin", "msys", "linux", "linux2"]: mouse.release_mouse(mouse_keycode) @@ -110,21 +104,7 @@ def click_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwarg :param x event x :param y event y """ - try: - if type(mouse_keycode) is str: - mouse_keycode = mouse_table.get(mouse_keycode) - else: - pass - except AutoControlCantFindKeyException: - raise AutoControlCantFindKeyException(table_cant_find_key) - try: - now_x, now_y = position() - if x is None: - x = now_x - if y is None: - y = now_y - except AutoControlMouseException: - raise AutoControlMouseException(mouse_get_position) + mouse_keycode, x, y = mouse_preprocess(mouse_keycode, x, y) try: mouse.click_mouse(mouse_keycode, x, y) return mouse_keycode, x, y From 2abd60b9f1392a2853a831466689fe24946a184f Mon Sep 17 00:00:00 2001 From: JE-Chen Date: Tue, 1 Mar 2022 16:42:57 +0800 Subject: [PATCH 3/4] refactor test refactor test --- test/unit_test/mouse/mouse_test.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/unit_test/mouse/mouse_test.py b/test/unit_test/mouse/mouse_test.py index 1641368..5f19aa7 100644 --- a/test/unit_test/mouse/mouse_test.py +++ b/test/unit_test/mouse/mouse_test.py @@ -45,3 +45,11 @@ release_mouse(1651651915) except AutoControlMouseException as error: print(repr(error), file=sys.stderr) +try: + press_mouse("mouse_left") +except AutoControlMouseException as error: + print(repr(error), file=sys.stderr) +try: + release_mouse("mouse_left") +except AutoControlMouseException as error: + print(repr(error), file=sys.stderr) From 9365dd3fc1599f674ecab46b33b8d99f1e668771 Mon Sep 17 00:00:00 2001 From: JE-Chen Date: Tue, 1 Mar 2022 17:08:33 +0800 Subject: [PATCH 4/4] remove with editor remove with editor --- .idea/workspace.xml | 13 +++---------- .../with_editor/auto_gui_with_je_editor.py | 3 --- 2 files changed, 3 insertions(+), 13 deletions(-) delete mode 100644 test/unit_test/with_editor/auto_gui_with_je_editor.py diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 630886c..90ca5f5 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,14 +2,8 @@ - - - - - - - + \ No newline at end of file diff --git a/test/unit_test/with_editor/auto_gui_with_je_editor.py b/test/unit_test/with_editor/auto_gui_with_je_editor.py deleted file mode 100644 index f6f3d76..0000000 --- a/test/unit_test/with_editor/auto_gui_with_je_editor.py +++ /dev/null @@ -1,3 +0,0 @@ -from je_editor import start_editor - -start_editor()