Skip to content

Commit

Permalink
Merge pull request #132 from Integration-Automation/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
JE-Chen authored Nov 13, 2023
2 parents ea0b486 + 29b93cc commit d67677f
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 105 deletions.
76 changes: 52 additions & 24 deletions .idea/workspace.xml

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

2 changes: 1 addition & 1 deletion dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "je_auto_control_dev"
version = "0.0.96"
version = "0.0.97"
authors = [
{ name = "JE-Chen", email = "jechenmailman@gmail.com" },
]
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# -- Project information -----------------------------------------------------

project = 'AutoControl'
copyright = '2020 ~ 2023, JE-Chen'
copyright = '2020 ~ Now, JE-Chen'
author = 'JE-Chen'

# -- General configuration ---------------------------------------------------
Expand Down
29 changes: 15 additions & 14 deletions je_auto_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
callback_executor
# Critical
from je_auto_control.utils.critical_exit.critcal_exit import CriticalExit
from je_auto_control.utils.cv2_utils.screen_record import ScreenRecorder
# utils cv2_utils
from je_auto_control.utils.cv2_utils.screenshot import pil_screenshot
from je_auto_control.utils.exception.exceptions import \
AutoControlActionException
from je_auto_control.utils.exception.exceptions import \
Expand All @@ -32,8 +35,6 @@
from je_auto_control.utils.executor.action_executor import execute_action
from je_auto_control.utils.executor.action_executor import execute_files
from je_auto_control.utils.executor.action_executor import executor
from je_auto_control.utils.project.create_project_structure import \
create_project_dir
# file process
from je_auto_control.utils.file_process.get_dir_file_list import \
get_dir_files_as_list
Expand All @@ -51,17 +52,24 @@
generate_xml
from je_auto_control.utils.generate_report.generate_xml_report import \
generate_xml_report
# utils image
from je_auto_control.utils.image.screenshot import pil_screenshot
# json
from je_auto_control.utils.json.json_file import read_action_json
from je_auto_control.utils.json.json_file import write_action_json
# package manager
from je_auto_control.utils.package_manager.package_manager_class import \
package_manager
from je_auto_control.utils.project.create_project_structure import \
create_project_dir
# Scheduler
from je_auto_control.utils.scheduler.extend_apscheduler import SchedulerManager
# Shell command
from je_auto_control.utils.shell_process.shell_exec import ShellManager
from je_auto_control.utils.shell_process.shell_exec import default_shell_manager
# socket server
from je_auto_control.utils.socket_server.auto_control_socket_server import \
start_autocontrol_socket_server
# Start exe
from je_auto_control.utils.start_exe.start_another_process import start_exe
# test record
from je_auto_control.utils.test_record.record_test_class import \
test_record_instance
Expand All @@ -83,26 +91,19 @@
from je_auto_control.wrapper.auto_control_keyboard import write
# import mouse
from je_auto_control.wrapper.auto_control_mouse import click_mouse
from je_auto_control.wrapper.auto_control_mouse import mouse_keys_table
from je_auto_control.wrapper.auto_control_mouse import get_mouse_position
from je_auto_control.wrapper.auto_control_mouse import mouse_keys_table
from je_auto_control.wrapper.auto_control_mouse import mouse_scroll
from je_auto_control.wrapper.auto_control_mouse import press_mouse
from je_auto_control.wrapper.auto_control_mouse import release_mouse
from je_auto_control.wrapper.auto_control_mouse import mouse_scroll
from je_auto_control.wrapper.auto_control_mouse import set_mouse_position
from je_auto_control.wrapper.auto_control_mouse import special_mouse_keys_table
# test_record
from je_auto_control.wrapper.auto_control_record import record
from je_auto_control.wrapper.auto_control_record import stop_record
from je_auto_control.wrapper.auto_control_screen import screenshot
# import screen
from je_auto_control.wrapper.auto_control_screen import screen_size
# Shell command
from je_auto_control.utils.shell_process.shell_exec import ShellManager
from je_auto_control.utils.shell_process.shell_exec import default_shell_manager
# Start exe
from je_auto_control.utils.start_exe.start_another_process import start_exe
# Scheduler
from je_auto_control.utils.scheduler.extend_apscheduler import SchedulerManager
from je_auto_control.wrapper.auto_control_screen import screenshot

