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 #12

Merged
merged 4 commits into from
Dec 1, 2021
Merged

Dev #12

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
36 changes: 18 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,67 @@ jobs:
name: pip requirements.txt
# screen test
- run:
command: python ./circle_ci_test/screen/screen_test.py
command: python ./circle_ci_test/unit_test/screen/screen_test.py
name: screen_test
- run:
command: python ./circle_ci_test/screen/screenshot_test.py
command: python ./circle_ci_test/unit_test/screen/screenshot_test.py
name: screenshot_test
# keyboard test
- run:
command: python ./circle_ci_test/keyboard/keyboard_type_test.py
command: python ./circle_ci_test/unit_test/keyboard/keyboard_type_test.py
name: keyboard_type_test
- run:
command: python ./circle_ci_test/keyboard/keyboard_write_test.py
command: python ./circle_ci_test/unit_test/keyboard/keyboard_write_test.py
name: keyboard_write_test
- run:
command: python ./circle_ci_test/keyboard/keyboard_is_press_test.py
command: python ./circle_ci_test/unit_test/keyboard/keyboard_is_press_test.py
name: keyboard_is_press_test
- run:
command: python ./circle_ci_test/keyboard/hotkey_test.py
command: python ./circle_ci_test/unit_test/keyboard/hotkey_test.py
name: hotkey_test
# mouse test
- run:
command: python ./circle_ci_test/mouse/mouse_test.py
command: python ./circle_ci_test/unit_test/mouse/mouse_test.py
name: mouse_test
- run:
command: python ./circle_ci_test/mouse/mouse_scroll_test.py
command: python ./circle_ci_test/unit_test/mouse/mouse_scroll_test.py
name: scroll_test
# exception test
- run:
command: python ./circle_ci_test/exception/test_auto_control_exception.py
command: python ./circle_ci_test/unit_test/exception/test_auto_control_exception.py
name: test_auto_control_exception
# image detect
- run:
command: python ./circle_ci_test/image/locate_all_image_test.py
command: python ./circle_ci_test/unit_test/image/locate_all_image_test.py
name: locate_all_image_test
- run:
command: python ./circle_ci_test/image/locate_and_click_test.py
command: python ./circle_ci_test/unit_test/image/locate_and_click_test.py
name: locate_and_click_test
- run:
command: python ./circle_ci_test/image/locate_image_center_test.py
command: python ./circle_ci_test/unit_test/image/locate_image_center_test.py
name: locate_image_center_test
# critical exit
- run:
command: python ./circle_ci_test/critical_exit/critical_exit_test.py
command: python ./circle_ci_test/unit_test/critical_exit/critical_exit_test.py
name: critical_exit_test
- run:
command: python ./circle_ci_test/critical_exit/real_critical_test.py
command: python ./circle_ci_test/unit_test/critical_exit/real_critical_test.py
name: real_critical_test
# record
- run:
command: python ./circle_ci_test/record/record_test.py
command: python ./circle_ci_test/unit_test/record/record_test.py
name: record_test
# execute
- run:
command: python ./circle_ci_test/execute_action/execute_action_test.py
command: python ./circle_ci_test/unit_test/execute_action/execute_action_test.py
name: execute_action_test
# json
- run:
command: python ./circle_ci_test/json/json_test.py
command: python ./circle_ci_test/unit_test/json/json_test.py
name: json_test
# timeout
- run:
command: python ./circle_ci_test/timeout/timeout_test.py
command: python ./circle_ci_test/unit_test/timeout/timeout_test.py
name: timeout_test

workflows:
Expand Down
124 changes: 68 additions & 56 deletions .idea/workspace.xml

Large diffs are not rendered by default.

36 changes: 3 additions & 33 deletions je_auto_control/utils/action_executer/action_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def execute_event(action):
event = event_dict.get(action[0])
if len(action) == 2:
event(**action[1])
else:
elif len(action) == 1:
event()
else:
pass


def execute_action(action_list: list):
Expand All @@ -78,35 +80,3 @@ def execute_action(action_list: list):
print(temp_string)
execute_record_string = "".join([execute_record_string, temp_string + "\n"])
return execute_record_string


