Commit 43f0078a authored by Tom Pillot's avatar Tom Pillot
Browse files

Add start stop button on the scoreboard

parent 0fcfa328
...@@ -15,18 +15,19 @@ class ScoreWindow(ScoreWindowUi): ...@@ -15,18 +15,19 @@ class ScoreWindow(ScoreWindowUi):
self.teams = teams self.teams = teams
self.initial_time = 0 self.initial_time = 0
self.time_is_red = False self.time_is_red = False
self.is_started = False
self.detector = Detector() self.detector = Detector()
self.start_stop_button.clicked.connect(self.start_stop_activity)
def start_scoreboard(self, time): def start_scoreboard(self, time):
# Start and display the clock # Start and display the clock
self.time_edit.setTime(time) self.time_edit.setTime(time)
self.initial_time = - time.secsTo(qtc.QTime(0, 0, 0, 0)) # Time set initially in seconds self.initial_time = - time.secsTo(qtc.QTime(0, 0, 0, 0)) # Time set initially in seconds
self.timer.timeout.connect(self.timer_timeout) self.timer.timeout.connect(self.timer_timeout)
self.timer.start(1000)
self.update_gui()
# Show the webcam # Show the webcam
self.webcam_timer.timeout.connect(self.refresh_webcam) self.webcam_timer.timeout.connect(self.refresh_webcam)
self.webcam_timer.start(self.WEBCAM_REFRESH_TIME) self.refresh_webcam(detect_tags=False)
def timer_timeout(self): def timer_timeout(self):
self.timer.start(1000) self.timer.start(1000)
...@@ -74,7 +75,7 @@ class ScoreWindow(ScoreWindowUi): ...@@ -74,7 +75,7 @@ class ScoreWindow(ScoreWindowUi):
# Keep the points item so the points can be modified later easily # Keep the points item so the points can be modified later easily
team.points_item = points_item team.points_item = points_item
def refresh_webcam(self): def refresh_webcam(self, detect_tags=True):
# Read an image from the webcam and detect the tags it contains # Read an image from the webcam and detect the tags it contains
ret, frame = self.detector.cam.read() ret, frame = self.detector.cam.read()
dets = self.detector.show_tags_on_image(frame) dets = self.detector.show_tags_on_image(frame)
...@@ -90,9 +91,10 @@ class ScoreWindow(ScoreWindowUi): ...@@ -90,9 +91,10 @@ class ScoreWindow(ScoreWindowUi):
print("Failed to grab frame.") print("Failed to grab frame.")
# Update scores # Update scores
for det in dets: if detect_tags: # Prevent teams from winning points when the game has not started
if det.decision_margin > self.detector.DECISION_MARGIN: for det in dets:
self.add_points(det.tag_id) if det.decision_margin > self.detector.DECISION_MARGIN:
self.add_points(det.tag_id)
self.webcam_timer.start(self.WEBCAM_REFRESH_TIME) self.webcam_timer.start(self.WEBCAM_REFRESH_TIME)
...@@ -126,3 +128,18 @@ class ScoreWindow(ScoreWindowUi): ...@@ -126,3 +128,18 @@ class ScoreWindow(ScoreWindowUi):
def show_event(self, team, points_added): def show_event(self, team, points_added):
message = team.name + " a gagné " + str(points_added) + " points." message = team.name + " a gagné " + str(points_added) + " points."
self.list_widget.insertItem(0, message) self.list_widget.insertItem(0, message)
def start_stop_activity(self):
"""
Start or stop the activity depending on the last button state
"""
if self.is_started:
self.timer.stop()
self.webcam_timer.stop()
self.start_stop_button.setIcon(qtg.QIcon('game/icons/start.png'))
self.is_started = False
else:
self.timer.start(1000)
self.webcam_timer.start(self.WEBCAM_REFRESH_TIME)
self.start_stop_button.setIcon(qtg.QIcon('game/icons/stop.png'))
self.is_started = True
...@@ -18,6 +18,10 @@ class ScoreWindowUi(qtw.QMainWindow): ...@@ -18,6 +18,10 @@ class ScoreWindowUi(qtw.QMainWindow):
palette.setColor(qtg.QPalette.Background, qtg.QColor("#E0E1E0")) palette.setColor(qtg.QPalette.Background, qtg.QColor("#E0E1E0"))
self.setPalette(palette) self.setPalette(palette)
self.start_stop_button = qtw.QPushButton()
self.start_stop_button.setIcon(qtg.QIcon('game/icons/start.png'))
self.start_stop_button.setIconSize(qtc.QSize(50, 50))
self.time_edit = qtw.QTimeEdit() self.time_edit = qtw.QTimeEdit()
self.time_edit.setDisplayFormat("mm:ss") self.time_edit.setDisplayFormat("mm:ss")
self.time_edit.setAlignment(qtc.Qt.AlignCenter) self.time_edit.setAlignment(qtc.Qt.AlignCenter)
...@@ -27,16 +31,18 @@ class ScoreWindowUi(qtw.QMainWindow): ...@@ -27,16 +31,18 @@ class ScoreWindowUi(qtw.QMainWindow):
# The time edit needs to be inside a widget so that we can set the style of the widget and # The time edit needs to be inside a widget so that we can set the style of the widget and
# later when the font color of the time edit is changed, the widget style remains the same # later when the font color of the time edit is changed, the widget style remains the same
self.time_widget = qtw.QWidget() self.time_widget = qtw.QWidget()
self.time_widget.setLayout(qtw.QVBoxLayout()) hlayout1 = qtw.QHBoxLayout()
self.time_widget.layout().addWidget(self.time_edit) hlayout1.addWidget(self.time_edit)
hlayout1.addWidget(self.start_stop_button)
self.time_widget.setLayout(hlayout1)
with open("game/time_widget.qss", "r") as f: with open("game/qss/time_widget.qss", "r") as f:
self.time_widget.setStyleSheet(f.read()) self.time_widget.setStyleSheet(f.read())
self.list_widget = qtw.QListWidget() self.list_widget = qtw.QListWidget()
self.list_widget.setDisabled(True) self.list_widget.setDisabled(True)
with open("game/list_widget.qss", "r") as f: with open("game/qss/list_widget.qss", "r") as f:
self.list_widget.setStyleSheet(f.read()) self.list_widget.setStyleSheet(f.read())
self.webcam_label = qtw.QLabel() self.webcam_label = qtw.QLabel()
...@@ -57,7 +63,7 @@ class ScoreWindowUi(qtw.QMainWindow): ...@@ -57,7 +63,7 @@ class ScoreWindowUi(qtw.QMainWindow):
self.table_widget.setFocusPolicy(qtc.Qt.NoFocus) self.table_widget.setFocusPolicy(qtc.Qt.NoFocus)
self.table_widget.setSelectionMode(qtw.QAbstractItemView.NoSelection) self.table_widget.setSelectionMode(qtw.QAbstractItemView.NoSelection)
with open("game/table_widget.qss", "r") as f: with open("game/qss/table_widget.qss", "r") as f:
self.setStyleSheet(f.read()) self.setStyleSheet(f.read())
self.timer = qtc.QTimer(self) self.timer = qtc.QTimer(self)
...@@ -66,13 +72,13 @@ class ScoreWindowUi(qtw.QMainWindow): ...@@ -66,13 +72,13 @@ class ScoreWindowUi(qtw.QMainWindow):
vlayout1.addWidget(self.list_widget) vlayout1.addWidget(self.list_widget)
vlayout1.addWidget(self.webcam_label) vlayout1.addWidget(self.webcam_label)
hlayout = qtw.QHBoxLayout() hlayout2 = qtw.QHBoxLayout()
hlayout.addWidget(self.table_widget, stretch=True) hlayout2.addWidget(self.table_widget, stretch=True)
hlayout.addLayout(vlayout1) hlayout2.addLayout(vlayout1)
vlayout2 = qtw.QVBoxLayout() vlayout2 = qtw.QVBoxLayout()
vlayout2.addWidget(self.time_widget, alignment=qtc.Qt.AlignCenter) vlayout2.addWidget(self.time_widget, alignment=qtc.Qt.AlignCenter)
vlayout2.addLayout(hlayout) vlayout2.addLayout(hlayout2)
widget.setLayout(vlayout2) widget.setLayout(vlayout2)
def resizeEvent(self, a0): def resizeEvent(self, a0):
......
...@@ -22,10 +22,13 @@ class TeamWindow(TeamWindowUi): ...@@ -22,10 +22,13 @@ class TeamWindow(TeamWindowUi):
self.detector = Detector() self.detector = Detector()
self.teams = {} # The keys are the tag ids and the values are the teams self.teams = {} # The keys are the tag ids and the values are the teams
self.add_activities()
self.scan_button.clicked.connect(self.detect_tag) self.scan_button.clicked.connect(self.detect_tag)
self.add_button.clicked.connect(self.add_team) self.add_button.clicked.connect(self.add_team)
self.edit_button.clicked.connect(self.edit_team) self.edit_button.clicked.connect(self.edit_team)
self.delete_button.clicked.connect(self.delete_team) self.delete_button.clicked.connect(self.delete_team)
self.activity_box.currentIndexChanged.connect(self.show_activity_description)
def set_label_color(self, tag_id): def set_label_color(self, tag_id):
try: try:
...@@ -120,3 +123,17 @@ class TeamWindow(TeamWindowUi): ...@@ -120,3 +123,17 @@ class TeamWindow(TeamWindowUi):
self.status_bar.showMessage("Veuillez choisir le temps de l'activité.", self.STATUS_TIME) self.status_bar.showMessage("Veuillez choisir le temps de l'activité.", self.STATUS_TIME)
return False return False
return True return True
def add_activities(self):
"""
Add activities with their descriptions
"""
name = "Course Thymio"
description = "Les équipes doivent programmer leur Thymio pour qu'il arrive le plus vite possible à la fin du" \
" parcourt. Une webcam qui filme l'arrivée permet de détecter automatiquement les équipes qui " \
"réussissent à finir la course dans les temps. "
self.activity_box.addItem(name, description)
self.show_activity_description()
def show_activity_description(self):
self.activity_description.setText(self.activity_box.currentData())
...@@ -20,7 +20,12 @@ class TeamWindowUi(qtw.QMainWindow): ...@@ -20,7 +20,12 @@ class TeamWindowUi(qtw.QMainWindow):
self.setStatusBar(self.status_bar) self.setStatusBar(self.status_bar)
self.table_view = qtw.QTableView() self.table_view = qtw.QTableView()
# Prevent user from selecting and modifying the cells
self.table_view.setEditTriggers(qtw.QAbstractItemView.NoEditTriggers) self.table_view.setEditTriggers(qtw.QAbstractItemView.NoEditTriggers)
self.table_view.setFocusPolicy(qtc.Qt.NoFocus)
self.table_view.setSelectionMode(qtw.QAbstractItemView.NoSelection)
self.table_view.horizontalHeader().setSectionResizeMode(qtw.QHeaderView.Stretch) self.table_view.horizontalHeader().setSectionResizeMode(qtw.QHeaderView.Stretch)
self.table_view.verticalHeader().setVisible(False) self.table_view.verticalHeader().setVisible(False)
...@@ -38,7 +43,11 @@ class TeamWindowUi(qtw.QMainWindow): ...@@ -38,7 +43,11 @@ class TeamWindowUi(qtw.QMainWindow):
self.edit_button = qtw.QPushButton("Modifier") self.edit_button = qtw.QPushButton("Modifier")
self.delete_button = qtw.QPushButton("Supprimer") self.delete_button = qtw.QPushButton("Supprimer")
self.scan_button = qtw.QPushButton("Scanner le tag") self.scan_button = qtw.QPushButton("Scanner le tag")
self.activity_box = qtw.QComboBox() self.activity_box = qtw.QComboBox()
self.activity_description = qtw.QLabel()
self.activity_description.setWordWrap(True)
self.activity_description.setFixedWidth(300)
self.start_button = qtw.QPushButton("Démarrer l'activité") self.start_button = qtw.QPushButton("Démarrer l'activité")
self.tag_label = qtw.QLabel("") self.tag_label = qtw.QLabel("")
...@@ -75,12 +84,13 @@ class TeamWindowUi(qtw.QMainWindow): ...@@ -75,12 +84,13 @@ class TeamWindowUi(qtw.QMainWindow):
vlayout2 = qtw.QVBoxLayout() vlayout2 = qtw.QVBoxLayout()
vlayout2.addWidget(qtw.QLabel("Choix de l'activité :")) vlayout2.addWidget(qtw.QLabel("Choix de l'activité :"))
vlayout2.addWidget(self.activity_box) vlayout2.addWidget(self.activity_box)
vlayout2.addWidget(self.activity_description)
vlayout2.addItem(vertical_spacer) vlayout2.addItem(vertical_spacer)
vlayout2.addWidget(qtw.QLabel("Choix du temps :")) vlayout2.addWidget(qtw.QLabel("Choix du temps :"))
vlayout2.addWidget(self.time_edit) vlayout2.addWidget(self.time_edit)
vlayout2.addItem(vertical_spacer) vlayout2.addItem(vertical_spacer)
vlayout2.addWidget(self.start_button) vlayout2.addWidget(self.start_button)
vlayout2.addStretch() # vlayout2.addStretch()
hlayout5 = qtw.QHBoxLayout() hlayout5 = qtw.QHBoxLayout()
hlayout5.addLayout(vlayout1) hlayout5.addLayout(vlayout1)
......
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