Esempio n. 1
0
    def __init__(self, svgfile, component, nodes):
        #QGraphicsSvgItem.__init__(self,svgfile)
        QGraphicsObject.__init__(self)
        self.__svggraphic = QGraphicsSvgItem(svgfile)

        rect = self.__svggraphic.boundingRect()

        self.__nodeGraphics = []
        self.__component = weakref.ref(component)

        # this signals the itemChange() method when this item is moved
        # used for refreshing the spaces between components
        self.setFlags(QGraphicsItem.ItemSendsGeometryChanges)
        self.nodedx = []  # stores the node square offsets

        item = QGraphicsTextItem(component.name, self)
        rect = item.boundingRect()
        item.setPos(-0.5 * rect.width(), 40 - 0.5 * rect.height())

        self.setAcceptsHoverEvents(True)

        for n in nodes:
            self.nodedx.append([n[0], n[1]])
            node = n[2].getQGraphicsItem(n[0], n[1], nsize, self)
            node.setPen(QPen(Qt.black))
            node.refresh()
            self.__nodeGraphics.append(node)

        self.refresh()
        self.installEventFilter(self)
        self.setHandlesChildEvents(True)
Esempio n. 2
0
 def show(self):
     self.scale(0.0, 0.0)
     self.animation.setPosAt(0.0, QPointF(self.matrix.dx()+self.boundingRect().width()/8, self.matrix.dy()+self.boundingRect().height()/8))
     self.animation.setPosAt(1.0, QPointF(self.matrix.dx(), self.matrix.dy()))
     self.animation.setScaleAt(0.0, 0.25, 0.25)
     self.animation.setScaleAt(1.0, 0.5, 0.5)
     self.timeline.start()
     QGraphicsSvgItem.show(self)
Esempio n. 3
0
 def show(self):
     self.scale(0.0, 0.0)
     self.animation.setPosAt(
         0.0,
         QPointF(self.matrix.dx() + self.boundingRect().width() / 8,
                 self.matrix.dy() + self.boundingRect().height() / 8))
     self.animation.setPosAt(1.0, QPointF(self.matrix.dx(),
                                          self.matrix.dy()))
     self.animation.setScaleAt(0.0, 0.25, 0.25)
     self.animation.setScaleAt(1.0, 0.5, 0.5)
     self.timeline.start()
     QGraphicsSvgItem.show(self)
Esempio n. 4
0
 def __init__(self, name, tileset, roundsFinished=0, parent = None):
     """generate new wind tile"""
     if not len(WINDPIXMAPS):
         WINDPIXMAPS[('E', False)] = None # avoid recursion
         self.genWINDPIXMAPS()
     QGraphicsEllipseItem.__init__(self)
     if parent:
         self.setParentItem(parent)
     self.name = name
     self.face = QGraphicsSvgItem()
     self.face.setParentItem(self)
     self.prevailing = None
     self.setWind(name, roundsFinished)
     self.tileset = tileset
     self.__sizeFace()
Esempio n. 5
0
    def itemChange(self, change, value):
        # if the item is moved then update any spaces attached to it
        if change == QGraphicsItem.ItemPositionHasChanged:
            nodes = self.component.nodes

            for n in nodes:
                conn = n.amIConnected(self.component)

                if conn[0] and isinstance(conn[1], pykat.components.space):
                    conn[1].getQGraphicsItem().refresh()

        return QGraphicsSvgItem.itemChange(self, change, value)
