-
Notifications
You must be signed in to change notification settings - Fork 5
/
dialogs.py
298 lines (257 loc) · 9.92 KB
/
dialogs.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
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import os
import advanced_ui
import markers_ui
import specific_ui
import timeout_ui
from PyQt5 import QtCore
from PyQt5.QtWidgets import (
QWidget,
QDialog,
QApplication,
QGridLayout,
QLabel,
QLineEdit,
QDialogButtonBox,
QMessageBox,
QCheckBox,
)
from PyQt5.QtGui import QPalette
from PyQt5.QtCore import QTime, QTimer, Qt
class advdialog(QDialog):
def __init__(self, gui, parent=None):
QWidget.__init__(self, parent)
self.gui = gui
self.ui = advanced_ui.Ui_Dialog()
self.ui.setupUi(self)
def keyPressEvent(self, event):
k = event.key()
if k == Qt.Key_Enter or k == Qt.Key_Return:
return
QDialog.keyPressEvent(self, event)
def closeEvent(self, event):
self.gui.ui.showexpert.setChecked(False)
QDialog.closeEvent(self, event)
class markerdialog(QDialog):
def __init__(self, gui, parent=None):
QWidget.__init__(self, parent)
self.gui = gui
self.ui = markers_ui.Ui_Dialog()
self.ui.setupUi(self)
class specificdialog(QDialog):
def __init__(self, gui, parent=None):
QWidget.__init__(self, parent)
self.gui = gui
self.ui = specific_ui.Ui_Dialog()
self.ui.setupUi(self)
def keyPressEvent(self, event):
k = event.key()
if k == Qt.Key_Enter or k == Qt.Key_Return:
return
QDialog.keyPressEvent(self, event)
def closeEvent(self, event):
QDialog.closeEvent(self, event)
class timeoutdialog(QDialog):
def __init__(self, gui, idle, parent=None):
QWidget.__init__(self, parent)
self.gui = gui
self.ui = timeout_ui.Ui_Dialog()
self.ui.setupUi(self)
try:
self.idle = int(idle)
except Exception:
self.idle = None
if self.idle is not None:
self.SMALLTIMESECS = 3600
self.BIGTIMESECS = self.idle * 3600
self.show9 = False
else:
self.SMALLTIMESECS = 3600
self.BIGTIMESECS = 9 * 3600
self.show9 = True
self.zerotime = QTime(0, 0, 0)
self.smalltime = QTime(
self.SMALLTIMESECS / 3600,
(self.SMALLTIMESECS % 3600) / 60,
self.SMALLTIMESECS % 60,
)
self.bigtime = QTime(
self.BIGTIMESECS / 3600,
(self.BIGTIMESECS % 3600) / 60,
self.BIGTIMESECS % 60,
)
self.timer = QTimer()
self.timeValue = QTime(0, 0, 0)
self.ui.TimeDisplay.display(self.timeValue.toString("hh:mm:ss"))
self.timer.timeout.connect(self.decrement)
self.ui.hour1.clicked.connect(self.hour1)
self.ui.hour9.clicked.connect(self.hour9)
self.hide()
def closeEvent(self, event):
self.timer.stop()
QDialog.closeEvent(self, event)
def setText(self, line1, line2):
# Ugly, ugly, ugly... cut and paste from timeout_ui.py.
_translate = QtCore.QCoreApplication.translate
self.ui.label.setText(
_translate(
"Dialog",
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">\n'
'<html><head><meta name="qrichtext" content="1" /><style type="text/css">\n'
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;\">\n"
'<table border="0" style="-qt-table-type: root; margin-top:4px; margin-bottom:4px; margin-left:4px; margin-right:4px;">\n'
"<tr>\n"
'<td style="border: none;">\n'
'<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:20pt; font-weight:600;">'
+ line1
+ "</span></p>\n"
'<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:20pt; font-weight:600;">'
+ line2
+ "</span></p></td></tr></table></body></html>",
)
)
# Called when our initial countdown timer has expired.
# Show the dialog and
def activate(self):
self.timeValue = self.smalltime
self.ui.TimeDisplay.display(self.timeValue.toString("hh:mm:ss"))
self.timer.start(1000)
self.ui.hour9.setVisible(self.show9)
self.show9 = False
self.setWindowTitle(self.gui.sWindowTitle)
self.setText("CAMERA VIEWER", "AUTODISCONNECT IN:")
self.show()
self.move(self.gui.pos())
# Called when we have just connected to a new camera.
def newconn(self):
if self.idle is None:
self.hour1(True)
else:
self.hour9()
pass
# Called when we have just done a reconnect action.
def reconn(self):
self.hour1(False)
def hour1(self, show9=False):
self.timer.stop()
self.hide()
self.show9 = show9
self.gui.setDisco(self.SMALLTIMESECS)
def hour9(self):
self.timer.stop()
self.hide()
self.gui.setDisco(self.BIGTIMESECS)
# Countdown the clock. Emit onTimeoutExpiry if we are done!
def decrement(self):
self.timeValue = self.timeValue.addSecs(-1)
self.ui.TimeDisplay.display(self.timeValue.toString("hh:mm:ss"))
if self.timeValue == self.zerotime:
self.timer.stop()
self.setText("CAMERA DISCONNECTED!", "CLICK TO RECONNECT.")
self.gui.timeoutExpiry.emit()
def force(self, line):
self.gui.stop_disco()
self.timer.stop()
self.setWindowTitle(self.gui.sWindowTitle)
self.setText("CAMERA DISCONNECTED BY", line)
self.ui.TimeDisplay.display(self.zerotime.toString("hh:mm:ss"))
self.ui.hour9.setVisible(self.show9)
self.show()
self.move(self.gui.pos())
self.gui.timeoutExpiry.emit()
class forcedialog(QDialog):
def __init__(self, dir, gui, parent=None):
QWidget.__init__(self, parent)
self.setWindowTitle("Disconnect")
self.dir = dir
self.gui = gui
self.gridLayout = QGridLayout(self)
self.label = QLabel(self)
self.label.setText("Your ID:")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.killID = QLineEdit(self)
self.killID.setText(self.gui.lastforceid)
self.gridLayout.addWidget(self.killID, 0, 1, 1, 2)
self.hostheader = QLabel(self)
self.hostheader.setTextFormat(QtCore.Qt.RichText)
self.hostheader.setText("<b>Host</b>")
self.gridLayout.addWidget(self.hostheader, 1, 0, 1, 1)
self.pidheader = QLabel(self)
self.pidheader.setTextFormat(QtCore.Qt.RichText)
self.pidheader.setText("<b>PID</b>")
self.gridLayout.addWidget(self.pidheader, 1, 1, 1, 1)
self.ttyheader = QLabel(self)
self.ttyheader.setTextFormat(QtCore.Qt.RichText)
self.ttyheader.setText("<b>TTY</b>")
self.gridLayout.addWidget(self.ttyheader, 1, 2, 1, 1)
self.checks = []
dirlist = os.listdir(dir)
dirlist.sort()
i = 2
for file in dirlist:
try:
ll = file.split(":")
if file == self.gui.description:
plt = QPalette()
plt.setColor(QPalette.WindowText, Qt.red)
check = QCheckBox(self)
check.setPalette(plt)
else:
check = QCheckBox(self)
check.setText(ll[0])
check.forcefile = file
self.gridLayout.addWidget(check, i, 0, 1, 1)
# Coloring the labels is easy.
if file == self.gui.description:
pre = '<font color="red">'
post = "</font>"
else:
pre = ""
post = ""
pidlabel = QLabel(self)
pidlabel.setTextFormat(QtCore.Qt.RichText)
pidlabel.setText(pre + ll[1] + post)
self.gridLayout.addWidget(pidlabel, i, 1, 1, 1)
with open(dir + file) as f:
lines = f.readlines()
ttylabel = QLabel(self)
ttylabel.setTextFormat(QtCore.Qt.RichText)
ttylabel.setText(pre + lines[0].strip() + post)
self.gridLayout.addWidget(ttylabel, i, 2, 1, 1)
i = i + 1
self.checks.append(check)
except Exception:
pass
self.buttonBox = QDialogButtonBox(self)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(
QDialogButtonBox.Cancel | QDialogButtonBox.Ok | QDialogButtonBox.YesToAll
)
self.gridLayout.addWidget(self.buttonBox, i, 0, 1, 3)
self.buttonBox.clicked.connect(self.onClick)
self.show()
def onClick(self, button):
stb = self.buttonBox.standardButton(button)
if stb == QDialogButtonBox.Ok or stb == QDialogButtonBox.YesToAll:
all = stb == QDialogButtonBox.YesToAll
id = str(self.killID.text()).strip()
if id == "":
QMessageBox.critical(
None, "Error", "No Identification!", QMessageBox.Ok, QMessageBox.Ok
)
return
self.gui.lastforceid = id
id = id + "\n"
for c in self.checks:
if all or c.isChecked():
try:
f = open(self.dir + c.forcefile, "a")
f.write(id)
f.close()
except Exception:
pass
self.close()
def closeEvent(self, event):
self.gui.haveforce = False
self.deleteLater()
QDialog.closeEvent(self, event)