Skip to content

Commit 0bc476f

Browse files
authored
Merge pull request #154 from Integration-Automation/dev
Dev
2 parents 80174bb + c0f35c4 commit 0bc476f

File tree

15 files changed

+337
-61
lines changed

15 files changed

+337
-61
lines changed

.github/workflows/dev_python3_9.yml renamed to .github/workflows/dev_python3_12.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717

1818
steps:
1919
- uses: actions/checkout@v3
20-
- name: Set up Python 3.9
20+
- name: Set up Python 3.12
2121
uses: actions/setup-python@v3
2222
with:
23-
python-version: "3.9"
23+
python-version: "3.12"
2424
- name: Install dependencies
2525
run: |
2626
python -m pip install --upgrade pip wheel

.github/workflows/stable_python3_9.yml renamed to .github/workflows/stable_python3_12.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717

1818
steps:
1919
- uses: actions/checkout@v3
20-
- name: Set up Python 3.9
20+
- name: Set up Python 3.12
2121
uses: actions/setup-python@v3
2222
with:
23-
python-version: "3.9"
23+
python-version: "3.12"
2424
- name: Install dependencies
2525
run: |
2626
python -m pip install --upgrade pip wheel

.idea/workspace.xml

Lines changed: 50 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@ build-backend = "setuptools.build_meta"
66