Esempio n. 6
0
class ComponentQGraphicsItem(QGraphicsObject):  #(QtSvg.QGraphicsSvgItem):
    def __init__(self, svgfile, component, nodes):
        #QGraphicsSvgItem.__init__(self,svgfile)
        QGraphicsObject.__init__(self)
        self.__svggraphic = QGraphicsSvgItem(svgfile)

        rect = self.__svggraphic.boundingRect()

        self.__nodeGraphics = []
        self.__component = weakref.ref(component)

        # this signals the itemChange() method when this item is moved
        # used for refreshing the spaces between components
        self.setFlags(QGraphicsItem.ItemSendsGeometryChanges)
        self.nodedx = []  # stores the node square offsets

        item = QGraphicsTextItem(component.name, self)
        rect = item.boundingRect()
        item.setPos(-0.5 * rect.width(), 40 - 0.5 * rect.height())

        self.setAcceptsHoverEvents(True)

        for n in nodes:
            self.nodedx.append([n[0], n[1]])
            node = n[2].getQGraphicsItem(n[0], n[1], nsize, self)
            node.setPen(QPen(Qt.black))
            node.refresh()
            self.__nodeGraphics.append(node)

        self.refresh()
        self.installEventFilter(self)
        self.setHandlesChildEvents(True)

    def boundingRect(self):
        return self.__svggraphic.boundingRect()

    def paint(self, arg1, arg2, arg3):
        self.__svggraphic.rotate(45)
        self.__svggraphic.paint(arg1, arg2, arg3)

    @property
    def component(self):
        return self.__component()

    def refresh(self):
        for n in self.__nodeGraphics:
            n.refresh()

    def itemChange(self, change, value):
        # if the item is moved then update any spaces attached to it
        if change == QGraphicsItem.ItemPositionHasChanged:
            nodes = self.component.nodes

            for n in nodes:
                conn = n.amIConnected(self.component)

                if conn[0] and isinstance(conn[1], pykat.components.space):
                    conn[1].getQGraphicsItem().refresh()

        return QGraphicsSvgItem.itemChange(self, change, value)
    def mousePressEvent(self, event):
        """ We reimplement this function to store the position of
        the item when a user issues a mouse press.

        """

        self._position = self.pos()

        if (event.modifiers() & Qt.ControlModifier):
            QApplication.setOverrideCursor(QCursor(Qt.SizeAllCursor))
        else:
            event.ignore()

        return QGraphicsSvgItem.mousePressEvent(self, event)
    def mousePressEvent(self, event):
        """ We reimplement this function to store the position of
        the item when a user issues a mouse press.

        """

        self._position = self.pos()

        if (event.modifiers() & Qt.ControlModifier):
            QApplication.setOverrideCursor(QCursor(Qt.SizeAllCursor))
        else:
            event.ignore()

        return QGraphicsSvgItem.mousePressEvent(self, event)
Esempio n. 9
0
 def __init__(self, name, tileset, roundsFinished=0, parent = None):
     """generate new wind tile"""
     if not len(WINDPIXMAPS):
         WINDPIXMAPS[('E', False)] = None # avoid recursion
         self.genWINDPIXMAPS()
     QGraphicsEllipseItem.__init__(self)
     if parent:
         self.setParentItem(parent)
     self.name = name
     self.face = QGraphicsSvgItem()
     self.face.setParentItem(self)
     self.prevailing = None
     self.setWind(name, roundsFinished)
     self.tileset = tileset
     self.__sizeFace()
Esempio n. 10
0
    def mouseReleaseEvent(self, event):
        """ We reimplement this function to check if its position
        has changed since the last mouse click. If yes we
        let the canvas know so it can store the action as
        a Redo/Undo event.

        """

        QApplication.restoreOverrideCursor()

        # this is needed for redo/undo
        if self._position != self.pos():
           self.scene().canvas_item_position_changed(self, self._position,
                                                     self.pos())

        return QGraphicsSvgItem.mouseReleaseEvent(self, event)
Esempio n. 11
0
    def mouseReleaseEvent(self, event):
        """ We reimplement this function to check if its position
        has changed since the last mouse click. If yes we
        let the canvas know so it can store the action as
        a Redo/Undo event.

        """

        QApplication.restoreOverrideCursor()

        # this is needed for redo/undo
        if self._position != self.pos():
            self.scene().canvas_item_position_changed(self, self._position,
                                                      self.pos())

        return QGraphicsSvgItem.mouseReleaseEvent(self, event)
