Skip to content

Commit 045ddb0

Browse files
authored
Merge pull request #323 from taojy123/dev
v5.2
2 parents deab5ba + 85e78dd commit 045ddb0

29 files changed

+1227
-988
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
- [] I have checked the previous issues and there's no simular problems. 我已查看以往的issue并且没有找到类似的问题。
11+
12+
**Describe the bug**
13+
**描述bug**
14+
15+
**To Reproduce**
16+
**如何复现bug**
17+
18+
**Expected behavior**
19+
**期望的结果**
20+
21+
**Screenshots _optional_**
22+
**截图 _可选_**
23+
24+
**Envrionment**
25+
**使用环境**
26+
- OS: e.g. Windows 11 24h2
27+
- 系统: 如Windows 11 24h2
28+
- Software Version: e.g. 5.1.1
29+
- 软件版本: 如 5.1.1
30+
31+
**Additional context**
32+
**附加信息**
33+
_Add any other context about the problem here._
34+
_其它与问题相关的内容。_
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
- [] I have checked the previous issues and there's no simular request. 我已查看以往的issue并且没有找到类似的请求。
11+
12+
**Feature Request**
13+
**请描述你的功能需求**
14+
15+
**Describe the solution you'd like _optional_**
16+
**你想到的解决方案 _可选_**
17+
18+
**Additional context**
19+
**附加信息**
20+
_Add any other context about the problem here._
21+
_其它与问题相关的内容。_

Event/Event.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,25 @@
1-
import time
21
from abc import ABCMeta, abstractmethod
2+
from typing import Dict, Any
33

44

55
class Event(metaclass=ABCMeta):
66
# 传入字典进行初始化
7-
def __init__(self, content):
8-
self.delay = content['delay']
9-
self.event_type = content['event_type']
10-
self.message = content['message']
11-
self.action = content['action']
12-
self.addon = content.get('addon')
7+
def __init__(self, content: Dict[str, Any]):
8+
"""Default param: delay, event_type, message, action"""
9+
for key in ['delay', 'event_type', 'action_type', 'action']:
10+
setattr(self, key, content[key])
1311

1412
def __str__(self):
15-
if self.addon:
16-
return '[%d, %s, %s, %s, %s]' % (self.delay, self.event_type, self.message, self.action, str(self.addon))
17-
return '[%d, %s, %s, %s]' % (self.delay, self.event_type, self.message, self.action)
18-
19-
def summarystr(self):
2013
if self.event_type == 'EK':
21-
return 'key {0} {1} after {2}ms'.format(self.action[1], self.message[4:], self.delay)
14+
return 'key {0} {1} after {2}ms'.format(self.action[1], self.action_type[4:], self.delay)
15+
elif self.event_type == 'EM':
16+
return '{0} at {2} after {1}ms'.format(self.action_type, self.delay, self.action)
2217
else:
23-
return '{0} after {1}ms'.format(self.message, self.delay)
18+
return str(self.__dict__)
2419

2520
# 延时
26-
def sleep(self, thd=None):
27-
if thd:
28-
thd.sleep(self.delay)
29-
else:
30-
time.sleep(self.delay / 1000.0)
21+
def sleep(self, thd):
22+
thd.sleep(self.delay)
3123

3224
@abstractmethod
3325
def execute(self, thd=None):

Event/UniversalEvents.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,39 +45,39 @@ def execute(self, thd=None):
4545
y = int(y * SH)
4646
pyautogui.moveTo(x, y)
4747

48-
if self.message == 'mouse left down':
48+
if self.action_type == 'mouse left down':
4949
pyautogui.mouseDown(button='left')
50-
elif self.message == 'mouse left up':
50+
elif self.action_type == 'mouse left up':
5151
pyautogui.mouseUp(button='left')
52-
elif self.message == 'mouse right down':
52+
elif self.action_type == 'mouse right down':
5353
pyautogui.mouseDown(button='right')
54-
elif self.message == 'mouse right up':
54+
elif self.action_type == 'mouse right up':
5555
pyautogui.mouseUp(button='right')
56-
elif self.message == 'mouse middle down':
56+
elif self.action_type == 'mouse middle down':
5757
pyautogui.mouseDown(button='middle')
58-
elif self.message == 'mouse middle up':
58+
elif self.action_type == 'mouse middle up':
5959
pyautogui.mouseUp(button='middle')
60-
elif self.message == 'mouse wheel up':
60+
elif self.action_type == 'mouse wheel up':
6161
pyautogui.scroll(1)
62-
elif self.message == 'mouse wheel down':
62+
elif self.action_type == 'mouse wheel down':
6363
pyautogui.scroll(-1)
64-
elif self.message == 'mouse move':
64+
elif self.action_type == 'mouse move':
6565
pass
6666
else:
67-
logger.warning('Unknown mouse event:%s' % self.message)
67+
logger.warning('Unknown mouse event:%s' % self.action_type)
6868

