-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote.py
165 lines (123 loc) · 4.63 KB
/
remote.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
#!encoding:utf-8
import sys
from PyQt4 import QtCore, QtGui,QtNetwork
normal_style = """
QLabel {
color: white;
background-color: black;
font-size: 70pt;
font-family: "DejaVu Sans Mono";
font-weight: bold;
}"""
info_style = """
QLabel {
color: white;
background-color: black;
font-size: 30pt;
font-family: "DejaVu Sans Mono";
font-weight: bold;
}"""
overtime_style = """
QLabel {
color: black;
background-color: red;
font-size: 70pt;
font-family: "DejaVu Sans Mono";
font-weight: bold;
}"""
class ConnectBox(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.lineEdit = QtGui.QLineEdit()
self.lineEdit.setText('127.0.0.1')
connectButton = QtGui.QPushButton('Kople til')
connectButton.setDefault(True)
cancelButton = QtGui.QPushButton('Avbryt')
buttonBox = QtGui.QDialogButtonBox(QtCore.Qt.Horizontal)
buttonBox.addButton(connectButton, QtGui.QDialogButtonBox.AcceptRole)
buttonBox.addButton(cancelButton, QtGui.QDialogButtonBox.RejectRole)
buttonBox.accepted.connect(self.accept)
buttonBox.rejected.connect(self.reject)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.lineEdit)
layout.addWidget(buttonBox)
self.setLayout(layout)
def connect_to(self):
return self.lineEdit.text()
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum)
cb = ConnectBox()
if cb.exec_():
self.ip = cb.connect_to()
self.socket = QtNetwork.QTcpSocket(self)
self.socket.readyRead.connect(self.read)
self.socket.error.connect(self.socketError)
layout = QtGui.QGridLayout()
self.countdownLabel = QtGui.QLabel()
self.countdownLabel.setStyleSheet(info_style)
self.countdownLabel.setText('Not Connected')
self.countdownLabel.setAlignment(QtCore.Qt.AlignCenter)
layout.addWidget(self.countdownLabel,0,0,1,2)
self.standbyText = QtGui.QLineEdit()
self.standbyText.returnPressed.connect(self.standby)
self.countdownTime = QtGui.QLineEdit()
self.countdownTime.returnPressed.connect(self.start)
layout.addWidget(self.standbyText,1,0,1,1)
layout.addWidget(self.countdownTime,2,0,1,1)
self.standbyButton = QtGui.QPushButton('Standby')
self.standbyButton.clicked.connect(self.standby)
self.startButton = QtGui.QPushButton('Start')
self.startButton.clicked.connect(self.start)
layout.addWidget(self.standbyButton,1,1)
layout.addWidget(self.startButton,2,1)
self.widget = QtGui.QWidget()
self.widget.setLayout(layout)
self.setCentralWidget(self.widget)
self.connect()
self.reconnect = 0
def sizeHint(self):
return QtCore.QSize(400,400)
def minimumSizeHint(self):
return QtCore.QSize(400,400)
def read(self):
self.reconnect = 0
text = str(self.socket.readLine()).strip()
cmd = text.split()
if cmd[0] == 'COUNTDOWN':
self.countdownLabel.setStyleSheet(normal_style)
self.countdownLabel.setText(cmd[1])
elif cmd[0] == 'OVERTIME':
self.countdownLabel.setStyleSheet(overtime_style)
self.countdownLabel.setText(cmd[1])
elif cmd[0] == 'STANDINGBY':
self.countdownLabel.setStyleSheet(info_style)
fjs = text.replace(cmd[0],"").strip()
self.countdownLabel.setText(fjs)
self.standbyText.setText(fjs)
if self.socket.bytesAvailable(): self.read()
@QtCore.pyqtSlot()
def connect(self):
self.socket.connectToHost(self.ip, 8675) #VK
def socketError(self, e):
if self.reconnect > 10:
qmb = QtGui.QMessageBox.information(self, 'FEIL', u'Nettverksfeil. Kople til på nytt?',
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
if qmb == QtGui.QMessageBox.Yes:
self.reconnect = 0
self.socketError(e)
else:
self.close()
else:
self.reconnect += 1
QtCore.QTimer.singleShot(1000, self, QtCore.SLOT('connect()'))
def standby(self):
self.socket.write('STANDBY %s\n'%self.standbyText.text())
def start(self):
self.socket.write('START %s\n'%self.countdownTime.text())
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())