Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #17

Merged
merged 4 commits into from
Mar 5, 2022
Merged

Dev #17

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/Python_JEAutoControl.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

142 changes: 75 additions & 67 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
Expand Down
5 changes: 3 additions & 2 deletions je_auto_control/utils/action_executor/action_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion je_auto_control/utils/critical_exit/critcal_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 0 additions & 16 deletions je_auto_control/windows/mouse/win32_ctype_mouse_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 6 additions & 6 deletions je_auto_control/wrapper/auto_control_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
80 changes: 30 additions & 50 deletions je_auto_control/wrapper/auto_control_mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,28 +66,17 @@ 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"]:
mouse.press_mouse(x, y, mouse_keycode)
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):
Expand All @@ -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)
Expand All @@ -100,8 +94,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):
Expand All @@ -110,28 +104,14 @@ 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
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):
Expand Down Expand Up @@ -175,5 +155,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))
8 changes: 8 additions & 0 deletions test/unit_test/mouse/mouse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 0 additions & 3 deletions test/unit_test/with_editor/auto_gui_with_je_editor.py

This file was deleted.