-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdialogs.py
177 lines (148 loc) · 5.43 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
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 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)