class RemigioPlayerInputWidget(QtGui.QFrame): winnerSet = QtCore.Signal(str) def __init__(self,player,bgcolors,colour=None,parent=None): super(RemigioPlayerInputWidget, self).__init__(parent) self.player = player self.pcolour = colour self.ko = False self.bgcolors = bgcolors self.mainLayout = QtGui.QVBoxLayout(self) self.label = QtGui.QLabel(self) self.mainLayout.addWidget(self.label) self.label.setAutoFillBackground(False) self.setFrameShape(QtGui.QFrame.Panel) self.setFrameShadow(QtGui.QFrame.Raised) self.label.setScaledContents(True) self.label.setAlignment(QtCore.Qt.AlignCenter) self.label.setWordWrap(False) self.scoreSpinBox = ScoreSpinBox(self) self.scoreSpinBox.setAlignment(QtCore.Qt.AlignCenter) # self.scoreSpinBox.setMaximumWidth(150) self.scoreSpinBox.setRange(-1,100) self.setColour(colour) self.lowerLayout = QtGui.QHBoxLayout() self.mainLayout.addLayout(self.lowerLayout) self.lowerLayout.addWidget(self.scoreSpinBox) self.reset() def reset(self): self.closeType = 0 self.updatePanel() def setColour(self,colour): self.pcolour = colour sh = "font-size: 24px; font-weight: bold; color:rgb({},{},{});".format(self.pcolour.red(),self.pcolour.green(),self.pcolour.blue()) self.label.setStyleSheet(sh) sh = """ QSpinBox {{ {} }} QSpinBox::up-button {{subcontrol-origin: border; subcontrol-position: left; width: 60px; height: 60px; }} QSpinBox::down-button {{subcontrol-origin: border; subcontrol-position: right; width: 60px; height: 60px; }} """.format(sh) self.scoreSpinBox.setStyleSheet(sh) def increaseCloseType(self): self.closeType = (self.closeType)%4 + 1 self.updatePanel() def updatePanel(self): text = "{}".format(self.player) css = "" if self.closeType > 0: text = text + " ({}x)".format(self.closeType) css = "font-weight: bold; background-color: #{0:X}".format(self.bgcolors[self.closeType]) self.setFrameShadow(QtGui.QFrame.Sunken) self.scoreSpinBox.setValue(0) self.scoreSpinBox.setDisabled(True) else: self.setFrameShadow(QtGui.QFrame.Raised) self.scoreSpinBox.setValue(-1) self.scoreSpinBox.setEnabled(True) self.label.setText(text) self.setStyleSheet("QFrame {{ {} }}".format(css)) def mousePressEvent(self, event): if self.isWinner(): self.increaseCloseType() else: self.scoreSpinBox.setFocus() def mouseDoubleClickEvent(self, event): if not self.isWinner(): self.winnerSet.emit(self.player) self.increaseCloseType() else: super(RemigioPlayerInputWidget,self).mouseDoubleClickEvent(event) def getScore(self): if self.isWinner(): return 0 else: return self.scoreSpinBox.value() def isWinner(self): return self.closeType > 0 def getCloseType(self): return self.closeType def getPlayer(self): return self.player def isKo(self): return self.ko def setKo(self): self.ko = True self.setDisabled(True) def unsetKo(self): self.ko = False self.setDisabled(False)
class RatukiPlayerInputWidget(QtGui.QFrame): winnerSet = QtCore.Signal(str) def __init__(self,player,colour=None, parent=None): super(RatukiPlayerInputWidget, self).__init__(parent) self.player = player self.winner = False self.pcolour = colour self.mainLayout = QtGui.QVBoxLayout(self) self.label = QtGui.QLabel(self) self.label.setText(self.player) self.mainLayout.addWidget(self.label) self.label.setAutoFillBackground(False) self.setFrameShape(QtGui.QFrame.Panel) self.setFrameShadow(QtGui.QFrame.Raised) self.label.setScaledContents(True) self.label.setAlignment(QtCore.Qt.AlignCenter) self.label.setWordWrap(False) self.scoreSpinBox = ScoreSpinBox(self) self.scoreSpinBox.setAlignment(QtCore.Qt.AlignCenter) # self.scoreSpinBox.setMaximumWidth(60) self.scoreSpinBox.setRange(-100,100) # self.mainLayout.addWidget(self.scoreSpinBox) # self.mainLayout.setAlignment(self.scoreSpinBox,QtCore.Qt.AlignCenter) self.setColour(self.pcolour) self.lowerLayout = QtGui.QHBoxLayout() self.mainLayout.addLayout(self.lowerLayout) self.lowerLayout.addWidget(self.scoreSpinBox) self.reset() def reset(self): self.winner = False self.scoreSpinBox.setValue(0) self.updatePanel() def updatePanel(self): css = "" if self.winner: css = "font-weight: bold; background-color: #{0:X}".format(0xFFFF99) self.setFrameShadow(QtGui.QFrame.Sunken) else: self.setFrameShadow(QtGui.QFrame.Raised) self.setStyleSheet("QFrame {{ {} }}".format(css)) def mousePressEvent(self, event): self.scoreSpinBox.setFocus() def mouseDoubleClickEvent(self, event): if not self.isWinner(): self.winner = True self.updatePanel() self.winnerSet.emit(self.player) else: super(RatukiPlayerInputWidget,self).mouseDoubleClickEvent(event) def isWinner(self): return self.winner def getPlayer(self): return self.player def getScore(self): return self.scoreSpinBox.value() def setColour(self,colour=None): if colour is not None: self.pcolour = colour sh = "font-size: 24px; font-weight: bold; color:rgb({},{},{});".format(self.pcolour.red(),self.pcolour.green(),self.pcolour.blue()) self.label.setStyleSheet(sh) sh = """ QSpinBox {{ {} }} QSpinBox::up-button {{subcontrol-origin: border; subcontrol-position: left; width: 60px; height: 60px; }} QSpinBox::down-button {{subcontrol-origin: border; subcontrol-position: right; width: 60px; height: 60px; }} """.format(sh) self.scoreSpinBox.setStyleSheet(sh) print("Setting stylesheet to the scoreSpinBox")