Commit 0a8784e2 authored by Tom Pillot's avatar Tom Pillot
Browse files

Improved scoreboard design

parent d5e9d9e4
......@@ -43,8 +43,6 @@ class Detector(apriltag.Detector):
greys = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
dets = super().detect(greys)
for det in dets:
print(dir(det))
print(type(det))
if det.decision_margin >= self.DECISION_MARGIN:
rect = det.corners.astype(int).reshape((-1, 1, 2))
cv2.polylines(img, [rect], True, (0, 0, 255), 2)
......
......@@ -37,6 +37,8 @@ class ScoreWindow(ScoreWindowUi):
self.time_is_red = True
else:
self.update_gui()
# Sort the table
self.sort_by_points()
def update_gui(self):
self.time_edit.setTime(self.time_edit.time().addSecs(-1))
......@@ -49,10 +51,18 @@ class ScoreWindow(ScoreWindowUi):
i += 1
def set_table_item(self, row, team):
self.table_widget.setItem(row, self.RANK, qtw.QTableWidgetItem(str(team.rank)))
self.table_widget.item(row, self.RANK).setBackground(qtg.QColor(team.color))
self.table_widget.setItem(row, self.NAME, qtw.QTableWidgetItem(team.name))
self.table_widget.setItem(row, self.POINTS, qtw.QTableWidgetItem(str(team.points)))
rank_item = qtw.QTableWidgetItem("#" + str(team.rank))
rank_item.setBackground(qtg.QColor(team.color))
rank_item.setTextAlignment(qtc.Qt.AlignCenter)
self.table_widget.setItem(row, self.RANK, rank_item)
self.table_widget.setItem(row, self.NAME, qtw.QTableWidgetItem(" " + team.name))
points_item = qtw.QTableWidgetItem()
points_item.setData(qtc.Qt.EditRole, team.points)
points_item.setTextAlignment(qtc.Qt.AlignCenter)
self.table_widget.setItem(row, self.POINTS, points_item)
self.table_widget.resizeRowsToContents()
self.table_widget.resizeColumnsToContents()
......@@ -70,3 +80,10 @@ class ScoreWindow(ScoreWindowUi):
else:
print("Failed to grab frame.")
self.webcam_timer.start(self.WEBCAM_REFRESH_TIME)
def sort_by_points(self):
self.table_widget.sortByColumn(self.POINTS, qtc.Qt.DescendingOrder)
# Update ranks
for row in range(self.table_widget.rowCount()):
item = self.table_widget.item(row, self.RANK)
item.setText("#" + str(row + 1))
......@@ -17,8 +17,8 @@ class ScoreWindowUi(qtw.QMainWindow):
self.time_edit.setFont(qtg.QFont("Arial", 100, qtg.QFont.Bold))
self.time_edit.setDisplayFormat("mm:ss")
self.time_edit.setAlignment(qtc.Qt.AlignCenter)
self.time_edit.setReadOnly(True)
self.time_edit.setFixedHeight(200)
self.time_edit.setDisabled(True)
with open("game/time_edit.qss", "r") as f:
self.time_edit.setStyleSheet(f.read())
......@@ -35,6 +35,8 @@ class ScoreWindowUi(qtw.QMainWindow):
self.table_widget.setFont(qtg.QFont("Arial", 40, qtg.QFont.Bold))
self.table_widget.setEditTriggers(qtw.QAbstractItemView.NoEditTriggers)
self.table_widget.verticalHeader().setVisible(False)
self.table_widget.setFocusPolicy(qtc.Qt.NoFocus)
self.table_widget.setSelectionMode(qtw.QAbstractItemView.NoSelection)
# self.table_widget.setShowGrid(False)
with open("game/table_widget.qss", "r") as f:
......
QHeaderView::section {
background-color: #646464;
color: rgba(255, 255, 255, 222);
background-color: rgb(63, 81, 181);
padding: 4px;
font-size: 14pt;
border-style: none;
......@@ -16,6 +17,7 @@ QHeaderView::section:vertical {
}
QTableWidget {
color: #FFFFFF;
color: rgba(0, 0, 0, 222);
background-color: rgb(245, 245, 246);
border-radius: 10px;
}
\ No newline at end of file
class Team:
def __init__(self, name, tag_id, color):
def __init__(self, name, tag_id, color, points):
self.name = name
self.tag_id = tag_id
self.color = color
self.points = 0
self.points = points
self.rank = 0
self.can_win_points = True
def add_points(self, points_added):
if self.can_win_points:
self.points += points_added
self.can_win_points = False
......@@ -19,6 +19,8 @@ class TeamWindow(TeamWindowUi):
def __init__(self):
super().__init__()
self.random_gen = qtc.QRandomGenerator() # For testing
self.detector = Detector()
self.teams = {} # The keys are the tag ids and the values are the teams
......@@ -59,7 +61,7 @@ class TeamWindow(TeamWindowUi):
self.tag_label.setText("")
self.tag_label.setStyleSheet("")
self.name_input.setText("")
self.teams[tag_id] = Team(name, tag_id, self.team_colors[tag_id])
self.teams[tag_id] = Team(name, tag_id, self.team_colors[tag_id], int(self.random_gen.generate()/10000000))
def edit_team(self):
"""
......
QTimeEdit {
color: white;
selection-color: white;
selection-background-color: black;
background-color: qlineargradient( x1:0 y1:0, x2:1 y2:0, stop:0 cyan, stop:1 blue);
border-style: solid;
border-width: 4px;
border-color: rgb(100,100,100);
color: #EEF4FF;
background-color: qlineargradient( x1:0 y1:0, x2:1 y2:0, stop:0 #028BC3, stop:1 #7B4FB7);
border-radius: 10px;
}
QTimeEdit::up-button {width: 0}
......
......@@ -30,7 +30,7 @@ if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
w = MainWindow()
# Ajout automatique d'équipe pour tester l'application
# Add teams to test the application
if len(sys.argv) > 1 and sys.argv[1] == "test":
for tag_id in w.team_window.team_colors.keys():
tag_str = str(tag_id)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment