Пример #1
0
 def __init__(self, parent = None, lifePoints = 20):
     QPushButton.__init__(self, parent)
     self.player = Player(lifePoints)
     self.setText(str(self.player.lifePoints))
Пример #2
0
class LifeButton(QPushButton):
    def __init__(self, parent = None, lifePoints = 20):
        QPushButton.__init__(self, parent)
        self.player = Player(lifePoints)
        self.setText(str(self.player.lifePoints))

    #Update life total depending on mouse click and keyboard modifiers
    def mousePressEvent(self, event):
        mod = QApplication.keyboardModifiers()

        if event.button() == Qt.LeftButton:
            if mod & Qt.ControlModifier:
                self.player.addLifePoints(2)
            elif mod & Qt.MetaModifier:
                self.player.addLifePoints(5)
            elif mod & Qt.ShiftModifier:
                self.player.addLifePoints(10)
            else:
                self.player.addLifePoints()
        elif event.button() == Qt.RightButton:
            if mod & Qt.ControlModifier:
                self.player.subtractLifePoints(2)
            elif mod & Qt.MetaModifier:
                self.player.subtractLifePoints(5)
            elif mod & Qt.ShiftModifier:
                self.player.subtractLifePoints(10)
            else:
                self.player.subtractLifePoints()

        self.setText(str(self.player.lifePoints))
        
    #Reset life totals back to default
    def resetState(self, lifePoints = 20):
        self.player.lifePoints = lifePoints
        self.setText(str(self.player.lifePoints))