|
4 | 4 | from PySide6.QtGui import QIntValidator, QDoubleValidator, QKeyEvent, Qt |
5 | 5 | from PySide6.QtWidgets import ( |
6 | 6 | QWidget, QLineEdit, QComboBox, QPushButton, QVBoxLayout, QLabel, |
7 | | - QGridLayout, QHBoxLayout, QRadioButton, QButtonGroup, QMessageBox, |
| 7 | + QGridLayout, QHBoxLayout, QMessageBox, |
8 | 8 | QTabWidget, QTextEdit, QFileDialog, QCheckBox, QGroupBox |
9 | 9 | ) |
10 | 10 |
|
@@ -64,249 +64,6 @@ def __init__(self, parent=None): |
64 | 64 | self.screen_recorder = ScreenRecorder() |
65 | 65 | self._record_data = [] |
66 | 66 |
|
67 | | - # ========================================================================= |
68 | | - # Tab 1: Auto Click |
69 | | - # ========================================================================= |
70 | | - def _build_auto_click_tab(self) -> QWidget: |
71 | | - tab = QWidget() |
72 | | - outer = QVBoxLayout() |
73 | | - |
74 | | - # --- Mouse / Keyboard click group --- |
75 | | - click_group = QGroupBox(_t("tab_auto_click")) |
76 | | - grid = QGridLayout() |
77 | | - row = 0 |
78 | | - |
79 | | - grid.addWidget(QLabel(_t("input_method")), row, 0) |
80 | | - self.mouse_radio = QRadioButton(_t("mouse_radio")) |
81 | | - self.keyboard_radio = QRadioButton(_t("keyboard_radio")) |
82 | | - self.mouse_radio.setChecked(True) |
83 | | - self._input_group = QButtonGroup() |
84 | | - self._input_group.addButton(self.mouse_radio) |
85 | | - self._input_group.addButton(self.keyboard_radio) |
86 | | - h = QHBoxLayout() |
87 | | - h.addWidget(self.mouse_radio) |
88 | | - h.addWidget(self.keyboard_radio) |
89 | | - grid.addLayout(h, row, 1) |
90 | | - |
91 | | - row += 1 |
92 | | - grid.addWidget(QLabel(_t("interval_time")), row, 0) |
93 | | - self.interval_input = QLineEdit("1000") |
94 | | - self.interval_input.setValidator(QIntValidator(1, 999999999)) |
95 | | - grid.addWidget(self.interval_input, row, 1) |
96 | | - |
97 | | - row += 1 |
98 | | - grid.addWidget(QLabel(_t("cursor_x")), row, 0) |
99 | | - self.cursor_x_input = QLineEdit() |
100 | | - self.cursor_x_input.setValidator(QIntValidator()) |
101 | | - grid.addWidget(self.cursor_x_input, row, 1) |
102 | | - |
103 | | - row += 1 |
104 | | - grid.addWidget(QLabel(_t("cursor_y")), row, 0) |
105 | | - self.cursor_y_input = QLineEdit() |
106 | | - self.cursor_y_input.setValidator(QIntValidator()) |
107 | | - grid.addWidget(self.cursor_y_input, row, 1) |
108 | | - |
109 | | - row += 1 |
110 | | - grid.addWidget(QLabel(_t("mouse_button")), row, 0) |
111 | | - self.mouse_button_combo = QComboBox() |
112 | | - self.mouse_button_combo.addItems(list(mouse_keys_table.keys()) if isinstance(mouse_keys_table, dict) else list(mouse_keys_table)) |
113 | | - grid.addWidget(self.mouse_button_combo, row, 1) |
114 | | - |
115 | | - row += 1 |
116 | | - grid.addWidget(QLabel(_t("keyboard_button")), row, 0) |
117 | | - self.keyboard_button_combo = QComboBox() |
118 | | - self.keyboard_button_combo.addItems(list(get_keyboard_keys_table().keys())) |
119 | | - grid.addWidget(self.keyboard_button_combo, row, 1) |
120 | | - |
121 | | - row += 1 |
122 | | - grid.addWidget(QLabel(_t("click_type")), row, 0) |
123 | | - self.click_type_combo = QComboBox() |
124 | | - self.click_type_combo.addItems([_t("single_click"), _t("double_click")]) |
125 | | - grid.addWidget(self.click_type_combo, row, 1) |
126 | | - |
127 | | - row += 1 |
128 | | - self.repeat_until_stopped = QRadioButton(_t("repeat_until_stopped_radio")) |
129 | | - self.repeat_count_times = QRadioButton(_t("repeat_radio")) |
130 | | - self.repeat_count_input = QLineEdit() |
131 | | - self.repeat_count_input.setValidator(QIntValidator(1, 999999999)) |
132 | | - self.repeat_count_input.setPlaceholderText(_t("times")) |
133 | | - rg = QButtonGroup(tab) |
134 | | - rg.addButton(self.repeat_until_stopped) |
135 | | - rg.addButton(self.repeat_count_times) |
136 | | - self.repeat_until_stopped.setChecked(True) |
137 | | - rh = QHBoxLayout() |
138 | | - rh.addWidget(self.repeat_until_stopped) |
139 | | - rh.addWidget(self.repeat_count_times) |
140 | | - rh.addWidget(self.repeat_count_input) |
141 | | - grid.addLayout(rh, row, 0, 1, 2) |
142 | | - |
143 | | - row += 1 |
144 | | - btn_h = QHBoxLayout() |
145 | | - self.start_button = QPushButton(_t("start")) |
146 | | - self.start_button.clicked.connect(self._start_auto_click) |
147 | | - self.stop_button = QPushButton(_t("stop")) |
148 | | - self.stop_button.clicked.connect(self._stop_auto_click) |
149 | | - btn_h.addWidget(self.start_button) |
150 | | - btn_h.addWidget(self.stop_button) |
151 | | - grid.addLayout(btn_h, row, 0, 1, 2) |
152 | | - |
153 | | - click_group.setLayout(grid) |
154 | | - outer.addWidget(click_group) |
155 | | - |
156 | | - # --- Mouse position --- |
157 | | - pos_group = QGroupBox(_t("get_position")) |
158 | | - pos_layout = QHBoxLayout() |
159 | | - self.pos_btn = QPushButton(_t("get_position")) |
160 | | - self.pos_btn.clicked.connect(self._get_mouse_pos) |
161 | | - self.pos_label = QLabel(_t("current_position") + " --") |
162 | | - pos_layout.addWidget(self.pos_btn) |
163 | | - pos_layout.addWidget(self.pos_label) |
164 | | - pos_group.setLayout(pos_layout) |
165 | | - outer.addWidget(pos_group) |
166 | | - |
167 | | - # --- Hotkey --- |
168 | | - hotkey_group = QGroupBox(_t("hotkey_label")) |
169 | | - hk_layout = QHBoxLayout() |
170 | | - self.hotkey_input = QLineEdit() |
171 | | - self.hotkey_input.setPlaceholderText("ctrl,a") |
172 | | - self.hotkey_btn = QPushButton(_t("hotkey_send")) |
173 | | - self.hotkey_btn.clicked.connect(self._send_hotkey) |
174 | | - hk_layout.addWidget(self.hotkey_input) |
175 | | - hk_layout.addWidget(self.hotkey_btn) |
176 | | - hotkey_group.setLayout(hk_layout) |
177 | | - outer.addWidget(hotkey_group) |
178 | | - |
179 | | - # --- Write text --- |
180 | | - write_group = QGroupBox(_t("write_label")) |
181 | | - wr_layout = QHBoxLayout() |
182 | | - self.write_input = QLineEdit() |
183 | | - self.write_btn = QPushButton(_t("write_send")) |
184 | | - self.write_btn.clicked.connect(self._send_write) |
185 | | - wr_layout.addWidget(self.write_input) |
186 | | - wr_layout.addWidget(self.write_btn) |
187 | | - write_group.setLayout(wr_layout) |
188 | | - outer.addWidget(write_group) |
189 | | - |
190 | | - # --- Scroll --- |
191 | | - scroll_group = QGroupBox(_t("mouse_scroll_label")) |
192 | | - sc_layout = QHBoxLayout() |
193 | | - self.scroll_value_input = QLineEdit("3") |
194 | | - self.scroll_value_input.setValidator(QIntValidator()) |
195 | | - sc_layout.addWidget(QLabel(_t("mouse_scroll_label"))) |
196 | | - sc_layout.addWidget(self.scroll_value_input) |
197 | | - if special_mouse_keys_table: |
198 | | - self.scroll_dir_combo = QComboBox() |
199 | | - self.scroll_dir_combo.addItems(list(special_mouse_keys_table.keys())) |
200 | | - sc_layout.addWidget(self.scroll_dir_combo) |
201 | | - else: |
202 | | - self.scroll_dir_combo = None |
203 | | - self.scroll_btn = QPushButton(_t("scroll_send")) |
204 | | - self.scroll_btn.clicked.connect(self._send_scroll) |
205 | | - sc_layout.addWidget(self.scroll_btn) |
206 | | - scroll_group.setLayout(sc_layout) |
207 | | - outer.addWidget(scroll_group) |
208 | | - |
209 | | - outer.addStretch() |
210 | | - |
211 | | - # toggle handler |
212 | | - self.mouse_radio.toggled.connect(self._update_click_mode) |
213 | | - self._update_click_mode() |
214 | | - |
215 | | - tab.setLayout(outer) |
216 | | - return tab |
217 | | - |
218 | | - def _update_click_mode(self): |
219 | | - use_mouse = self.mouse_radio.isChecked() |
220 | | - self.cursor_x_input.setEnabled(use_mouse) |
221 | | - self.cursor_y_input.setEnabled(use_mouse) |
222 | | - self.mouse_button_combo.setEnabled(use_mouse) |
223 | | - self.keyboard_button_combo.setEnabled(not use_mouse) |
224 | | - |
225 | | - def _start_auto_click(self): |
226 | | - try: |
227 | | - interval = int(self.interval_input.text()) |
228 | | - except ValueError: |
229 | | - QMessageBox.warning(self, "Warning", "Interval must be a number") |
230 | | - return |
231 | | - self.repeat_count = 0 |
232 | | - try: |
233 | | - self.repeat_max = int(self.repeat_count_input.text()) |
234 | | - except ValueError: |
235 | | - self.repeat_max = 0 |
236 | | - self.timer.setInterval(interval) |
237 | | - try: |
238 | | - self.timer.timeout.disconnect(self._timer_tick) |
239 | | - except RuntimeError: |
240 | | - pass |
241 | | - self.timer.timeout.connect(self._timer_tick) |
242 | | - self.timer.start() |
243 | | - |
244 | | - def _stop_auto_click(self): |
245 | | - self.timer.stop() |
246 | | - |
247 | | - def _timer_tick(self): |
248 | | - if self.repeat_until_stopped.isChecked(): |
249 | | - self._do_click() |
250 | | - elif self.repeat_count_times.isChecked(): |
251 | | - self.repeat_count += 1 |
252 | | - if self.repeat_count <= self.repeat_max: |
253 | | - self._do_click() |
254 | | - else: |
255 | | - self.repeat_count = 0 |
256 | | - self.timer.stop() |
257 | | - |
258 | | - def _do_click(self): |
259 | | - try: |
260 | | - is_double = self.click_type_combo.currentIndex() == 1 |
261 | | - if self.mouse_radio.isChecked(): |
262 | | - btn = self.mouse_button_combo.currentText() |
263 | | - x = int(self.cursor_x_input.text() or "0") |
264 | | - y = int(self.cursor_y_input.text() or "0") |
265 | | - click_mouse(btn, x, y) |
266 | | - if is_double: |
267 | | - click_mouse(btn, x, y) |
268 | | - else: |
269 | | - key = self.keyboard_button_combo.currentText() |
270 | | - type_keyboard(key) |
271 | | - if is_double: |
272 | | - type_keyboard(key) |
273 | | - except (OSError, ValueError, TypeError, RuntimeError) as error: |
274 | | - self.timer.stop() |
275 | | - QMessageBox.warning(self, "Error", str(error)) |
276 | | - |
277 | | - def _get_mouse_pos(self): |
278 | | - try: |
279 | | - x, y = get_mouse_position() |
280 | | - self.pos_label.setText(_t("current_position") + f" ({x}, {y})") |
281 | | - self.cursor_x_input.setText(str(x)) |
282 | | - self.cursor_y_input.setText(str(y)) |
283 | | - except (OSError, ValueError, TypeError, RuntimeError) as error: |
284 | | - QMessageBox.warning(self, "Error", str(error)) |
285 | | - |
286 | | - def _send_hotkey(self): |
287 | | - try: |
288 | | - keys = [k.strip() for k in self.hotkey_input.text().split(",") if k.strip()] |
289 | | - if keys: |
290 | | - hotkey(keys) |
291 | | - except (OSError, ValueError, TypeError, RuntimeError) as error: |
292 | | - QMessageBox.warning(self, "Error", str(error)) |
293 | | - |
294 | | - def _send_write(self): |
295 | | - try: |
296 | | - text = self.write_input.text() |
297 | | - if text: |
298 | | - write(text) |
299 | | - except (OSError, ValueError, TypeError, RuntimeError) as error: |
300 | | - QMessageBox.warning(self, "Error", str(error)) |
301 | | - |
302 | | - def _send_scroll(self): |
303 | | - try: |
304 | | - val = int(self.scroll_value_input.text() or "3") |
305 | | - direction = self.scroll_dir_combo.currentText() if self.scroll_dir_combo else "scroll_down" |
306 | | - mouse_scroll(val, scroll_direction=direction) |
307 | | - except (OSError, ValueError, TypeError, RuntimeError) as error: |
308 | | - QMessageBox.warning(self, "Error", str(error)) |
309 | | - |
310 | 67 | # ========================================================================= |
311 | 68 | # Tab 2: Screenshot |
312 | 69 | # ========================================================================= |
|
0 commit comments