Esempio n. 12
0
class PlayerWind(QGraphicsEllipseItem):
    """a round wind tile"""
    def __init__(self, name, tileset, roundsFinished=0, parent = None):
        """generate new wind tile"""
        if not len(WINDPIXMAPS):
            WINDPIXMAPS[('E', False)] = None # avoid recursion
            self.genWINDPIXMAPS()
        QGraphicsEllipseItem.__init__(self)
        if parent:
            self.setParentItem(parent)
        self.name = name
        self.face = QGraphicsSvgItem()
        self.face.setParentItem(self)
        self.prevailing = None
        self.setWind(name, roundsFinished)
        self.tileset = tileset
        self.__sizeFace()

    @staticmethod
    def genWINDPIXMAPS():
        """prepare wind tiles"""
        tileset = Tileset(common.PREF.windTilesetName)
        for wind in WINDS:
            for prevailing in False, True:
                pwind = PlayerWind(wind, tileset, prevailing)
                pMap = QPixmap(40, 40)
                pMap.fill(Qt.transparent)
                painter = QPainter(pMap)
                painter.setRenderHint(QPainter.Antialiasing)
                painter.scale(0.40, 0.40)
                pwind.paint(painter, QStyleOptionGraphicsItem())
                for child in pwind.childItems():
                    if isinstance(child, QGraphicsSvgItem):
                        painter.save()
                        painter.translate(child.mapToParent(0.0, 0.0))
                        child.paint(painter, QStyleOptionGraphicsItem())
                        painter.restore()
                WINDPIXMAPS[(wind, prevailing)] = pMap

    def __sizeFace(self):
        """size the chinese character depending on the wind tileset"""
        self.resetTransform()
        size = self.tileset.faceSize
        self.setFlag(QGraphicsItem.ItemClipsChildrenToShape)
        diameter = size.height() * 1.1
        scaleFactor = 0.9
        facePos = {'traditional':(10, 10), 'default':(15, 10),
                   'classic':(19, 1), 'jade':(19, 1)}
        self.setRect(0, 0, diameter, diameter)
        self.setScale(scaleFactor)
        faceX, faceY = facePos[self.tileset.desktopFileName]
        self.face.setPos(faceX, faceY)
        self.face.setSharedRenderer(self.tileset.renderer())

    def setWind(self, name, roundsFinished):
        """change the wind"""
        self.name = name
        if isinstance(roundsFinished, bool):
            self.prevailing = roundsFinished
        else:
            self.prevailing = name == WINDS[roundsFinished % 4]
        self.setBrush(ROUNDWINDCOLOR if self.prevailing else QColor('white'))
        windtilenr = {'N':1, 'S':2, 'E':3, 'W':4}
        self.face.setElementId('WIND_%d' % windtilenr[name])
Esempio n. 13
0
    def __init__(self, dataDir="", parent=None):
        QWidget.__init__(self, parent)
        self.renderer = QSvgRenderer(dataDir + "poker.svg")
        self.scene = QGraphicsScene()
        self.chat = QGraphicsSimpleTextItem()
        self.table = QGraphicsSvgItem(dataDir + "poker.svg")
        self.table.setSharedRenderer(self.renderer)
        self.table.setElementId("table")
        self.table.setMatrix(self.renderer.matrixForElement("transform_table"))
        self.scene.addItem(self.chat)
        self.scene.addItem(self.table)
        self.board = []
        for i in range(5):
            card = AnimatedGraphicsSvgItem(dataDir + "svg-cards.svg",
                                           self.table)
            card.setElementId("back")
            parent = self.renderer.matrixForElement("transform_table")
            child = self.renderer.matrixForElement("transform_card%i" % i)
            cardMatrix = child.translate(-parent.dx(), -parent.dy())
            card.setMatrix(cardMatrix)
            #card.setFlag(QGraphicsSvgItem.ItemIsMovable, True)
            card.scale(0.5, 0.5)
            card.hide()
            self.scene.addItem(card)
            self.board.append(card)
        self.seats = []
        self.names = []
        self.moneys = []
        self.bets = []
        for i in range(10):
            seat = SeatItem()

            def seatClickedEvent(seat=i):
                seatClickedCallback = self.seatClicked
                seatClickedCallback(seat)

            seat.event = seatClickedEvent
            seat.setSharedRenderer(self.renderer)
            seat.setElementId("seat")
            seat.setMatrix(
                self.renderer.matrixForElement("transform_seat%i" % i))
            self.scene.addItem(seat)
            self.seats.append(seat)
            name = QGraphicsSimpleTextItem(seat)
            name.setMatrix(self.renderer.matrixForElement("seat_name"))
            self.scene.addItem(name)
            self.names.append(name)
            money = QGraphicsSimpleTextItem(seat)
            money.setMatrix(self.renderer.matrixForElement("seat_money"))
            self.scene.addItem(money)
            self.moneys.append(money)
            bet = QGraphicsSimpleTextItem()
            bet.setMatrix(self.renderer.matrixForElement("transform_bet%i" %
                                                         i))
            self.scene.addItem(bet)
            self.bets.append(bet)
        self.pots = []
        for i in range(9):
            pot = QGraphicsSimpleTextItem()
            pot.setMatrix(self.renderer.matrixForElement("transform_pot%i" %
                                                         i))
            self.scene.addItem(pot)
            self.pots.append(pot)
        self.view = QGraphicsView(self)
        self.view.setScene(self.scene)
        self.view.resize(800, 600)
        self.fold = ActionItem()
        self.fold.setText("fold")
        self.fold.setPos(0, 550)
        self.scene.addItem(self.fold)
        self.fold.event = lambda: self.foldClicked()
        self.check = ActionItem()
        self.check.setText("check")
        self.check.setPos(50, 550)
        self.scene.addItem(self.check)
        self.check.event = lambda: self.checkClicked()
        self.call = ActionItem()
        self.call.setText("call")
        self.call.setPos(100, 550)
        self.scene.addItem(self.call)
        self.call.event = lambda: self.callClicked()
        self.bet = ActionItem()
        self.bet.setText("bet")
        self.bet.setPos(150, 550)
        self.scene.addItem(self.bet)
        self.bet.event = lambda: self.betClicked()
