Esempio n. 1
0
    def addVote(self, bookName, bookId, userName, passwd, userType, userBigSmall, recVoteNum, advVoteNum):
        "This slot will be invoked once the 'userDropped' signal is emitted from bookListWidget."

        matchlist = self.findItems(bookName, Qt.MatchExactly, 0)
        exist_userType = None
        exist_userName = None
        if len(matchlist) > 0:
            bookItem = self.findItems(bookName, Qt.MatchExactly, 0)[0]
            exist_userType = bookItem.child(0).text(1)
            exist_userName = bookItem.child(0).text(0)
        result = rule.validationForAddVote(bookName, bookId, userName, userType, exist_userName, exist_userType, recVoteNum, advVoteNum)
        if result:
            QMessageBox.information(self, u'提示:', result, QMessageBox.Ok)
            return

        realRecVoteNum, realAdvVoteNum, remainRecVoteNum, remainAdvVoteNum = rule.getRealRemainVoteNum(userBigSmall, recVoteNum, advVoteNum)

        # emit the remain vote num signal to update userTableWidget
        self.emit(SIGNAL('voteCompleted'), userName, remainRecVoteNum, remainAdvVoteNum)
        
        voteData = self.appdata.getVoteData()
        voteData.addData(bookName, bookId, userName, passwd)
        with open('data', 'w') as file:
            pickle.dump(self.appdata, file)

        self.__addNewRowOnVoteTree(bookName, bookId, userName, passwd, userType, userBigSmall, realRecVoteNum, realAdvVoteNum)
Esempio n. 2
0
    def updateUserTableByUserName(self, userName):
        # find matched userItem
        userItems = self.findItems(userName, Qt.MatchExactly)
        for userItem in userItems:
            if self.column(userItem) == 0:
                break
        else:
            # (1) match failed, so we skipped to update vote tree widget.
            return None
        row = self.row(userItem)

        # userType, userBigSmall, recVoteNum, advVoteNum
        userType = self.item(row, 1).text()
        userBigSmall = self.item(row, 2).text()
        recVoteNum = self.item(row, 3).text()
        advVoteNum = self.item(row, 4).text()

        # (2) login failed, so we skipped to update vote tree widget.
        if int(recVoteNum) == -1:
            return None
                
        realRecVoteNum, realAdvVoteNum, remainRecVoteNum, remainAdvVoteNum = rule.getRealRemainVoteNum(userBigSmall, recVoteNum, advVoteNum)

        self.item(row, 3).setText(remainRecVoteNum)
        self.item(row, 4).setText(remainAdvVoteNum)
        
        return (userType, userBigSmall, realRecVoteNum, realAdvVoteNum)