77
[project]
88
name = "je_auto_control_dev"
9-
version = "0.0.111"
9+
version = "0.0.116"
1010
authors = [
1111
{ name = "JE-Chen", email = "[email protected]" },
1212
]
1313
description = "GUI Automation Framework"
14-
requires-python = ">=3.9"
14+
requires-python = ">=3.10"
1515
license-files = ["LICENSE"]
1616
dependencies = [
1717
"je_open_cv",
1818
"pillow",
19-
"Pyside6==6.9.0",
2019
"pyobjc-core;platform_system=='Darwin'",
2120
"pyobjc;platform_system=='Darwin'",
2221
"python-Xlib;platform_system=='Linux'",
2322
"mss"
2423
]
2524
classifiers = [
26-
"Programming Language :: Python :: 3.9",
25+
"Programming Language :: Python :: 3.10",
2726
"Development Status :: 2 - Pre-Alpha",
2827
"Environment :: Win32 (MS Windows)",
2928
"Environment :: MacOS X",
@@ -44,4 +43,4 @@ content-type = "text/markdown"
4443
find = { namespaces = false }
4544

4645
[project.optional-dependencies]
47-
gui = ["Pyside6", "qt-material"]
46+
gui = ["PySide6==6.9.1", "qt-material"]

je_auto_control/gui/__init__.py

Whitespace-only changes.

je_auto_control/gui/language_wrapper/__init__.py

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
english_word_dict = {
2+
# Main
3+
"application_name": "AutoControlGUI",
4+
# Widget
5+
"interval_time": "Interval Time (s):",
6+
"cursor_x": "Cursor X Position:",
7+
"cursor_y": "Cursor Y Position:",
8+
"mouse_button": "Mouse Button:",
9+
"keyboard_button": "Keyboard Button:",
10+
"click_type": "Click Type:",
11+
"input_method": "Input Method:",
12+
"mouse_radio": "Mouse",
13+
"keyboard_radio": "Keyboard",
14+
"repeat_until_stopped_radio": "Repeat until stopped",
15+
"repeat_radio": "Repeat",
16+
"times": "Times",
17+
"start": "Start",
18+
"stop": "Stop",
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from je_auto_control.gui.language_wrapper.english import english_word_dict
2+
from je_auto_control.gui.language_wrapper.traditional_chinese import traditional_chinese_word_dict
3+
from je_auto_control.utils.logging.loggin_instance import autocontrol_logger
4+
5+
6+
7+
class LanguageWrapper(object):
8+
9+
def __init__(
10+
self
11+
):
12+
autocontrol_logger.info("Init LanguageWrapper")
13+
self.language: str = "English"
14+
self.choose_language_dict = {
15+
"English": english_word_dict,
16+
"Traditional_Chinese": traditional_chinese_word_dict
17+
}
18+
self.language_word_dict: dict = self.choose_language_dict.get(self.language)
19+
20+
def reset_language(self, language) -> None:
21+
autocontrol_logger.info(f"LanguageWrapper reset_language language: {language}")
22+
if language in [
23+
"English",
24+
"Traditional_Chinese"
25+
]:
26+
self.language = language
27+
self.language_word_dict = self.choose_language_dict.get(self.language)
28+
29+
30+
language_wrapper = LanguageWrapper()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
traditional_chinese_word_dict = {
2+
# Main
3+
"application_name": "AutoControlGUI",
4+
# Widget
5+
"interval_time": "間隔時間(秒):",
6+
"cursor_x": "滑鼠游標 X 軸位置:",
7+
"cursor_y": "滑鼠游標 Y 軸位置:",
8+
"mouse_button": "滑鼠按鍵:",
9+
"keyboard_button": "鍵盤按鍵:",
10+
"click_type": "點擊類型:",
11+
"input_method": "輸入方式:",
12+
"mouse_radio": "滑鼠",
13+
"keyboard_radio": "鍵盤",
14+
"repeat_until_stopped_radio": "重複直到停止",
15+
"repeat_radio": "重複",
16+
"times": "次數",
17+
"start": "開始",
18+
"stop": "停止",
19+
}

je_auto_control/gui/main_widget.py

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
from PySide6.QtCore import QTimer
2+
from PySide6.QtGui import QIntValidator, QKeyEvent, Qt
3+
from PySide6.QtWidgets import (
4+
QWidget, QLineEdit, QComboBox, QPushButton, QVBoxLayout, QLabel,
5+
QGridLayout, QHBoxLayout, QRadioButton, QButtonGroup, QMessageBox
6+
)
7+
8+
from je_auto_control.gui.language_wrapper.multi_language_wrapper import language_wrapper
9+
from je_auto_control.utils.executor.action_executor import execute_action
10+
from je_auto_control.wrapper.auto_control_keyboard import type_keyboard
11+
from je_auto_control.wrapper.auto_control_mouse import click_mouse
12+
from je_auto_control.wrapper.auto_control_record import record, stop_record
13+
from je_auto_control.wrapper.platform_wrapper import keyboard_keys_table, mouse_keys_table
14+
15+
16+
class AutoControlGUIWidget(QWidget):
17+
18+
def __init__(self, parent=None):
19+
super().__init__(parent)
20+
21+
main_layout = QVBoxLayout()
22+
23+
# Grid for input fields
24+
grid = QGridLayout()
25+
26+
# Interval time
27+
grid.addWidget(QLabel(language_wrapper.language_word_dict.get("interval_time")), 0, 0)
28+
self.interval_input = QLineEdit()
29+
self.interval_input.setValidator(QIntValidator())
30+
grid.addWidget(self.interval_input, 0, 1)
31+
32+
# Cursor X/Y
33+
grid.addWidget(QLabel(language_wrapper.language_word_dict.get("cursor_x")), 2, 0)
34+
self.cursor_x_input = QLineEdit()
35+
self.cursor_x_input.setValidator(QIntValidator())
36+
grid.addWidget(self.cursor_x_input, 2, 1)
37+
38+
grid.addWidget(QLabel(language_wrapper.language_word_dict.get("cursor_y")), 3, 0)
39+
self.cursor_y_input = QLineEdit()
40+
self.cursor_y_input.setValidator(QIntValidator())
41+
grid.addWidget(self.cursor_y_input, 3, 1)
42+
43+
# Mouse button
44+
grid.addWidget(QLabel(language_wrapper.language_word_dict.get("mouse_button")), 4, 0)
45+
self.mouse_button_combo = QComboBox()
46+
self.mouse_button_combo.addItems(mouse_keys_table)
47+
grid.addWidget(self.mouse_button_combo, 4, 1)
48+
49+
# Keyboard button
50+
grid.addWidget(QLabel(language_wrapper.language_word_dict.get("keyboard_button")), 5, 0)
51+
self.keyboard_button_combo = QComboBox()
52+
self.keyboard_button_combo.addItems(keyboard_keys_table.keys())
53+
grid.addWidget(self.keyboard_button_combo, 5, 1)
54+
55+
# Click type
56+
grid.addWidget(QLabel(language_wrapper.language_word_dict.get("click_type")), 6, 0)
57+
self.click_type_combo = QComboBox()
58+
self.click_type_combo.addItems(["Single Click", "Double Click"])
59+
grid.addWidget(self.click_type_combo, 6, 1)
60+
61+
# Input method selection
62+
grid.addWidget(QLabel(language_wrapper.language_word_dict.get("input_method")), 7, 0)
63+
self.mouse_radio = QRadioButton(language_wrapper.language_word_dict.get("mouse_radio"))
64+
self.keyboard_radio = QRadioButton(language_wrapper.language_word_dict.get("keyboard_radio"))
65+
self.mouse_radio.setChecked(True)
66+
self.input_method_group = QButtonGroup()
67+
self.input_method_group.addButton(self.mouse_radio)
68+
self.input_method_group.addButton(self.keyboard_radio)
69+
grid.addWidget(self.mouse_radio, 7, 1)
70+
grid.addWidget(self.keyboard_radio, 7, 2)
71+
72+
main_layout.addLayout(grid)
73+
74+
# Repeat options
75+
repeat_layout = QHBoxLayout()
76+
self.repeat_until_stopped = QRadioButton(language_wrapper.language_word_dict.get("repeat_until_stopped_radio"))
77+
self.repeat_count_times = QRadioButton(language_wrapper.language_word_dict.get("repeat_radio"))
78+
self.repeat_count_input = QLineEdit()
79+
self.repeat_count_input.setValidator(QIntValidator())
80+
self.repeat_count_input.setPlaceholderText(language_wrapper.language_word_dict.get("times"))
81+
repeat_group = QButtonGroup()
82+
repeat_group.addButton(self.repeat_until_stopped)
83+
repeat_group.addButton(self.repeat_count_times)
84+
self.repeat_until_stopped.setChecked(True)
85+
self.repeat_count = 0
86+
self.repeat_max = 0
87+
88+
repeat_layout.addWidget(self.repeat_until_stopped)
89+
repeat_layout.addWidget(self.repeat_count_times)
90+
repeat_layout.addWidget(self.repeat_count_input)
91+
main_layout.addLayout(repeat_layout)
92+
93+
# Start/Stop buttons
94+
button_layout = QHBoxLayout()
95+
self.start_button = QPushButton(language_wrapper.language_word_dict.get("start"))
96+
self.start_button.clicked.connect(self.start_autocontrol)
97+
self.stop_button = QPushButton(language_wrapper.language_word_dict.get("stop"))
98+
self.stop_button.clicked.connect(self.stop_autocontrol)
99+
button_layout.addWidget(self.start_button)
100+
button_layout.addWidget(self.stop_button)
101+
main_layout.addLayout(button_layout)
102+
103+
# Timer
104+
self.start_autocontrol_timer = QTimer()
105+
106+
# Connect input method toggle
107+
self.mouse_radio.toggled.connect(self.update_input_mode)
108+
self.keyboard_radio.toggled.connect(self.update_input_mode)
109+
self.update_input_mode()
110+
111+
self.setLayout(main_layout)
112+
113+
def update_input_mode(self):
114+
use_mouse = self.mouse_radio.isChecked()
115+
self.cursor_x_input.setEnabled(use_mouse)
116+
self.cursor_y_input.setEnabled(use_mouse)
117+
self.mouse_button_combo.setEnabled(use_mouse)
118+
self.keyboard_button_combo.setEnabled(not use_mouse)
119+
120+
def start_autocontrol(self):
121+
self.start_autocontrol_timer.setInterval(int(self.interval_input.text()))
122+
self.start_autocontrol_timer.timeout.connect(lambda: self.start_timer_function())
123+
self.start_autocontrol_timer.start()
124+
self.repeat_max = int(self.repeat_count_input.text())
125+
126+
def start_timer_function(self):
127+
if self.repeat_until_stopped.isChecked():
128+
self.trigger_autocontrol_function()
129+
elif self.repeat_count_times.isChecked():
130+
self.repeat_count += 1
131+
if self.repeat_count < self.repeat_max:
132+
self.trigger_autocontrol_function()
133+
else:
134+
self.repeat_count = 0
135+
self.repeat_max = 0
136+
self.start_autocontrol_timer.stop()
137+
138+
def trigger_autocontrol_function(self):
139+
click_type = self.click_type_combo.currentText()
140+
if self.mouse_radio.isChecked():
141+
trigger_function = click_mouse
142+
button = self.mouse_button_combo.currentText()
143+
x = int(self.cursor_x_input.text())
144+
y = int(self.cursor_y_input.text())
145+
if click_type == "Single Click":
146+
trigger_function(mouse_keycode=button, x=x, y=y)
147+
elif click_type == "Double Click":
148+
trigger_function(mouse_keycode=button, x=x, y=y)
149+
trigger_function(mouse_keycode=button, x=x, y=y)
150+
elif self.keyboard_radio.isChecked():
151+
trigger_function = type_keyboard
152+
button = self.keyboard_button_combo.currentText()
153+
if click_type == "Single Click":
154+
trigger_function(keycode=button)
155+
elif click_type == "Double Click":
156+
trigger_function(keycode=button)
157+
trigger_function(keycode=button)
158+
159+
def stop_autocontrol(self):
160+
self.start_autocontrol_timer.stop()
161+
162+
163+
def keyPressEvent(self, event: QKeyEvent):
164+
if event.modifiers() == Qt.KeyboardModifier.ControlModifier and event.key() == Qt.Key.Key_4:
165+
self.start_autocontrol_timer.stop()
166+
else:
167+
super().keyPressEvent(event)

0 commit comments

Comments
 (0)