Esempio n. 14
0
class QPokerWidget(QWidget):
    def __init__(self, dataDir="", parent=None):
        QWidget.__init__(self, parent)
        self.renderer = QSvgRenderer(dataDir + "poker.svg")
        self.scene = QGraphicsScene()
        self.chat = QGraphicsSimpleTextItem()
        self.table = QGraphicsSvgItem(dataDir + "poker.svg")
        self.table.setSharedRenderer(self.renderer)
        self.table.setElementId("table")
        self.table.setMatrix(self.renderer.matrixForElement("transform_table"))
        self.scene.addItem(self.chat)
        self.scene.addItem(self.table)
        self.board = []
        for i in range(5):
            card = AnimatedGraphicsSvgItem(dataDir + "svg-cards.svg",
                                           self.table)
            card.setElementId("back")
            parent = self.renderer.matrixForElement("transform_table")
            child = self.renderer.matrixForElement("transform_card%i" % i)
            cardMatrix = child.translate(-parent.dx(), -parent.dy())
            card.setMatrix(cardMatrix)
            #card.setFlag(QGraphicsSvgItem.ItemIsMovable, True)
            card.scale(0.5, 0.5)
            card.hide()
            self.scene.addItem(card)
            self.board.append(card)
        self.seats = []
        self.names = []
        self.moneys = []
        self.bets = []
        for i in range(10):
            seat = SeatItem()

            def seatClickedEvent(seat=i):
                seatClickedCallback = self.seatClicked
                seatClickedCallback(seat)

            seat.event = seatClickedEvent
            seat.setSharedRenderer(self.renderer)
            seat.setElementId("seat")
            seat.setMatrix(
                self.renderer.matrixForElement("transform_seat%i" % i))
            self.scene.addItem(seat)
            self.seats.append(seat)
            name = QGraphicsSimpleTextItem(seat)
            name.setMatrix(self.renderer.matrixForElement("seat_name"))
            self.scene.addItem(name)
            self.names.append(name)
            money = QGraphicsSimpleTextItem(seat)
            money.setMatrix(self.renderer.matrixForElement("seat_money"))
            self.scene.addItem(money)
            self.moneys.append(money)
            bet = QGraphicsSimpleTextItem()
            bet.setMatrix(self.renderer.matrixForElement("transform_bet%i" %
                                                         i))
            self.scene.addItem(bet)
            self.bets.append(bet)
        self.pots = []
        for i in range(9):
            pot = QGraphicsSimpleTextItem()
            pot.setMatrix(self.renderer.matrixForElement("transform_pot%i" %
                                                         i))
            self.scene.addItem(pot)
            self.pots.append(pot)
        self.view = QGraphicsView(self)
        self.view.setScene(self.scene)
        self.view.resize(800, 600)
        self.fold = ActionItem()
        self.fold.setText("fold")
        self.fold.setPos(0, 550)
        self.scene.addItem(self.fold)
        self.fold.event = lambda: self.foldClicked()
        self.check = ActionItem()
        self.check.setText("check")
        self.check.setPos(50, 550)
        self.scene.addItem(self.check)
        self.check.event = lambda: self.checkClicked()
        self.call = ActionItem()
        self.call.setText("call")
        self.call.setPos(100, 550)
        self.scene.addItem(self.call)
        self.call.event = lambda: self.callClicked()
        self.bet = ActionItem()
        self.bet.setText("bet")
        self.bet.setPos(150, 550)
        self.scene.addItem(self.bet)
        self.bet.event = lambda: self.betClicked()

    def renderChat(self, message):
        self.chat.setText(message)

    def renderBoard(self, cards):
        for i in range(len(cards)):
            item = self.board[i]
            card = cards[i]
            item.setElementId(card2SvgElement(card))
            if item.isVisible() == False:
                item.show()
        for i in range(len(cards), len(self.board)):
            item = self.board[i]
            item.hide()
            item.setElementId('back')

    def renderStart(self):
        map(lambda svgItem: svgItem.setElementId('back'), self.board)
        map(lambda svgItem: svgItem.hide(), self.board)

    def renderPlayerArrive(self, seat, name):
        self.names[seat].setText(name)
        self.names[seat].show()

    def renderPlayerLeave(self, seat):
        self.names[seat].setText('')
        self.names[seat].hide()
        self.moneys[seat].hide()
        self.bets[seat].hide()

    def renderPlayerChips(self, seat, money, bet):
        if bet > 0:
            self.bets[seat].setText(str(bet))
            self.bets[seat].show()
        else:
            self.bets[seat].hide()
        self.moneys[seat].setText(str(money))
        self.moneys[seat].show()

    def renderPot(self, index, amount):
        self.pots[index].setText(str(amount))
        self.pots[index].show()

    def renderPotReset(self):
        for pot in self.pots:
            pot.setText("")
            pot.hide()

    def renderPosition(self, seatInPosition):
        for i in range(len(self.seats)):
            seat = self.seats[i]
            if i == seatInPosition:
                seat.setElementId("seat_inposition")
            else:
                seat.setElementId("seat")

    def renderPositionReset(self):
        for seat in self.seats:
            seat.setElementId("seat")

    def keyPressEvent(self, event):
        if event.text() == "q":
            self.view.scale(1.1, 1.1)
        elif event.text() == "a":
            self.view.scale(0.9, 0.9)

    seatClicked = lambda seat: None
    foldClicked = lambda: None
    checkClicked = lambda: None
    callClicked = lambda: None
    betClicked = lambda: None
