예제 #1
0
파일: widgets.py 프로젝트: smyrman/kikrit
    def __init__(self, rfid_thread, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.rfid_thread = rfid_thread

        # Views:
        self.label = QtGui.QLabel("Amount to deposit:")
        self.label.setAlignment(QtCore.Qt.AlignRight)

        self.amount_line = AmountLine()
        self.amount_line.grabKeyboard()

        self.msg = MessageLine()

        self.stack = QtGui.QStackedWidget()
        self.empty_page = QtGui.QWidget(self.stack)
        self.balance_page = BalancePage(self.stack)
        self.stack.addWidget(self.empty_page)
        self.stack.addWidget(self.balance_page)

        # Layout:
        grid = QtGui.QGridLayout()
        grid.addWidget(self.label, 0, 0)
        grid.addWidget(self.amount_line, 0, 1)
        grid.addWidget(self.stack, 1, 0, 1, 2)
        grid.addWidget(self.msg, 2, 1)
        self.setLayout(grid)

        # Connect signals:
        if parent != None:
            self.parentWidget().currentChanged.connect(self.tabChanged)
        self.rfid_thread.rfid_signal.connect(self.rfidEvent)

        self.amount_line.right_pressed.connect(self.rightPressed)
        self.amount_line.left_pressed.connect(self.leftPressed)
        self.amount_line.up_pressed.connect(self.upPressed)
        self.amount_line.down_pressed.connect(self.downPressed)
        self.amount_line.escape_pressed.connect(self.escapePressed)
예제 #2
0
파일: widgets.py 프로젝트: smyrman/kikrit
class DepositWidget(QtGui.QWidget):
    label = None
    amount_line = None
    msg = None

    stack = None
    balance_page = None
    empty_page = None

    def __init__(self, rfid_thread, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.rfid_thread = rfid_thread

        # Views:
        self.label = QtGui.QLabel("Amount to deposit:")
        self.label.setAlignment(QtCore.Qt.AlignRight)

        self.amount_line = AmountLine()
        self.amount_line.grabKeyboard()

        self.msg = MessageLine()

        self.stack = QtGui.QStackedWidget()
        self.empty_page = QtGui.QWidget(self.stack)
        self.balance_page = BalancePage(self.stack)
        self.stack.addWidget(self.empty_page)
        self.stack.addWidget(self.balance_page)

        # Layout:
        grid = QtGui.QGridLayout()
        grid.addWidget(self.label, 0, 0)
        grid.addWidget(self.amount_line, 0, 1)
        grid.addWidget(self.stack, 1, 0, 1, 2)
        grid.addWidget(self.msg, 2, 1)
        self.setLayout(grid)

        # Connect signals:
        if parent != None:
            self.parentWidget().currentChanged.connect(self.tabChanged)
        self.rfid_thread.rfid_signal.connect(self.rfidEvent)

        self.amount_line.right_pressed.connect(self.rightPressed)
        self.amount_line.left_pressed.connect(self.leftPressed)
        self.amount_line.up_pressed.connect(self.upPressed)
        self.amount_line.down_pressed.connect(self.downPressed)
        self.amount_line.escape_pressed.connect(self.escapePressed)

    def _reset(self):
        self.amount_line.setText("")
        self.stack.setCurrentIndex(0)

    def _tabHasFocus(self):
        """Returns True if self is the parrents current widget, or if there is
		no parent. Otherwise return False.

		"""
        parent = self.parentWidget()
        if parent == None or parent.currentWidget() == self:
            return True
        return False

    def tabChanged(self, index):
        if self.parentWidget().widget(index) == self:
            self.amount_line.grabKeyboard()
        else:
            self.amount_line.releaseKeyboard()

    def leftPressed(self):
        self.amount_line.addToAmount(-1)
        self.amount_line.selectAll()

    def rightPressed(self):
        self.amount_line.addToAmount(1)
        self.amount_line.selectAll()

    def upPressed(self):
        self.amount_line.addToAmount(10)
        self.amount_line.selectAll()

    def downPressed(self):
        self.amount_line.addToAmount(-10)
        self.amount_line.selectAll()

    def escapePressed(self):
        self._reset()

    def rfidEvent(self, rfid_str):
        # Guard: This widget has focus?
        if not self._tabHasFocus():
            return

            # Get amount:
        try:
            txt = self.amount_line.text()
            if txt == "":
                txt = "0"
            amount = int(txt)
            if float(amount) != float(txt):
                amount = None
                self.msg.post("Deposit amount must be an integer", self.msg.STYLE_ERROR)
        except ValueError:
            amount = None
            self.msg.post("Deposit amount must be an integer", self.msg.STYLE_ERROR)

            # Get card:
        try:
            card = RFIDCard.objects.get(rfid_string=unicode(rfid_str))
        except RFIDCard.DoesNotExist:
            self.msg.post("RFID card not found", self.msg.STYLE_ERROR)
            card = None

            # Execute deposit:
        if card != None and amount != None:
            if amount > 0:
                deposit_money(card.account, amount)
                self._reset()
                self.msg.post(u"An amount of %d,- was deposited" % amount, self.msg.STYLE_DEPOSIT)
                self.balance_page.showPage(card.account)
            else:
                self._reset()
                self.balance_page.showPage(card.account)