6969
elif self.event_type == 'EK':
7070
key_code, key_name, extended = self.action
7171

72-
if self.message == 'key down':
72+
if self.action_type == 'key down':
7373
pyautogui.keyDown(key_name)
74-
elif self.message == 'key up':
74+
elif self.action_type == 'key up':
7575
pyautogui.keyUp(key_name)
7676
else:
77-
logger.warning('Unknown keyboard event:', self.message)
77+
logger.warning('Unknown keyboard event:', self.action_type)
7878

7979
elif self.event_type == 'EX':
80-
if self.message == 'input':
80+
if self.action_type == 'input':
8181
text = self.action
8282
# pyperclip.copy(text)
8383

@@ -88,5 +88,5 @@ def execute(self, thd=None):
8888
# keyboardctl.release('v')
8989
# keyboardctl.release('ctrl')
9090
else:
91-
logger.warning('Unknown extra event:%s' % self.message)
91+
logger.warning('Unknown extra event:%s' % self.action_type)
9292

Event/WindowsEvents.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,26 @@ def execute(self, thd=None):
6464
ny = int(y * 65535)
6565
win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE | win32con.MOUSEEVENTF_MOVE, nx, ny, 0, 0)
6666

67-
if self.message == 'mouse left down':
67+
if self.action_type == 'mouse left down':
6868
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
69-
elif self.message == 'mouse left up':
69+
elif self.action_type == 'mouse left up':
7070
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
71-
elif self.message == 'mouse right down':
71+
elif self.action_type == 'mouse right down':
7272
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
73-
elif self.message == 'mouse right up':
73+
elif self.action_type == 'mouse right up':
7474
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
75-
elif self.message == 'mouse middle down':
75+
elif self.action_type == 'mouse middle down':
7676
win32api.mouse_event(win32con.MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0)
77-
elif self.message == 'mouse middle up':
77+
elif self.action_type == 'mouse middle up':
7878
win32api.mouse_event(win32con.MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0)
79-
elif self.message == 'mouse wheel up':
79+
elif self.action_type == 'mouse wheel up':
8080
win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, win32con.WHEEL_DELTA, 0)
81-
elif self.message == 'mouse wheel down':
81+
elif self.action_type == 'mouse wheel down':
8282
win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, -win32con.WHEEL_DELTA, 0)
83-
elif self.message == 'mouse move':
83+
elif self.action_type == 'mouse move':
8484
pass
8585
else:
86-
logger.warning('Unknown mouse event:%s' % self.message)
86+
logger.warning('Unknown mouse event:%s' % self.action_type)
8787

8888
elif self.event_type == 'EK':
8989
key_code, key_name, extended = self.action
@@ -100,16 +100,16 @@ def execute(self, thd=None):
100100
if extended:
101101
base = win32con.KEYEVENTF_EXTENDEDKEY
102102

103-
if self.message == 'key down':
103+
if self.action_type == 'key down':
104104
win32api.keybd_event(key_code, 0, base, 0)
105-
elif self.message == 'key up':
105+
elif self.action_type == 'key up':
106106
win32api.keybd_event(key_code, 0, base | win32con.KEYEVENTF_KEYUP, 0)
107107
else:
108-
logger.warning('Unknown keyboard event:', self.message)
108+
logger.warning('Unknown keyboard event:', self.action_type)
109109

110110
elif self.event_type == 'EX':
111111

112-
if self.message == 'input':
112+
if self.action_type == 'input':
113113
text = self.action
114114
pyperclip.copy(text)
115115
# Ctrl+V
@@ -118,4 +118,4 @@ def execute(self, thd=None):
118118
win32api.keybd_event(86, 0, win32con.KEYEVENTF_KEYUP, 0)
119119
win32api.keybd_event(162, 0, win32con.KEYEVENTF_KEYUP, 0)
120120
else:
121-
logger.warning('Unknown extra event:%s' % self.message)
121+
logger.warning('Unknown extra event:%s' % self.action_type)

KeymouseGo.py

Lines changed: 26 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,18 @@
55
from PySide6.QtCore import Qt, Slot, QRect
66

77
import UIFunc
8+
import Recorder
89
import argparse
910
from Event import ScriptEvent
1011
from loguru import logger
1112