Esempio n. 15
0
 def __init__(self, file, parent = None):
     QGraphicsSvgItem.__init__(self, file, parent)
     self.animation = QGraphicsItemAnimation()
     self.animation.setItem(self)
     self.timeline = QTimeLine(300)
     self.animation.setTimeLine(self.timeline)
Esempio n. 16
0
 def setMatrix(self, matrix):
     self.matrix = matrix
     QGraphicsSvgItem.setMatrix(self, matrix)
Esempio n. 17
0
 def __init__(self, file, parent=None):
     QGraphicsSvgItem.__init__(self, file, parent)
     self.animation = QGraphicsItemAnimation()
     self.animation.setItem(self)
     self.timeline = QTimeLine(300)
     self.animation.setTimeLine(self.timeline)
Esempio n. 18
0
 def setMatrix(self, matrix):
     self.matrix = matrix
     QGraphicsSvgItem.setMatrix(self, matrix)
Esempio n. 19
0
class QPokerWidget(QWidget):
    def __init__(self, dataDir = "", parent = None):
        QWidget.__init__(self, parent)
        self.renderer = QSvgRenderer(dataDir + "poker.svg")
        self.scene = QGraphicsScene()
        self.chat = QGraphicsSimpleTextItem()
        self.table = QGraphicsSvgItem(dataDir + "poker.svg")
        self.table.setSharedRenderer(self.renderer)
        self.table.setElementId("table")
        self.table.setMatrix(self.renderer.matrixForElement("transform_table"))
        self.scene.addItem(self.chat)
        self.scene.addItem(self.table)
        self.board = []
        for i in range(5):
            card = AnimatedGraphicsSvgItem(dataDir + "svg-cards.svg", self.table)
            card.setElementId("back")
            parent = self.renderer.matrixForElement("transform_table")
            child = self.renderer.matrixForElement("transform_card%i" % i)
            cardMatrix = child.translate(-parent.dx(), -parent.dy())
            card.setMatrix(cardMatrix)
            #card.setFlag(QGraphicsSvgItem.ItemIsMovable, True)
            card.scale(0.5, 0.5)
            card.hide()
            self.scene.addItem(card)
            self.board.append(card)
        self.seats = []
        self.names = []
        self.moneys = []
        self.bets = []
        for i in range(10):
            seat = SeatItem()
            def seatClickedEvent(seat = i):                
                seatClickedCallback = self.seatClicked
                seatClickedCallback(seat)
            seat.event = seatClickedEvent
            seat.setSharedRenderer(self.renderer)
            seat.setElementId("seat")
            seat.setMatrix(self.renderer.matrixForElement("transform_seat%i" % i))
            self.scene.addItem(seat)
            self.seats.append(seat)
            name = QGraphicsSimpleTextItem(seat)
            name.setMatrix(self.renderer.matrixForElement("seat_name"))
            self.scene.addItem(name)
            self.names.append(name)
            money = QGraphicsSimpleTextItem(seat)
            money.setMatrix(self.renderer.matrixForElement("seat_money"))
            self.scene.addItem(money)
            self.moneys.append(money)
            bet = QGraphicsSimpleTextItem()            
            bet.setMatrix(self.renderer.matrixForElement("transform_bet%i" % i))
            self.scene.addItem(bet)
            self.bets.append(bet)
        self.pots = []
        for i in range(9):
            pot = QGraphicsSimpleTextItem()
            pot.setMatrix(self.renderer.matrixForElement("transform_pot%i" %i))
            self.scene.addItem(pot)
            self.pots.append(pot)
        self.view = QGraphicsView(self)
        self.view.setScene(self.scene)
        self.view.resize(800, 600)
        self.fold = ActionItem()
        self.fold.setText("fold")
        self.fold.setPos(0, 550)
        self.scene.addItem(self.fold)
        self.fold.event = lambda: self.foldClicked()
        self.check = ActionItem()
        self.check.setText("check")
        self.check.setPos(50, 550)
        self.scene.addItem(self.check)
        self.check.event = lambda: self.checkClicked()
        self.call = ActionItem()
        self.call.setText("call")
        self.call.setPos(100, 550)
        self.scene.addItem(self.call)
        self.call.event = lambda: self.callClicked()
        self.bet = ActionItem()
        self.bet.setText("bet")
        self.bet.setPos(150, 550)
        self.scene.addItem(self.bet)
        self.bet.event = lambda: self.betClicked()
    def renderChat(self, message):
        self.chat.setText(message)
    def renderBoard(self, cards):
        for i in range(len(cards)):
            item = self.board[i]
            card = cards[i]
            item.setElementId(card2SvgElement(card))
            if item.isVisible() == False:
                item.show()
        for i in range(len(cards), len(self.board)):
            item = self.board[i]
            item.hide()
            item.setElementId('back')
    def renderStart(self):
        map(lambda svgItem: svgItem.setElementId('back'), self.board)
        map(lambda svgItem: svgItem.hide(), self.board)
    def renderPlayerArrive(self, seat, name):
        self.names[seat].setText(name)
        self.names[seat].show()
    def renderPlayerLeave(self, seat):
        self.names[seat].setText('')
        self.names[seat].hide()
        self.moneys[seat].hide()
        self.bets[seat].hide()
    def renderPlayerChips(self, seat, money, bet):
        if bet > 0:
            self.bets[seat].setText(str(bet))
            self.bets[seat].show()
        else:
            self.bets[seat].hide()
        self.moneys[seat].setText(str(money))
        self.moneys[seat].show()
    def renderPot(self, index, amount):
        self.pots[index].setText(str(amount))
        self.pots[index].show()
    def renderPotReset(self):
        for pot in self.pots:
            pot.setText("")
            pot.hide()
    def renderPosition(self, seatInPosition):
        for i in range(len(self.seats)):
            seat = self.seats[i]
            if i == seatInPosition:
                seat.setElementId("seat_inposition")
            else:
                seat.setElementId("seat")
    def renderPositionReset(self):
        for seat in self.seats:
            seat.setElementId("seat")
    def keyPressEvent(self, event):
        if event.text() == "q":
            self.view.scale(1.1, 1.1)
        elif event.text() == "a":
            self.view.scale(0.9, 0.9)
    seatClicked = lambda seat: None
    foldClicked = lambda: None
    checkClicked = lambda: None
    callClicked = lambda: None
    betClicked = lambda: None
