示例#1
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.prenoms=[x.strip().capitalize() for x in open("prenoms.txt",encoding="utf-8")]

        # Get user name
        ok = False
        while not ok:
            login, ok = QtGui.QInputDialog.getText(self, 'Nom', 'Votre nom SVP:')

        self.ballots=Ballots("ballots_%s.txt"%login)
        self.combis=[]
        for n,p in enumerate(self.prenoms):
            for p2 in self.prenoms[n+1:]:
                self.combis.append((p,p2))
        import random
        random.shuffle(self.combis)

        # limit the number of votes to 50
        self.combis = self.combis[:50]

        QtCore.QObject.connect(self.ui.button1,QtCore.SIGNAL("clicked()"), self.callback_1)
        QtCore.QObject.connect(self.ui.button2,QtCore.SIGNAL("clicked()"), self.callback_2)
        QtCore.QObject.connect(self.ui.button_equal,QtCore.SIGNAL("clicked()"), self.callback_eq)
        QtCore.QObject.connect(self.ui.actionQuit,QtCore.SIGNAL("triggered()"), sys.exit)
        QtCore.QObject.connect(self.ui.actionResults,QtCore.SIGNAL("triggered()"), self.show_results)
        self.update()
示例#2
0
class StartQT4(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.prenoms=[x.strip().capitalize() for x in open("prenoms.txt",encoding="utf-8")]

        # Get user name
        ok = False
        while not ok:
            login, ok = QtGui.QInputDialog.getText(self, 'Nom', 'Votre nom SVP:')

        self.ballots=Ballots("ballots_%s.txt"%login)
        self.combis=[]
        for n,p in enumerate(self.prenoms):
            for p2 in self.prenoms[n+1:]:
                self.combis.append((p,p2))
        import random
        random.shuffle(self.combis)

        # limit the number of votes to 50
        self.combis = self.combis[:50]

        QtCore.QObject.connect(self.ui.button1,QtCore.SIGNAL("clicked()"), self.callback_1)
        QtCore.QObject.connect(self.ui.button2,QtCore.SIGNAL("clicked()"), self.callback_2)
        QtCore.QObject.connect(self.ui.button_equal,QtCore.SIGNAL("clicked()"), self.callback_eq)
        QtCore.QObject.connect(self.ui.actionQuit,QtCore.SIGNAL("triggered()"), sys.exit)
        QtCore.QObject.connect(self.ui.actionResults,QtCore.SIGNAL("triggered()"), self.show_results)
        self.update()
        #print self.prenoms
    def callback_1(self):
        self.count_ballot_and_update(1)
    def callback_2(self):
        self.count_ballot_and_update(2)
    def callback_eq(self):
        self.count_ballot_and_update(0)
    def update(self):
        p1,p2=None,None
        while p1 is None or frozenset((p1,p2)) in self.ballots.has_ballots:
            if not self.combis:
                self.ui.button1.setEnabled(False)
                self.ui.button2.setEnabled(False)
                self.ui.button_equal.setEnabled(False)
                self.show_results()
                sys.exit(0)
            else:
                p1,p2=self.combis.pop()
        self.ui.prenom1.setText(p1)
        self.ui.prenom2.setText(p2)
    def show_results(self):
        self.show()
        res_win=ResultWindow()
        res_win.show_results(self.prenoms)
    def count_ballot_and_update(self,win):
        if win == 0:
            b=(str(self.ui.prenom1.text()),"=",str(self.ui.prenom2.text()),1)
        elif win==1:
            b=(str(self.ui.prenom1.text()),">",str(self.ui.prenom2.text()),1)
        elif win==2:
            b=(str(self.ui.prenom2.text()),">",str(self.ui.prenom1.text()),1)
        self.ballots.add(b)
        self.ballots.save()
        self.update()