/
main.py
202 lines (142 loc) · 5.38 KB
/
main.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
'''
Thank you for using RoboGUI
Designed for BSM Robots
Created By Andrew Voss
How to run: python main.py
Arguments: use argument "windowed" to launch in windowed mode
Ex. python main.py windowed
Compatibility: Unix Systems (mac & linux) & windows
Not tested on windows
Notes:
- Tasks https://goo.gl/57n8XC & https://github.com/avoss19/RoboGUI
'''
import sys, os, time
import camera
import ip
from PyQt4.QtCore import SIGNAL, QThread, pyqtSlot, QSize, QTimer, QUrl
from PyQt4.QtGui import *
class Form(QWidget):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.initScreenSize() # If window mode set to fullscreen window
self.pyQtResolution() # Get window resolution
# Program icon
app_icon = QIcon()
app_icon.addFile('bsm.png')
app.setWindowIcon(app_icon)
# window title
self.setWindowTitle("RoboGUI")
# Display widgets
self.videoStream()
self.printIP()
self.controllerButton()
self.quitButton()
self.debugButton() # For testing purposes
#self.updateDisplayB()
def initScreenSize(self):
# For fullscreen app
screen_resolution = app.desktop().screenGeometry()
self.x, self.y = screen_resolution.width(), screen_resolution.height()
def debug(self):
# For printing info to console
#print sys.argv
print "PyQt4 Resolution: ", self.x, " x ", self.y
print self.size()
rec = self.geometry();
height = rec.height();
width = rec.width();
print width, height
def debugButton(self):
self.debugB = QPushButton("Debug", self)
self.debugB.move(0,self.y-30)
self.connect(self.debugB, SIGNAL("clicked()"),self.debug)
def pyQtResolution(self):
# Get resolution of window
rec = self.geometry()
self.x = rec.width()
self.y = rec.height()
def center(self):
# Center window on display
frameGm = self.frameGeometry()
screen = QApplication.desktop().screenNumber(QApplication.desktop().cursor().pos())
centerPoint = QApplication.desktop().screenGeometry(screen).center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())
def updateDisplay(self):
self.pyQtResolution()
self.debugB.move(0,self.y-30)
self.ip.move(self.x - 200,5)
self.ip.resize(195, self.y - 10)
self.update()
def updateDisplayB(self):
self.displayB = QPushButton("Update Display", self)
self.displayB.move(0,400)
self.connect(self.displayB, SIGNAL("clicked()"),self.updateDisplay)
def videoStream(self):
# Video Feed
self.layout = QGridLayout(self)
view = camera.camera(ip.camera1)
# set size of camera stream
view.setMaximumHeight(500)
view.setMaximumWidth(500)
# Add widget to display
self.layout.addWidget(view)
def printIP(self):
# Print connected ip addresses to screen
ipAddresses = "<b>Connected IP Addresses:</b>"
nextLine = "<br />"
numIP = 0
# get ip address from ip.py
for i in ip.ips:
if i[:1] != "_":
exec("ipAddresses = ipAddresses + nextLine + i + ' = ' + ip." + str(i))
numIP = numIP + 1
# change color of ip address text
ipAddresses = "<font color ='green'>" + ipAddresses + "</font>"
# Create text on screen to display ip addresses
self.ip = QTextEdit(self)
self.ip.insertHtml(ipAddresses)
self.ip.setReadOnly(True)
# position of ip address text & resize
self.ip.move(self.x - 200, 5)
def controllerStart(self):
# not best method to start python program, but threading doesn't play well with pyqt4
os.system("python Controller.py &")
def controllerButton(self):
self.controller = QPushButton("Run Controller-Support", self)
self.controller.move(0,5)
self.connect(self.controller, SIGNAL("clicked()"),self.controllerStart)
self.controller.resize(180,30)
def quit(self):
# quits all running python programs (not best method to kill program), but will kill controller-support
# Only tested on mac osx; but should technically work
from sys import platform
if platform == "linux" or platform == "linux2":
os.system("killall -9 python")
os.system("killall -9 Python")
# tested on two different macs and for some reason one python task is capitalized while the other isn't
# not sure if it is an isolated situation
elif platform == "darwin":
os.system("killall -9 python")
os.system("killall -9 Python")
elif platform == "win32":
os.system("taskkill /F /IM python.exe /T")
def quitButton(self):
self.q = QPushButton("Quit", self)
self.q.setStyleSheet('QPushButton {color: red;}')
self.q.move(0,30)
self.connect(self.q, SIGNAL("clicked()"),self.quit)
def windowMode():
try:
if sys.argv[1] == "windowed":
form.show()
else:
form.showFullScreen()
except:
form.showFullScreen()
if __name__ == '__main__':
app = QApplication(sys.argv)
form = Form()
windowMode()
form.updateDisplay() # Fix miss placed widgets
sys.exit(app.exec_())