seopardy/player.py

63 lines
1.8 KiB
Python

from __future__ import print_function
from PySide import QtGui, QtCore
class Player(QtGui.QWidget):
DEFAULT_PLAYERS = [
("Foo", QtGui.QColor(255, 0, 0)),
("Bar", QtGui.QColor(0, 255, 0)),
("Baz", QtGui.QColor(0, 0, 255)),
("Blubb", QtGui.QColor(0, 255, 255)),
("Murr", QtGui.QColor(255, 0, 255)),
]
def __init__(self, name, color, points=0, parent=None):
super(Player, self).__init__(parent)
self.name = name
self.color = color
self.points = points
self._setup_gui()
def _setup_gui(self):
self.layout = QtGui.QVBoxLayout()
self.name_label = QtGui.QLabel(self.name, self)
self.name_label.setStyleSheet("QLabel { font-size: 40px; background-color: %s; color: white; }" % (self.color.name(),))
self.layout.addWidget(self.name_label)
self.points_label = QtGui.QLabel(str(self.points), self)
self.points_label.setStyleSheet("QLabel { font-size: 40px;}")
self.layout.addWidget(self.points_label, alignment=QtCore.Qt.AlignRight)
self.setLayout(self.layout)
def change_name(self, new_name):
self.name = new_name
self.name_label.setText(new_name)
def add_points(self, amount):
self.points += amount
self.points_label.setText("% 5s" % (self.points,))
@classmethod
def gen_player(clazz, num, parent=None):
if num > len(clazz.DEFAULT_PLAYERS):
raise ValueError("You tried to generate too many players")
return clazz(*clazz.DEFAULT_PLAYERS[num-1], parent=parent)
class ButtonEvent(QtCore.QEvent):
eventType = QtCore.QEvent.Type(QtCore.QEvent.registerEventType())
def __init__(self, playerno):
super(ButtonEvent, self).__init__(self.eventType)
if playerno < 0 or playerno > 10:
raise ValueError("That player number is just not plausable")
self.playerno = playerno
def get_playerno(self):
return self.playerno
nobodyColor = QtGui.QColor(128, 128, 128)