-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoSelect4237.py
142 lines (113 loc) · 5.09 KB
/
AutoSelect4237.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
from PySide2 import QtGui, QtCore, QtWidgets
import sys, json
from lib.network import RoboRIOTransmitter
from lib.widgets import AboutWindow
from lib.frames import GameFrame2019, GameFrame2018, GameFrame2017, GameFrame2016
VERSION = 4.0
class GUI(QtWidgets.QMainWindow):
iconSize = 75
def __init__(self):
super(GUI, self).__init__()
self.initUI()
"""
Method to create the frames, tabs, and
"""
def initUI(self):
self.teamNumber = self.getTeamNumber()
print("Team number set to " + str(self.teamNumber))
self.roboRIOIP = "roborio-" + str(self.teamNumber) + "-frc.local"
self.transmitter = RoboRIOTransmitter.RoboRIOTransmitter(self.roboRIOIP)
#About window
self.about = AboutWindow.AboutWindow()
'''
General
'''
self.DRMLabel = QtWidgets.QLabel("<font size=8>This program was made by Team 4237.<font>")
self.DRMLabel.setStyleSheet("QLabel { color : red;}")
self.teamNotFoundLabel = QtWidgets.QLabel("An FRC team number could not be found on this computer, make sure the FRC Driver Station is installed")
self.teamNotFoundLabel.setStyleSheet("QLabel { color : red; }")
#Actions
self.exitAction = QtWidgets.QAction('&Exit', self)
self.exitAction.triggered.connect(self.close)
self.sendToRobotAction = QtWidgets.QAction('&Send To Robot', self)
self.sendToRobotAction.triggered.connect(self.sendToRobot)
self.openAboutAction = QtWidgets.QAction('&About', self)
self.openAboutAction.triggered.connect(self.about.show)
#Icons
self.strongholdIcon = QtGui.QIcon("img/2016/logos/Stronghold.png")
self.steamworksIcon = QtGui.QIcon("img/2017/logos/Steamworks.png")
self.powerupIcon = QtGui.QIcon("img/2018/logos/Powerup.png")
self.deepspaceIcon = QtGui.QIcon("img/2019/logos/DestinationDeepSpace.png")
self.windowIcon = QtGui.QIcon("img/general/icons/LanceABotIcon.png")
#Tabs and Frames
self.frame2016 = GameFrame2016.GameFrame2016()
self.frame2017 = GameFrame2017.GameFrame2017()
self.frame2018 = GameFrame2018.GameFrame2018()
self.frame2019 = GameFrame2019.GameFrame2019()
#Layout
self.tabs = QtWidgets.QTabWidget()
self.tabs.addTab(self.frame2019, self.deepspaceIcon, "")
self.tabs.addTab(self.frame2018, self.powerupIcon, "")
self.tabs.addTab(self.frame2017, self.steamworksIcon, "")
self.tabs.addTab(self.frame2016, self.strongholdIcon, "")
self.tabs.setIconSize(QtCore.QSize(100, 50))
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.tabs)
if self.teamNumber == None:
print("Error verifying team number")
self.layout.addWidget(self.teamNotFoundLabel)
self.mainFrame = QtWidgets.QFrame()
self.mainFrame.setLayout(self.layout)
menuBar = self.menuBar()
fileMenu = menuBar.addMenu('&File')
fileMenu.addAction(self.exitAction)
robotMenu = menuBar.addMenu('&Robot')
robotMenu.addAction(self.sendToRobotAction)
helpMenu = menuBar.addMenu('&Help')
helpMenu.addAction(self.openAboutAction)
self.setCentralWidget(self.mainFrame)
self.setWindowTitle('AutoSelect 4237 - Version ' + str(VERSION))
self.setWindowIcon(self.windowIcon)
self.show()
def closeEvent(self, event):
self.about.close()
print("Close Event received")
"""
Base method for sending selected autonomous
"""
def sendToRobot(self):
if self.tabs.currentIndex() == 0:
self.sendToRobot2018()
elif self.tabs.currentIndex() == 1:
self.sendToRobot2017()
elif self.tabs.currentIndex() == 2:
self.sendToRobot2016()
def sendToRobot2016(self):
pass
def sendToRobot2017(self):
pass
def sendToRobot2018(self):
print(self.frame2018.getJsonData())
self.transmitter.sendMessage(json.dumps(self.frame2018.getJsonData()))
'''
Method to get the current team number from the FRC Driver Station
'''
def getTeamNumber(self):
print("Searching for team number")
try:
with open("C:\\Users\\Public\\Documents\\FRC\\FRC DS Data Storage.ini", 'r') as DSFile:
lines = DSFile.readlines()
for x in range(0, len(lines)):
if "TeamNumber" in lines[x]:
split = lines[x].split("= \"")
split[1] = split[1].replace("\"", "")
teamNumber = (int)(split[1])
return teamNumber
except:
print("Team number could not be found")
def main():
app = QtWidgets.QApplication(sys.argv)
window = GUI()
sys.exit(app.exec_())
if __name__ == '__main__':
main()