if __name__ == "__main__":
import sys

test_list = None
if sys.platform in ["win32", "cygwin", "msys"]:
test_list = [
["type_key", {"keycode": 65}],
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["position"],
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
]
elif sys.platform in ["linux", "linux2"]:
test_list = [
["type_key", {"keycode": 38}],
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["position"],
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
]
elif sys.platform in ["darwin"]:
test_list = [
["type_key", {"keycode": 0x00}],
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["position"],
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
]
print("\n\n")
print(execute_action(test_list))
1 change: 1 addition & 0 deletions je_auto_control/utils/critical_exit/critcal_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def run(self):
if keyboard_check.check_key_is_press(self._exit_check_key):
_thread.interrupt_main()
except AutoControlException:
_thread.interrupt_main()
raise AutoControlException(je_auto_control_critical_exit_error)

def init_critical_exit(self):
Expand Down
8 changes: 4 additions & 4 deletions je_auto_control/wrapper/auto_control_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def press_key(keycode: [int, str], is_shift: bool = False, **kwargs):
if type(keycode) is not int:
try:
keycode = keys_table.get(keycode)
except Exception:
except AutoControlCantFindKeyException:
raise AutoControlCantFindKeyException(table_cant_find_key)
try:
if sys.platform in ["win32", "cygwin", "msys", "linux", "linux2"]:
keyboard.press_key(keycode)
elif sys.platform in ["darwin"]:
keyboard.press_key(keycode, is_shift=is_shift)
return str(keycode)
except Exception:
except AutoControlKeyboardException:
raise AutoControlKeyboardException(keyboard_press_key)


Expand All @@ -42,15 +42,15 @@ def release_key(keycode: [int, str], is_shift: bool = False, **kwargs):
if type(keycode) is not int:
try:
keycode = keys_table.get(keycode)
except Exception:
except AutoControlCantFindKeyException:
raise AutoControlCantFindKeyException(table_cant_find_key)
try:
if sys.platform in ["win32", "cygwin", "msys", "linux", "linux2"]:
keyboard.release_key(keycode)
elif sys.platform in ["darwin"]:
keyboard.release_key(keycode, is_shift=is_shift)
return str(keycode)
except Exception:
except AutoControlKeyboardException:
raise AutoControlKeyboardException(keyboard_release_key)


