-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote_manager.py
More file actions
271 lines (207 loc) · 10.5 KB
/
Copy pathremote_manager.py
File metadata and controls
271 lines (207 loc) · 10.5 KB
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
""" Remote Interface Software """
import sys
import os
import time
import csv
import win32gui, win32process
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtGui import QIcon, QWindow
from PyQt5 import uic
# =============================================================================
# Points to UI file for class to load and loads drop-downs
# =============================================================================
path = os.getcwd()
FORM_CLASS, _ = uic.loadUiType(path + "\\Assets\\RemoteDash.ui")
class Main(QMainWindow, FORM_CLASS):
""" Setup constructor for project """
def __init__(self, parent=None):
super().__init__(parent)
QMainWindow.__init__(self)
self.setupUi(self)
# Reads from equipment csv file to see what's available
with open(path + "\\Assets\\Equipment.csv") as file_name:
equipment_info = csv.reader(file_name, delimiter=",")
self.EQUIPMENT_LIST = list(equipment_info)
# Load list of available streams to drop-down boxes
self.SELECTION_LIST = []
for item in self.EQUIPMENT_LIST:
self.SELECTION_LIST.append(str(item[0]))
# Grab list of last streams used
self.LAST_STREAMS = []
with open(path + '\\VNC_Connections\\save_file.txt') as save_stream:
for line in save_stream:
self.LAST_STREAMS.append(int(line.strip('\n')))
self.path = os.getcwd()
self.pid_1 = ""
self.pid_2 = ""
self.pid_3 = ""
self.pid_4 = ""
self.pid_5 = ""
self.pid_6 = ""
self.pid_7 = ""
self.pid_8 = ""
self.pid_9 = ""
self.combo1.addItems(self.SELECTION_LIST)
self.combo2.addItems(self.SELECTION_LIST)
self.combo3.addItems(self.SELECTION_LIST)
self.combo4.addItems(self.SELECTION_LIST)
self.combo5.addItems(self.SELECTION_LIST)
self.combo6.addItems(self.SELECTION_LIST)
self.combo7.addItems(self.SELECTION_LIST)
self.combo8.addItems(self.SELECTION_LIST)
self.combo9.addItems(self.SELECTION_LIST)
self.handle_buttons()
def handle_buttons(self):
""" Define Button functionality """
self.pbload.clicked.connect(self.load_last)
self.kill_all.clicked.connect(self.kill_prog)
self.pbkill_1.clicked.connect(self.event_handler)
self.pbkill_2.clicked.connect(self.event_handler)
self.pbkill_3.clicked.connect(self.event_handler)
self.pbkill_4.clicked.connect(self.event_handler)
self.pbkill_5.clicked.connect(self.event_handler)
self.pbkill_6.clicked.connect(self.event_handler)
self.pbkill_7.clicked.connect(self.event_handler)
self.pbkill_8.clicked.connect(self.event_handler)
self.pbkill_9.clicked.connect(self.event_handler)
self.combo1.activated.connect(self.event_handler)
self.combo2.activated.connect(self.event_handler)
self.combo3.activated.connect(self.event_handler)
self.combo4.activated.connect(self.event_handler)
self.combo5.activated.connect(self.event_handler)
self.combo6.activated.connect(self.event_handler)
self.combo7.activated.connect(self.event_handler)
self.combo8.activated.connect(self.event_handler)
self.combo9.activated.connect(self.event_handler)
# =============================================================================
# Stream Handling Functions by Number
# =============================================================================
def event_handler(self):
""" Classic Case structure to decide what method to call """
button_clicked = self.sender()
if button_clicked.objectName() == 'combo1':
self.stream(0, self.pid_1, self.stream1, self.combo1, self.LAST_STREAMS[0])
elif button_clicked.objectName() == 'combo2':
self.stream(1, self.pid_2, self.stream2, self.combo2, self.LAST_STREAMS[1])
elif button_clicked.objectName() == 'combo3':
self.stream(2, self.pid_3, self.stream3, self.combo3, self.LAST_STREAMS[2])
elif button_clicked.objectName() == 'combo4':
self.stream(3, self.pid_4, self.stream4, self.combo4, self.LAST_STREAMS[3])
elif button_clicked.objectName() == 'combo5':
self.stream(4, self.pid_5, self.stream5, self.combo5, self.LAST_STREAMS[4])
elif button_clicked.objectName() == 'combo6':
self.stream(5, self.pid_6, self.stream6, self.combo6, self.LAST_STREAMS[5])
elif button_clicked.objectName() == 'combo7':
self.stream(6, self.pid_7, self.stream7, self.combo7, self.LAST_STREAMS[6])
elif button_clicked.objectName() == 'combo8':
self.stream(7, self.pid_8, self.stream8, self.combo8, self.LAST_STREAMS[7])
elif button_clicked.objectName() == 'combo9':
self.stream(8, self.pid_9, self.stream9, self.combo9, self.LAST_STREAMS[8])
elif button_clicked.objectName() == 'pbkill_1':
self.kill(self.pid_1, self.stream1, self.combo1, self.LAST_STREAMS[0])
elif button_clicked.objectName() == 'pbkill_2':
self.kill(self.pid_2, self.stream2, self.combo2, self.LAST_STREAMS[1])
elif button_clicked.objectName() == 'pbkill_3':
self.kill(self.pid_3, self.stream3, self.combo3, self.LAST_STREAMS[2])
elif button_clicked.objectName() == 'pbkill_4':
self.kill(self.pid_4, self.stream4, self.combo4, self.LAST_STREAMS[3])
elif button_clicked.objectName() == 'pbkill_5':
self.kill(self.pid_5, self.stream5, self.combo5, self.LAST_STREAMS[4])
elif button_clicked.objectName() == 'pbkill_6':
self.kill(self.pid_6, self.stream6, self.combo6, self.LAST_STREAMS[5])
elif button_clicked.objectName() == 'pbkill_7':
self.kill(self.pid_7, self.stream7, self.combo7, self.LAST_STREAMS[6])
elif button_clicked.objectName() == 'pbkill_8':
self.kill(self.pid_8, self.stream8, self.combo8, self.LAST_STREAMS[7])
elif button_clicked.objectName() == 'pbkill_9':
self.kill(self.pid_9, self.stream9, self.combo9, self.LAST_STREAMS[8])
def stream(self, index_id, pid_num, stream_num, combo_num, last):
"""
Opens an instance of TightVNC and embeds it in the UI. \n
INPUT: Combobox selection event. \n
OUTPUT: Opens tightVNC connection and embeds it.
"""
try:
for i in reversed(range(stream_num.count())):
stream_num.itemAt(i).widget().setParent(None)
except AttributeError:
pass
selected_stream = combo_num.currentIndex()
stream_index = self.EQUIPMENT_LIST[selected_stream]
if stream_index != self.EQUIPMENT_LIST[0]:
last = selected_stream
os.system('start /min ' + self.path + '\\VNC_Connections\\' + str(stream_index[1]))
time.sleep(1)
try:
for i in reversed(range(self.stream_num.count())):
stream_num.itemAt(i).widget().setParent(None)
except AttributeError:
pass
external_window = win32gui.FindWindowEx(
0, 0, "TvnWindowClass", stream_index[2]
)
hwnd = win32gui.FindWindow(None, stream_index[2])
threadid, pid_num = win32process.GetWindowThreadProcessId(hwnd)
stream_window = QWindow.fromWinId(external_window)
port_to_box = self.createWindowContainer(stream_window)
stream_num.addWidget(port_to_box)
stream_num.update()
self.LAST_STREAMS[index_id] = last
def kill(self, pid_num, stream_num, combo_num, last):
""" Kills individual stream """
os.system(f'TASKKILL /fi "pid eq ' + str(pid_num) + '"')
try:
for i in reversed(range(stream_num.count())):
stream_num.itemAt(i).widget().setParent(None)
except AttributeError:
pass
combo_num.setCurrentIndex(0)
last = combo_num.currentIndex()
stream_num.update()
def load_last(self):
""" Loads previous streams if there was one """
if self.LAST_STREAMS[0] != "0":
self.combo1.setCurrentIndex(self.LAST_STREAMS[0])
self.stream(0, self.pid_1, self.stream1, self.combo1, self.LAST_STREAMS[0])
if self.LAST_STREAMS[1] != "0":
self.combo2.setCurrentIndex(self.LAST_STREAMS[1])
self.stream(1, self.pid_2, self.stream2, self.combo2, self.LAST_STREAMS[1])
if self.LAST_STREAMS[2] != "0":
self.combo3.setCurrentIndex(self.LAST_STREAMS[2])
self.stream(2, self.pid_3, self.stream3, self.combo3, self.LAST_STREAMS[2])
if self.LAST_STREAMS[3] != "0":
self.combo4.setCurrentIndex(self.LAST_STREAMS[3])
self.stream(3, self.pid_4, self.stream4, self.combo4, self.LAST_STREAMS[3])
if self.LAST_STREAMS[4] != "0":
self.combo5.setCurrentIndex(self.LAST_STREAMS[4])
self.stream(4, self.pid_5, self.stream5, self.combo5, self.LAST_STREAMS[4])
if self.LAST_STREAMS[5] != "0":
self.combo6.setCurrentIndex(self.LAST_STREAMS[5])
self.stream(5, self.pid_6, self.stream6, self.combo6, self.LAST_STREAMS[5])
if self.LAST_STREAMS[6] != "0":
self.combo7.setCurrentIndex(self.LAST_STREAMS[6])
self.stream(6, self.pid_7, self.stream7, self.combo7, self.LAST_STREAMS[6])
if self.LAST_STREAMS[7] != "0":
self.combo8.setCurrentIndex(self.LAST_STREAMS[7])
self.stream(7, self.pid_8, self.stream8, self.combo8, self.LAST_STREAMS[7])
if self.LAST_STREAMS[8] != "0":
self.combo9.setCurrentIndex(self.LAST_STREAMS[8])
self.stream(8, self.pid_9, self.stream9, self.combo9, self.LAST_STREAMS[8])
def kill_prog(self):
""" kill the program """
with open(path + '\\VNC_Connections\\save_file.txt', 'w') as save_file:
for stream in self.LAST_STREAMS:
save_file.write('%s\n' %stream)
self.close()
# =============================================================================
# Launch main application window and set parameters
# =============================================================================
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Main()
window.setWindowIcon(QIcon("Assets\\satellite-dish.ico"))
window.showFullScreen()
try:
sys.exit(app.exec_())
except SystemExit:
os.system('TASKKILL /IM tvnviewer.exe /F')