12-
from assets.plugins.ProcessException import * # noqa: F403
13-
14-
15-
def add_lib_path(libpaths):
16-
for libpath in libpaths:
17-
if os.path.exists(libpath) and (libpath not in sys.path):
18-
sys.path.append(libpath)
13+
from Plugin.Manager import PluginManager
14+
from Util.RunScriptClass import RunScriptCMDClass, StopFlag
1915

2016

2117
def to_abs_path(*args):
22-
return os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), *args)
23-
24-
25-
add_lib_path([os.path.join(to_abs_path('plugins'))])
18+
return os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
19+
*args)
2620

2721

2822
def resize_layout(ui, ratio_w, ratio_h):
@@ -51,52 +45,31 @@ def main():
5145

5246

5347
@logger.catch
54-
def single_run(script_path, run_times=1, speed=100, module_name='Extension'):
48+
def single_run(script_path, run_times):
49+
flag = StopFlag(False)
50+
thread = RunScriptCMDClass(script_path, run_times, flag)
51+
52+
stop_name = 'f9'
53+
5554
@Slot(ScriptEvent)
5655
def on_keyboard_event(event):
5756
key_name = event.action[1].lower()
58-
stop_name = 'f9'
5957
if key_name == stop_name:
6058
logger.debug('break exit!')
61-
os._exit(0)
59+
flag.value = True
60+
thread.resume()
6261
return True
6362

64-
UIFunc.Recorder.setuphook(commandline=True)
65-
UIFunc.Recorder.set_callback(on_keyboard_event)
66-
67-
try:
68-
for path in script_path:
69-
logger.info('Script path:%s' % path)
70-
events, smodule_name, labeldict = UIFunc.RunScriptClass.parsescript(path,
71-
speed=speed)
72-
extension = UIFunc.RunScriptClass.getextension(
73-
smodule_name if smodule_name is not None else module_name,
74-
runtimes=run_times,
75-
speed=speed)
76-
j = 0
77-
extension.onbeginp()
78-
while j < extension.runtimes or extension.runtimes == 0:
79-
logger.info('=========== %d ===========' % j)
80-
try:
81-
if extension.onbeforeeachloop(j):
82-
UIFunc.RunScriptClass.run_script_once(events, extension, labeldict=labeldict)
83-
extension.onaftereachloop(j)
84-
j += 1
85-
except BreakProcess:
86-
logger.debug('Break')
87-
j += 1
88-
continue
89-
except EndProcess:
90-
logger.debug('End')
91-
break
92-
extension.onendp()
93-
logger.info('%s run finish' % path)
94-
logger.info('Scripts run finish!')
95-
except Exception as e:
96-
logger.error(e)
97-
raise e
98-
finally:
99-
os._exit(0)
63+
Recorder.setuphook(commandline=True)
64+
Recorder.set_callback(on_keyboard_event)
65+
66+
PluginManager.reload()
67+
eventloop = QApplication()
68+
69+
thread.finished.connect(eventloop.exit)
70+
thread.start()
71+
72+
sys.exit(eventloop.exec_())
10073

10174

10275
if __name__ == '__main__':
@@ -113,25 +86,10 @@ def on_keyboard_event(event):
11386
type=int,
11487
default=1
11588
)
116-
parser.add_argument('-sp', '--speed',
117-
help='Run speed for the script, input in percentage form',
118-
type=int,
119-
default=100
120-
)
121-
parser.add_argument('-m', '--module',
122-
help='Extension for the program',
123-
type=str,
124-
default='Extension'
125-
)
12689
args = vars(parser.parse_args())
12790
logger.debug(args)
128-
if args['speed'] <= 0:
129-
logger.warning('Unsupported speed')
130-
else:
131-
single_run(args['scripts'],
132-
run_times=args['runtimes'],
133-
speed=args['speed'],
134-
module_name=args['module']
135-
)
91+
single_run(args['scripts'],
92+
run_times=args['runtimes']
93+
)
13694
else:
13795
main()

Plugin/Interface.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from abc import abstractmethod
2+
from typing import Dict, List, Callable
3+
4+
5+
class PluginMeta:
6+
def __init__(self, manifest: Dict):
7+
for key, value in manifest.items():
8+
setattr(self, key, value)
9+
10+
def __str__(self) -> str:
11+
return f'{self.name}:{self.version}'
12+
13+
14+
class PluginInterface:
15+
functions: List[Callable] = []
16+
17+
def __init__(self, manifest: Dict):
18+
self.meta = PluginMeta(manifest)
19+
20+
@abstractmethod
21+
def register_functions(self) -> Dict[str, Callable]:
22+
pass
23+
24+
@abstractmethod
25+
def register_record_functions(self) -> List[Callable]:
26+
pass
27+

0 commit comments

Comments
 (0)