Expand Down
24 changes: 12 additions & 12 deletions je_auto_control/wrapper/auto_control_mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def position():
"""
try:
return mouse.position()
except Exception:
except AutoControlMouseException:
raise AutoControlMouseException(mouse_get_position)


Expand All @@ -32,7 +32,7 @@ def set_position(x: int, y: int, **kwargs):
try:
mouse.set_position(x=x, y=y)
return x, y
except Exception:
except AutoControlMouseException:
raise AutoControlMouseException(mouse_set_position)


Expand All @@ -47,7 +47,7 @@ def press_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwarg
mouse_keycode = mouse_table.get(mouse_keycode)
else:
pass
except Exception:
except AutoControlCantFindKeyException:
raise AutoControlCantFindKeyException(table_cant_find_key)
try:
now_x, now_y = position()
Expand All @@ -60,7 +60,7 @@ def press_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwarg
elif sys.platform in ["darwin"]:
mouse.press_mouse(x, y, mouse_keycode)
return mouse_keycode, x, y
except Exception:
except AutoControlMouseException:
raise AutoControlMouseException(mouse_press_mouse)


Expand All @@ -75,23 +75,23 @@ def release_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwa
mouse_keycode = mouse_table.get(mouse_keycode)
else:
pass
except Exception:
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 Exception:
except AutoControlMouseException:
raise AutoControlMouseException(mouse_get_position)
try:
if sys.platform in ["win32", "cygwin", "msys", "linux", "linux2"]:
mouse.release_mouse(mouse_keycode)
elif sys.platform in ["darwin"]:
mouse.release_mouse(x, y, mouse_keycode)
return mouse_keycode, x, y
except Exception:
except AutoControlMouseException:
raise AutoControlMouseException(mouse_release_mouse)


Expand All @@ -106,20 +106,20 @@ def click_mouse(mouse_keycode: [int, str], x: int = None, y: int = None, **kwarg
mouse_keycode = mouse_table.get(mouse_keycode)
else:
pass
except Exception:
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 Exception:
except AutoControlMouseException:
raise AutoControlMouseException(mouse_get_position)
try:
mouse.click_mouse(mouse_keycode, x, y)
return mouse_keycode, x, y
except Exception:
except AutoControlMouseException:
raise AutoControlMouseException(mouse_click_mouse)


Expand All @@ -136,7 +136,7 @@ def scroll(scroll_value: int, x: int = None, y: int = None, scroll_direction: st
"""
try:
now_cursor_x, now_cursor_y = position()
except Exception:
except AutoControlMouseException:
raise AutoControlMouseException(mouse_get_position)
width, height = size()
if x is None:
Expand All @@ -162,5 +162,5 @@ def scroll(scroll_value: int, x: int = None, y: int = None, scroll_direction: st
scroll_direction = special_table.get(scroll_direction)
mouse.scroll(scroll_value, scroll_direction)
return scroll_value, scroll_direction
except Exception:
except AutoControlMouseException:
raise AutoControlMouseException(mouse_click_mouse)
38 changes: 7 additions & 31 deletions je_auto_control/wrapper/auto_control_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,8 @@
from je_auto_control.utils.je_auto_control_exception.exception_tag import macos_record_error
from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlException
from je_auto_control.utils.je_auto_control_exception.exceptions import AutoControlJsonActionException
from je_auto_control.wrapper.auto_control_keyboard import type_key
from je_auto_control.wrapper.auto_control_mouse import click_mouse
from je_auto_control.wrapper.platform_wrapper import recorder

event_dict = {"mouse_left": "click_mouse", "mouse_right": "click_mouse", "mouse_middle": "click_mouse",
"keyboard": "type_key"}


def record_mouse():
recorder.record_mouse()


def stop_record_mouse():
action_queue = recorder.stop_record_mouse()
if action_queue is None:
raise AutoControlJsonActionException
for mouse_action in action_queue.queue:
click_mouse(mouse_action[0], mouse_action[1], mouse_action[2])


def record_keyboard():
recorder.record_keyboard()


def stop_record_keyboard():
action_queue = recorder.stop_record_keyboard()
if action_queue is None:
raise AutoControlJsonActionException
for keyboard_action in action_queue.queue:
type_key(keyboard_action[1])


def record():
if sys.platform == "darwin":
Expand All @@ -49,13 +20,18 @@ def stop_record():
if action_queue is None:
raise AutoControlJsonActionException
action_list = list(action_queue.queue)
return execute_action(action_list)
new_list = list()
for action in action_list:
if action[0] == "type_key":
new_list.append([action[0], dict([["keycode", action[1]]])])
else:
new_list.append([action[0], dict(zip(["mouse_keycode", "x", "y"], [action[0], action[1], action[2]]))])
return execute_action(new_list)


if __name__ == "__main__":
record()
from time import sleep

sleep(5)
stop_record()
sleep(2)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="je_auto_control",
version="0.0.73",
version="0.0.75",
author="JE-Chen",
author_email="zenmailman@gmail.com",
description="auto testing",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from je_auto_control.utils.je_auto_control_exception.exceptions import ImageNotFoundException

print(repr(ImageNotFoundException("test.png")))
print(repr(ImageNotFoundException("DW{PD}{DP}W{DOLD}PW{KDP{WKDP}WD][wpa][dwpa][dwaod()DW()Dikwa")))
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["release_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
]

elif sys.platform in ["linux", "linux2"]:
test_list = [
["type_key", {"keycode": 38}],
["type_key", {"keycode": 38}], a
["mouse_left", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
["position"],
["press_mouse", {"mouse_keycode": "mouse_left", "x": 500, "y": 500}],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
list(test_loads_json)

write_action_json(os.getcwd() + "/test.json", test_dumps_json)
read_json = read_action_json(os.getcwd() + "/test.json")
read_json = json.loads(read_action_json(os.getcwd() + "/test.json"))
print(read_json)
File renamed without changes
File renamed without changes