Esempio n. 20
0
 def __init__(self, dataDir = "", parent = None):
     QWidget.__init__(self, parent)
     self.renderer = QSvgRenderer(dataDir + "poker.svg")
     self.scene = QGraphicsScene()
     self.chat = QGraphicsSimpleTextItem()
     self.table = QGraphicsSvgItem(dataDir + "poker.svg")
     self.table.setSharedRenderer(self.renderer)
     self.table.setElementId("table")
     self.table.setMatrix(self.renderer.matrixForElement("transform_table"))
     self.scene.addItem(self.chat)
     self.scene.addItem(self.table)
     self.board = []
     for i in range(5):
         card = AnimatedGraphicsSvgItem(dataDir + "svg-cards.svg", self.table)
         card.setElementId("back")
         parent = self.renderer.matrixForElement("transform_table")
         child = self.renderer.matrixForElement("transform_card%i" % i)
         cardMatrix = child.translate(-parent.dx(), -parent.dy())
         card.setMatrix(cardMatrix)
         #card.setFlag(QGraphicsSvgItem.ItemIsMovable, True)
         card.scale(0.5, 0.5)
         card.hide()
         self.scene.addItem(card)
         self.board.append(card)
     self.seats = []
     self.names = []
     self.moneys = []
     self.bets = []
     for i in range(10):
         seat = SeatItem()
         def seatClickedEvent(seat = i):                
             seatClickedCallback = self.seatClicked
             seatClickedCallback(seat)
         seat.event = seatClickedEvent
         seat.setSharedRenderer(self.renderer)
         seat.setElementId("seat")
         seat.setMatrix(self.renderer.matrixForElement("transform_seat%i" % i))
         self.scene.addItem(seat)
         self.seats.append(seat)
         name = QGraphicsSimpleTextItem(seat)
         name.setMatrix(self.renderer.matrixForElement("seat_name"))
         self.scene.addItem(name)
         self.names.append(name)
         money = QGraphicsSimpleTextItem(seat)
         money.setMatrix(self.renderer.matrixForElement("seat_money"))
         self.scene.addItem(money)
         self.moneys.append(money)
         bet = QGraphicsSimpleTextItem()            
         bet.setMatrix(self.renderer.matrixForElement("transform_bet%i" % i))
         self.scene.addItem(bet)
         self.bets.append(bet)
     self.pots = []
     for i in range(9):
         pot = QGraphicsSimpleTextItem()
         pot.setMatrix(self.renderer.matrixForElement("transform_pot%i" %i))
         self.scene.addItem(pot)
         self.pots.append(pot)
     self.view = QGraphicsView(self)
     self.view.setScene(self.scene)
     self.view.resize(800, 600)
     self.fold = ActionItem()
     self.fold.setText("fold")
     self.fold.setPos(0, 550)
     self.scene.addItem(self.fold)
     self.fold.event = lambda: self.foldClicked()
     self.check = ActionItem()
     self.check.setText("check")
     self.check.setPos(50, 550)
     self.scene.addItem(self.check)
     self.check.event = lambda: self.checkClicked()
     self.call = ActionItem()
     self.call.setText("call")
     self.call.setPos(100, 550)
     self.scene.addItem(self.call)
     self.call.event = lambda: self.callClicked()
     self.bet = ActionItem()
     self.bet.setText("bet")
     self.bet.setPos(150, 550)
     self.scene.addItem(self.bet)
     self.bet.event = lambda: self.betClicked()
