forked from aidygus/LinVAM
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommandeditwnd.py
189 lines (165 loc) · 8.29 KB
/
commandeditwnd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from ui_commandeditwnd import Ui_CommandEditDialog
from keyactioneditwnd import KeyActionEditWnd
from mouseactioneditwnd import MouseActionEditWnd
from pauseactioneditwnd import PauseActionEditWnd
from soundactioneditwnd import SoundActionEditWnd
import json
class CommandEditWnd(QDialog):
def __init__(self, p_command, p_parent = None):
super().__init__(p_parent)
self.ui = Ui_CommandEditDialog()
self.ui.setupUi(self)
self.m_parent = p_parent
self.ui.deleteBut.clicked.connect(self.slotDelete)
self.ui.ok.clicked.connect(self.slotOK)
self.ui.cancel.clicked.connect(self.slotCancel)
self.ui.keyBut.clicked.connect(self.slotNewKeyEdit)
self.ui.mouseBut.clicked.connect(self.slotNewMouseEdit)
self.ui.pauseBut.clicked.connect(self.slotNewPauseEdit)
self.ui.upBut.clicked.connect(self.slotActionUp)
self.ui.downBut.clicked.connect(self.slotActionDown)
self.ui.editBut.clicked.connect(self.slotActionEdit)
self.ui.actionsListWidget.doubleClicked.connect(self.slotActionEdit)
w_otherMenu = QMenu()
w_otherMenu.addAction('Stop Another Command', self.slotStopAnotherCommand)
w_otherMenu.addAction('Execute Another Command', self.slotDoAnotherCommand)
w_otherMenu.addAction('Play Sound', self.slotNewSoundEdit)
self.ui.otherBut.setMenu(w_otherMenu)
self.m_command = {}
if p_command != None:
self.ui.say.setText(p_command['name'])
self.ui.thresholdSpin.setValue(p_command['threshold'])
w_actions = p_command['actions']
for w_action in w_actions:
w_jsonAction = json.dumps(w_action)
w_item = QListWidgetItem(w_jsonAction)
w_item.setData(Qt.UserRole, w_jsonAction)
self.ui.actionsListWidget.addItem(w_item)
self.ui.asyncChk.setChecked(p_command['async'])
if p_command['repeat'] == -1:
self.ui.continueExe.setChecked(True)
elif p_command['repeat'] == 1:
self.ui.oneExe.setChecked(True)
else:
self.ui.repeatExe.setChecked(True)
self.ui.repeatCnt.setValue(p_command['repeat'])
else:
self.ui.asyncChk.setChecked(False)
self.ui.oneExe.setChecked(True)
def addAction(self, p_action):
w_jsonAction = json.dumps(p_action)
w_item = QListWidgetItem(w_jsonAction)
w_item.setData(Qt.UserRole, w_jsonAction)
self.ui.actionsListWidget.addItem(w_item)
def slotStopAnotherCommand(self):
text, okPressed = QInputDialog.getText(self, "Get Command Name", "Another command name:", QLineEdit.Normal, "")
if okPressed and text != '':
w_commandStopAction = {}
w_commandStopAction['name'] = 'command stop action'
w_commandStopAction['command name'] = text
self.addAction(w_commandStopAction)
def slotDoAnotherCommand(self):
text, okPressed = QInputDialog.getText(self, "Get Command Name", "Another command name:", QLineEdit.Normal, "")
if okPressed and text != '':
w_commandDoAction = {}
w_commandDoAction['name'] = 'command execute action'
w_commandDoAction['command name'] = text
self.addAction(w_commandDoAction)
def slotDoPlaySound(self):
text, okPressed = QInputDialog.getItem(self, "Set sound to play", "Enter sound file:", list(self.m_parent.m_parent.m_sound.m_sounds), 0, False)
if okPressed and text != '':
w_commandDoAction = {}
w_commandDoAction['name'] = 'command play sound'
w_commandDoAction['command name'] = text
self.addAction(w_commandDoAction)
def slotNewKeyEdit(self):
w_keyEditWnd = KeyActionEditWnd(None, self)
if w_keyEditWnd.exec() == QDialog.Accepted:
self.addAction(w_keyEditWnd.m_keyAction)
def slotNewMouseEdit(self):
w_mouseEditWnd = MouseActionEditWnd(None, self)
if w_mouseEditWnd.exec() == QDialog.Accepted:
self.addAction(w_mouseEditWnd.m_mouseAction)
def slotNewPauseEdit(self):
w_pauseEditWnd = PauseActionEditWnd(None, self)
if w_pauseEditWnd.exec() == QDialog.Accepted:
self.addAction(w_pauseEditWnd.m_pauseAction)
def slotNewSoundEdit(self):
w_soundEditWnd = SoundActionEditWnd(self.m_parent.m_parent.m_sound, None, self)
if w_soundEditWnd.exec() == QDialog.Accepted:
self.addAction(w_soundEditWnd.m_soundAction)
def slotActionUp(self):
currentIndex = self.ui.actionsListWidget.currentRow()
currentItem = self.ui.actionsListWidget.takeItem(currentIndex);
self.ui.actionsListWidget.insertItem(currentIndex - 1, currentItem);
self.ui.actionsListWidget.setCurrentRow(currentIndex - 1);
def slotActionDown(self):
currentIndex = self.ui.actionsListWidget.currentRow();
currentItem = self.ui.actionsListWidget.takeItem(currentIndex);
self.ui.actionsListWidget.insertItem(currentIndex + 1, currentItem);
self.ui.actionsListWidget.setCurrentRow(currentIndex + 1);
def slotActionEdit(self):
w_listItems = self.ui.actionsListWidget.selectedItems()
if not w_listItems: return
w_action = {}
for w_item in w_listItems:
w_jsonAction = w_item.data(Qt.UserRole)
w_action = json.loads(w_jsonAction)
break
if w_action['name'] == 'key action':
w_keyEditWnd = KeyActionEditWnd(w_action, self)
if w_keyEditWnd.exec() == QDialog.Accepted:
w_jsonAction = json.dumps(w_keyEditWnd.m_keyAction)
elif w_action['name'] == 'mouse click action' \
or w_action['name'] == 'mouse move action'\
or w_action['name'] == 'mouse scroll action':
w_mouseEditWnd = MouseActionEditWnd(w_action, self)
if w_mouseEditWnd.exec() == QDialog.Accepted:
w_jsonAction = json.dumps(w_mouseEditWnd.m_mouseAction)
elif w_action['name'] == 'pause action':
w_pauseEditWnd = PauseActionEditWnd(w_action, self)
if w_pauseEditWnd.exec() == QDialog.Accepted:
w_jsonAction = json.dumps(w_pauseEditWnd.m_pauseAction)
elif w_action['name'] == 'command stop action' \
or w_action['name'] == 'command execute action':
text, okPressed = QInputDialog.getText(self, "Get Command Name", "Another command name:", QLineEdit.Normal,
w_action['command name'])
if okPressed and text != '':
w_action['command name'] = text
w_jsonAction = json.dumps(w_action)
elif w_action['name'] == 'play sound':
w_soundEditWnd = SoundActionEditWnd(self.m_parent.m_parent.m_sound, w_action, self)
if w_soundEditWnd.exec() == QDialog.Accepted:
w_jsonAction = json.dumps(w_soundEditWnd.m_soundAction)
w_item.setText(w_jsonAction)
w_item.setData(Qt.UserRole, w_jsonAction)
def slotDelete(self):
w_listItems = self.ui.actionsListWidget.selectedItems()
if not w_listItems: return
for w_item in w_listItems:
self.ui.actionsListWidget.takeItem(self.ui.actionsListWidget.row(w_item))
def saveCommand(self):
w_actionCnt = self.ui.actionsListWidget.count()
self.m_command['name'] = self.ui.say.text()
w_actions = []
for w_idx in range(w_actionCnt):
w_jsonAction = self.ui.actionsListWidget.item(w_idx).data(Qt.UserRole)
w_action = json.loads(w_jsonAction)
w_actions.append(w_action)
self.m_command['actions'] = w_actions
self.m_command['async'] = self.ui.asyncChk.isChecked()
self.m_command['threshold'] = self.ui.thresholdSpin.value()
if self.ui.oneExe.isChecked():
self.m_command['repeat'] = 1
elif self.ui.continueExe.isChecked():
self.m_command['repeat'] = -1
elif self.ui.repeatExe.isChecked():
self.m_command['repeat'] = self.ui.repeatCnt.value()
def slotOK(self):
self.saveCommand()
super().accept()
def slotCancel(self):
super().reject()