From 113a0b6c4a43f3d9c4cb28964d1ecb72611bd48d Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Sat, 23 Nov 2013 17:51:52 +0100 Subject: [PATCH] Added victory window --- game.py | 10 +++++++++- windows.py | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/game.py b/game.py index 37fdc34..5e3a269 100644 --- a/game.py +++ b/game.py @@ -3,7 +3,7 @@ from __future__ import print_function from PySide import QtCore, QtGui from player import Player -from windows import QuestionWindow, EditAnswersWindow, PlayerStartWindow +from windows import QuestionWindow, EditAnswersWindow, PlayerStartWindow, VictoryWindow from gamestate import QuestionAnswers class SeopardyGame(QtGui.QWidget): @@ -93,6 +93,8 @@ class SeopardyGame(QtGui.QWidget): self._inOtherWindow = True x.exec_() self._inOtherWindow = False + elif e.key() == QtCore.Qt.Key_V: + self.show_victory_window() elif e.key() == QtCore.Qt.Key_E: if self._inOtherWindow: return @@ -134,6 +136,12 @@ class SeopardyGame(QtGui.QWidget): self.gamestate.set_answers(section, number, newAnswers) self._restyle_button(section, number, newAnswers) + def show_victory_window(self): + self._inOtherWindow = True + victoryWindow = VictoryWindow(self.players, self) + victoryWindow.exec_() + self._inOtherWindow = False + def go_to_question(self, section, number): if self._inOtherWindow: return diff --git a/windows.py b/windows.py index 99e52a7..02501ac 100644 --- a/windows.py +++ b/windows.py @@ -338,3 +338,29 @@ class PlayerStartWindow(QtGui.QDialog): self.playerGrid.addWidget(edit, row, 1) +class VictoryWindow(QtGui.QDialog): + def __init__(self, players, parent): + super(VictoryWindow, self).__init__(parent) + self._players = players + self._parent = parent + + self._setupGui() + + def _setupGui(self): + self.layout = QtGui.QVBoxLayout() + self.playerGrid = QtGui.QGridLayout() + + winPlayers = sorted(self._players, key=lambda p: p.points, reverse=True) + for i, player in enumerate(winPlayers): + label = QtGui.QLabel(player.name, self) + fsize = 60 if i == 0 else 25 + label.setStyleSheet("QLabel { font-size: %dpx; background-color: %s; color: white; }" % (fsize, player.color.name(),)) + self.playerGrid.addWidget(label, i, 0) + + points = QtGui.QLabel(str(player.points), self) + points.setStyleSheet("QLabel { font-size: %dpx; }" % (fsize,)) + self.playerGrid.addWidget(points, i, 1, alignment=QtCore.Qt.AlignRight) + + self.layout.addLayout(self.playerGrid) + + self.setLayout(self.layout)