-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
286 lines (239 loc) · 9.81 KB
/
gui.py
File metadata and controls
286 lines (239 loc) · 9.81 KB
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
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from datasource import get_current_tournament
import recordButton
import infoDisplay
from tournamentDialogs import ManualMatchesDialog
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog
from newTournamentWidget import *
from matchesView import *
import os
from datasource import load_from_file
import camera
vWindow = None
def reload_gui():
vWindow.reload()
class ConfigurationWindow(QMainWindow):
def __init__(self):
super(ConfigurationWindow, self).__init__()
class VideoWindow(QMainWindow):
id = 0
match_recording = None
def createMenu(self):
menubar = self.menuBar()
fileMenu = menubar.addMenu('&File')
newAction = QAction('&New', self)
newAction.setShortcut("Ctrl+N")
newAction.triggered.connect(self.new_tournament)
fileMenu.addAction(newAction)
openAction = QAction('&Open', self)
openAction.setShortcut("Ctrl+O")
openAction.triggered.connect(self.open)
fileMenu.addAction(openAction)
saveAction = QAction('&Save', self)
saveAction.setShortcut("Ctrl+S")
saveAction.triggered.connect(self.save)
fileMenu.addAction(saveAction)
tournamentMenu = menubar.addMenu('&Tournament')
tournamentEditAction = QAction('&Edit Matches', self)
tournamentEditAction.setShortcut("Ctrl+M")
tournamentEditAction.triggered.connect(self.configure)
tournamentMenu.addAction(tournamentEditAction)
tournamentPullAction = QAction('&Update Schedule', self)
tournamentPullAction.setShortcut("Ctrl+U")
tournamentPullAction.triggered.connect(self.updatepull)
tournamentMenu.addAction(tournamentPullAction)
viewMatchesAction = QAction('&View Matches', self)
viewMatchesAction.setShortcut("Ctrl+V")
viewMatchesAction.triggered.connect(self.viewMatches)
tournamentMenu.addAction(viewMatchesAction)
def viewMatches(self):
m = RecordedViewMatchDialog()
if m.exec() is 1:
self.reload()
def reload(self):
self.update()
self.reload_combo()
self.updateStatusDisplay()
self.updateWindowTitle()
def new_tournament(self):
t = NewTournamentWidget()
if t.exec() is 1:
self.reload()
def reload_combo(self):
self.comboBox.clear()
current_tournament = get_current_tournament()
print(current_tournament)
if current_tournament is not None:
for match in current_tournament.matches:
self.comboBox.addItem(match.toInfoString())
self.id = 0
self.match_recording = None
self.comboBox.activated.connect(self.matchSelected)
self.updateStatusDisplay()
def save(self):
if get_current_tournament() is None:
print("Tournament None")
return
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
name,path = QFileDialog.getSaveFileName(self, "Save Tournament", filter="Tournament File (*.Tournament)", options=options)
if (path != ""):
get_current_tournament().save(name)
self.updateStatusDisplay()
def updatepull(self):
if get_current_tournament() is not None:
get_current_tournament().update_match_data()
self.reload()
self.updateStatusDisplay()
def open(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileName, _ = QFileDialog.getOpenFileName(None, "", filter="Tournament File (*.Tournament)", options=options)
if fileName:
print(fileName)
load_from_file(fileName)
self.reload_combo()
self.remember_default(str(fileName))
self.updateStatusDisplay()
def configure(self):
print("loading tournament")
dialog = ManualMatchesDialog();
returnCode=dialog.exec_()
print(returnCode)
self.updateStatusDisplay()
def toggleRecording(self):
if get_current_tournament() is None:
return
if (self.isRecording):
self.stopRecording()
else:
self.startRecording()
# update the window title and status bar
self.updateStatusDisplay()
def startRecording(self):
self.updateStatusDisplay()
if get_current_tournament() is None:
print("Tournament None!")
return
self.match_recording = get_current_tournament().matches[self.comboBox.currentIndex()]
self.isRecording = True
filename = self.match_recording.create_file_name()
self.camera.startRecording("videos/" + filename)
get_current_tournament().matches[self.comboBox.currentIndex()]\
.videos.append(filename)
self.recordButton.updateStyle(self.isRecording)
self.id = self.comboBox.currentIndex()
self.updateStatusDisplay()
def stopRecording(self):
self.updateStatusDisplay()
if get_current_tournament() is None:
print("Tournament None")
return
self.isRecording = False
self.camera.stopRecording()
self.recordButton.updateStyle(self.isRecording)
self.id+=1
get_current_tournament().save()
self.comboBox.setCurrentIndex(self.id)
self.match_recording = None
self.updateStatusDisplay()
def onQuit(self):
print("quit")
self.stopRecording()
self.save()
self.close()
def matchSelected(self):
self.match_number = self.comboBox.currentIndex()
# update the window title and status bar
self.updateStatusDisplay()
def updateStatusDisplay(self):
teams = ['','','','']
if get_current_tournament() is not None and get_current_tournament().matches is not None:
r1 = get_current_tournament().matches[self.comboBox.currentIndex()].red1
r2 = get_current_tournament().matches[self.comboBox.currentIndex()].red2
b1 = get_current_tournament().matches[self.comboBox.currentIndex()].blue1
b2 = get_current_tournament().matches[self.comboBox.currentIndex()].blue2
teams = [r1, r2, b1, b2]
print(teams)
self.updateWindowTitle(match_number=get_current_tournament().
matches[self.comboBox.currentIndex()].toId(), teams=teams)
self.infoDisplay.updateInfo(get_current_tournament().matches[self.comboBox.currentIndex()].toId(), teams, self.isRecording)
def updateWindowTitle(self, match_number=None, teams=None):
if get_current_tournament() is None:
self.setWindowTitle('VEX Match Recorder - [No Tournament Selected]')
return
if (match_number == None or teams == None):
# initialization
self.setWindowTitle('VEX Match Recorder - [No Match Selected]')
else:
if (self.isRecording):
title = 'VEX Match Recorder - Match ' + (match_number) + " Teams "
else:
title = 'VEX Match Recorder - Match ' + (match_number) + " Teams "
# add the teams to the title
for team in teams:
title += str(team) + " "
self.setWindowTitle(title)
def closeEvent(self, QCloseEvent):
self.onQuit()
def __init__(self, camera, parent=None):
super(VideoWindow, self).__init__(parent)
global vWindow
vWindow = self
self.createMenu()
self.camera = camera
# quit on alt+f4 or ctrl+w
self.shortcut = QShortcut(QKeySequence.Close, self)
self.shortcut.activated.connect(self.onQuit)
# by default, camera recording is off
self.isRecording = False
self.match_number = None
# Create a widget for window contents
centralWidget = QWidget(self)
self.setCentralWidget(centralWidget)
# create the top information display row
self.infoDisplay = infoDisplay.InfoDisplay()
# create the bottom control layout with buttons
self.recordButton = recordButton.RecordButton()
self.recordButton.clicked.connect(self.toggleRecording)
self.comboBox = QComboBox()
current_tournament = get_current_tournament()
if current_tournament is not None:
for match in current_tournament.matches:
self.comboBox.addItem(match.toInfoString())
self.comboBox.activated.connect(self.matchSelected)
controlLayout = QHBoxLayout()
controlLayout.setContentsMargins(0, 0, 0, 0)
controlLayout.addWidget(self.comboBox)
controlLayout.addWidget(self.recordButton)
# create the mainlayout that contains the viewfiner and controls
mainLayout = QVBoxLayout()
mainLayout.addLayout(self.infoDisplay)
mainLayout.addWidget(self.camera.getViewFinder())
mainLayout.addLayout(controlLayout)
# apply the mainlayout
centralWidget.setLayout(mainLayout)
self.updateWindowTitle()
#load default tournament file
self.load_default()
# self.recordButton.updateStyle(False)
self.updateStatusDisplay()
# loads the default touranment file
def load_default(self):
try:
file = open("defaults.cfg", "r")
except:
return # file not fuond
fileName = file.read()
if fileName:
print("loading default: " + fileName)
try:
load_from_file(fileName)
self.reload_combo()
except:
print("Failed to load default tournament file!")
self.updateStatusDisplay()
def remember_default(self, filename):
file = open("defaults.cfg", "w")
file.write(filename)