Esempio n. 21
0
    def __init__(self, parent = None):
        """
        Constructor
        """
        QtGui.QMainWindow.__init__(self, parent)
        self.setupUi(self)
        self.themeDir="/hometheme/Cockpit/"
        self.theme=["clock-drop-shadow.svg", 
                               "clock-face.svg", 
                               "clock-face-shadow.svg", 
                                "clock-marks.svg", 
                                "clock-frame.svg", 
                                "clock-glass.svg"
                             ]  
     
     #Variables that keep track of the angle of the hands, and  Time
        self.pHour=0
        self.pMinute=0
        self.pSecond=0
        self.secTimer = QtCore.QBasicTimer()
        self.minTimer=QtCore.QTimer()
        self.calibrateTimer=QtCore.QTimer()
        #The second hand counter  166=6 beats per second, 1000 =1 beat per sec
        self.secTimerType=166.9
        self.secTimerBeat=1
        #Variables that keep track of scene
        self.sceneWidth=0
        self.sceneHeight=0
        self.centerx=0
        self.centery=0
        self.xoffset=10
        #self.setGeometry(0,0,800, 480)
        self.setWindowTitle('Nclock')
        self.themeDir="/home/user/MyDocs/Nclocktheme/"
        #Check to see if files in /user/MyDocs/Nclock
        
        try:
            f=open (self.themeDir+"clock-face.svg")
        except :
            reply = QtGui.QMessageBox.question(self, 'Message',"No Theme Files in directory /home/user/MyDocs/Nclocktheme.     load default theme? No to Exit", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
            
            if reply==QtGui.QMessageBox.Yes :self.themeDir="theme/"
            else :    exit()
        
        #Initialize the Graphics Scene, Graphicsview is setup in QtDesigner UI
        self.scene = QtGui.QGraphicsScene()
        
        for path in self.theme:
            self.fileExist=1
            try:
                f=open (self.themeDir+path)
            except :
                    self.fileExist=0
            if self.fileExist==1:
                self.svgItem=QGraphicsSvgItem(self.themeDir+path)
                renderer=self.svgItem.renderer()
                self.scene.addItem(self.svgItem)
         #get the bounding box for the scene
        #self.rect=self.scene.itemsBoundingRect()
        #self.scene.setSceneRect(0, 0, 150, 150)
        self.rect=self.scene.itemsBoundingRect()
        
        self.sceneWidth=self.rect.width()
        self.sceneHeight=self.rect.height()
        self.centerx=self.sceneWidth/2
        self.centery=self.sceneHeight/2
        self.grView.centerOn(self.centerx, self.centery)
 
        #draw the Hourhand
        self.svgHour=QGraphicsSvgItem(self.themeDir+"clock-hour-hand.svg",)
        renderer=self.svgHour.renderer()
        self.svgHour.setPos(self.centerx, self.centery)
        #self.scene.addItem(self.svgHour)
        
        #draw the Minutehand
        self.svgMinute=QGraphicsSvgItem(self.themeDir+"clock-minute-hand.svg",)
        renderer=self.svgMinute.renderer()
        self.svgMinute.setPos(self.centerx, self.centery)
        #self.scene.addItem(self.svgMinute)
        
        #draw the Second hand 
        self.svgSecond=QGraphicsSvgItem(self.themeDir+"clock-second-hand.svg",)
        renderer=self.svgSecond.renderer()
        svgRect=QtCore.QRect()
        print svgRect
        svgRect.setX(-10)
        svgRect.setY(-1)
        svgRect.setWidth(100)
        svgRect.setHeight(100)
        print svgRect
        renderer.setViewBox(svgRect)
        self.svgSecond.setPos(self.centerx-10, self.centery-1)
        self.scene.addItem(self.svgSecond)
      
        #Paint the Scene and center
        self.rect=self.scene.itemsBoundingRect()
        height=self.rect.height()
        width=self.rect.width()
        if width>height: dimension=width
        
        else :dimension =height
        self.scene.setSceneRect(0, 0, dimension, dimension)
        self.rect=self.scene.itemsBoundingRect()
        
        self.grView.setScene(self.scene)
        self.grView.scale(3, 3)
Esempio n. 22
0
class PlayerWind(QGraphicsEllipseItem):
    """a round wind tile"""
    def __init__(self, name, tileset, roundsFinished=0, parent = None):
        """generate new wind tile"""
        if not len(WINDPIXMAPS):
            WINDPIXMAPS[('E', False)] = None # avoid recursion
            self.genWINDPIXMAPS()
        QGraphicsEllipseItem.__init__(self)
        if parent:
            self.setParentItem(parent)
        self.name = name
        self.face = QGraphicsSvgItem()
        self.face.setParentItem(self)
        self.prevailing = None
        self.setWind(name, roundsFinished)
        self.tileset = tileset
        self.__sizeFace()

    @staticmethod
    def genWINDPIXMAPS():
        """prepare wind tiles"""
        tileset = Tileset(Preferences.windTilesetName)
        for wind in WINDS:
            for prevailing in False, True:
                pwind = PlayerWind(wind, tileset, prevailing)
                pMap = QPixmap(40, 40)
                pMap.fill(Qt.transparent)
                painter = QPainter(pMap)
                painter.setRenderHint(QPainter.Antialiasing)
                painter.scale(0.40, 0.40)
                pwind.paint(painter, QStyleOptionGraphicsItem())
                for child in pwind.childItems():
                    if isinstance(child, QGraphicsSvgItem):
                        painter.save()
                        painter.translate(child.mapToParent(0.0, 0.0))
                        child.paint(painter, QStyleOptionGraphicsItem())
                        painter.restore()
                WINDPIXMAPS[(wind, prevailing)] = pMap

    def __sizeFace(self):
        """size the chinese character depending on the wind tileset"""
        self.resetTransform()
        size = self.tileset.faceSize
        self.setFlag(QGraphicsItem.ItemClipsChildrenToShape)
        diameter = size.height() * 1.1
        scaleFactor = 0.9
        facePos = {'traditional':(10, 10), 'default':(15, 10),
                   'classic':(19, 1), 'jade':(19, 1)}
        self.setRect(0, 0, diameter, diameter)
        self.setScale(scaleFactor)
        faceX, faceY = facePos[self.tileset.desktopFileName]
        self.face.setPos(faceX, faceY)
        self.face.setSharedRenderer(self.tileset.renderer())

    def setWind(self, name, roundsFinished):
        """change the wind"""
        self.name = name
        if isinstance(roundsFinished, bool):
            self.prevailing = roundsFinished
        else:
            self.prevailing = name == WINDS[roundsFinished % 4]
        self.setBrush(ROUNDWINDCOLOR if self.prevailing else QColor('white'))
        windtilenr = {'N':1, 'S':2, 'E':3, 'W':4}
        self.face.setElementId('WIND_%d' % windtilenr[name])
Esempio n. 23
0
 def __init__( self, fName, ref ):
     self.__fName = fName
     QGraphicsSvgItem.__init__( self, self.__getPath( fName ) )
     self.__scale = 0
     self.ref = ref
     return
Esempio n. 24
0
 def __init__(self,parent=None,scene=None):
     QGraphicsSvgItem.__init__(self)