__all__ = [
"click_mouse", "mouse_keys_table", "get_mouse_position", "press_mouse", "release_mouse",
Expand Down
10 changes: 5 additions & 5 deletions je_auto_control/utils/callback/callback_function_executor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Callable, Any
from sys import stderr
from typing import Callable, Any

# utils cv2_utils
from je_auto_control.utils.cv2_utils.screenshot import pil_screenshot
from je_auto_control.utils.exception.exception_tags import get_bad_trigger_method, get_bad_trigger_function
from je_auto_control.utils.exception.exceptions import CallbackExecutorException
# executor
Expand All @@ -16,8 +18,6 @@
# xml
from je_auto_control.utils.generate_report.generate_xml_report import generate_xml
from je_auto_control.utils.generate_report.generate_xml_report import generate_xml_report
# utils image
from je_auto_control.utils.image.screenshot import pil_screenshot
# json
from je_auto_control.utils.json.json_file import read_action_json
from je_auto_control.utils.json.json_file import write_action_json
Expand All @@ -30,7 +30,7 @@
from je_auto_control.utils.start_exe.start_another_process import start_exe
# test record
from je_auto_control.utils.test_record.record_test_class import test_record_instance
# import image
# import cv2_utils
from je_auto_control.wrapper.auto_control_image import locate_all_image
from je_auto_control.wrapper.auto_control_image import locate_and_click
from je_auto_control.wrapper.auto_control_image import locate_image_center
Expand Down Expand Up @@ -80,7 +80,7 @@ def __init__(self):
"AC_check_key_is_press": check_key_is_press,
"AC_write": write,
"AC_hotkey": hotkey,
# image
# cv2_utils
"AC_locate_all_image": locate_all_image,
"AC_locate_image_center": locate_image_center,
"AC_locate_and_click": locate_and_click,
Expand Down
File renamed without changes.
40 changes: 40 additions & 0 deletions je_auto_control/utils/cv2_utils/screen_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import threading
from typing import Dict, Tuple

from cv2 import VideoWriter

from je_auto_control.wrapper.auto_control_screen import screenshot


class ScreenRecorder(object):

def __init__(self):
self.running_recorder: Dict[str, ScreenRecordThread] = {}

def start_new_recode(self, recoder_name: str, path_and_filename: str = "output.avi", codec: str = "XVID",
frame_per_sec: int = 30, resolution: Tuple[int, int] = (1920, 1080)):
record_thread = ScreenRecordThread(path_and_filename, codec, frame_per_sec, resolution)
old_record = self.running_recorder.get(recoder_name, None)
if old_record is not None:
old_record.record_flag = False
record_thread.daemon = True
record_thread.start()
self.running_recorder.update({recoder_name: record_thread})


class ScreenRecordThread(threading.Thread):

def __init__(self, path_and_filename, codec, frame_per_sec, resolution: Tuple[int, int]):
super().__init__()
self.fourcc = VideoWriter.fourcc(*codec)
self.video_writer = VideoWriter(path_and_filename, self.fourcc, frame_per_sec, resolution)
self.record_flag = False

def run(self) -> None:
self.record_flag = True
while self.record_flag:
# Get raw pixels from the screen, save it to a Numpy array
image = screenshot()
self.video_writer.write(image)
else:
self.video_writer.release()
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

def find_image(image, detect_threshold: float = 1, draw_image: bool = False) -> List[int]:
"""
:param image which image we want to find on screen
:param image which cv2_utils we want to find on screen
:param detect_threshold detect precision 0.0 ~ 1.0; 1 is absolute equal
:param draw_image draw detect tag on return image
:param draw_image draw detect tag on return cv2_utils
"""
grab_image = ImageGrab.grab()
return template_detection.find_object(image=grab_image, template=image,
Expand All @@ -17,9 +17,9 @@ def find_image(image, detect_threshold: float = 1, draw_image: bool = False) ->

def find_image_multi(image, detect_threshold: float = 1, draw_image: bool = False) -> List[List[int]]:
"""
:param image which image we want to find on screen
:param image which cv2_utils we want to find on screen
:param detect_threshold detect precision 0.0 ~ 1.0; 1 is absolute equal
:param draw_image draw detect tag on return image
:param draw_image draw detect tag on return cv2_utils
"""
grab_image = ImageGrab.grab()
return template_detection.find_multi_object(image=grab_image, template=image,
Expand Down
4 changes: 2 additions & 2 deletions je_auto_control/utils/exception/exception_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
screen_screenshot: str = "screen screenshot error"
# table tags
table_cant_find_key: str = "cant find key error"
# image tags
cant_find_image: str = "cant find image"
# cv2_utils tags
cant_find_image: str = "cant find cv2_utils"
find_image_error_variable: str = "variable error"
# listener tags
listener_error: str = "Auto control listener error"
Expand Down
2 changes: 1 addition & 1 deletion je_auto_control/utils/executor/action_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self):
"AC_check_key_is_press": check_key_is_press,
"AC_write": write,
"AC_hotkey": hotkey,
# image
# cv2_utils
"AC_locate_all_image": locate_all_image,
"AC_locate_image_center": locate_image_center,
"AC_locate_and_click": locate_and_click,
Expand Down
Loading

0 comments on commit d67677f

Please sign in to comment.