def _display_questfinal(self):
        if not self._le2mserv.gestionnaire_base.is_created():
            QtGui.QMessageBox.warning(
                self._le2mserv.gestionnaire_graphique.screen,
                le2mtrans(u"Warning"),
                le2mtrans(u"There is no database yet. You first need to " u"load at least one part."),
            )
            return
        if not hasattr(self, "_tous"):
            QtGui.QMessageBox.warning(
                self._le2mserv.gestionnaire_graphique.screen,
                le2mtrans(u"Warning"),
                trans_TC(u"TeamCommunication has to be run before to " u"start this questionnaire"),
            )
            return

        confirmation = QtGui.QMessageBox.question(
            self._le2mserv.gestionnaire_graphique.screen,
            le2mtrans(u"Confirmation"),
            le2mtrans(u"Start the final questionnaire?"),
            QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Ok,
        )
        if confirmation != QtGui.QMessageBox.Ok:
            return

        yield (
            self._le2mserv.gestionnaire_experience.run_step(
                trans_TC(u"Final questionnaire"), self._tous, "display_questfinal"
            )
        )
 def _configure(self):
     """
     To make changes in the parameters
     :return:
     """
     dconfig = DConfiguration(self._le2mserv.gestionnaire_graphique.screen)
     if dconfig.exec_():
         pms.TEMPS_PARTIE, pms.TREATMENT, pms.GRILLES = dconfig.get_config()
         self._le2mserv.gestionnaire_graphique.infoserv(
             [
                 trans_TC(u"Part time: {}").format(pms.TEMPS_PARTIE),
                 trans_TC(u"Treatment: {}").format(pms.get_treatment(pms.TREATMENT)),
                 trans_TC(u"Grids: {}").format(len(pms.GRILLES)),
             ]
         )
    def __init__(self, defered, automatique, parent):
        super(DQuestionDictator, self).__init__(parent)

        self._defered = defered
        self._automatique = automatique

        layout = QtGui.QVBoxLayout(self)

        self._widPrediction = WSpinbox(
            label=texts_TC.get_text_predictiondictator(), minimum=0, maximum=10,
            automatique=self._automatique, parent=self)
        layout.addWidget(self._widPrediction)

        buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
        buttons.accepted.connect(self._accept)
        layout.addWidget(buttons)

        if self._automatique:
            self._timer = QtCore.QTimer()
            self._timer.timeout.connect(
                buttons.button(QtGui.QDialogButtonBox.Ok).click)
            self._timer.start(7000)

        self.setWindowTitle(trans_TC(u"Prediction"))
        self.adjustSize()
        self.setFixedSize(self.size())
 def _addto_finalpayoffs(self):
     if not self._gains:
         return
     for k, v in self._gains.viewitems():
         k.get_part("base").paiementFinal += float(v)
     self._le2mserv.gestionnaire_base.enregistrer()
     self._le2mserv.gestionnaire_graphique.infoserv(
         trans_TC(u"TC payoffs added to final payoffs"), fg="red")
 def _display_onremotes2(self):
     confirm = self._le2mserv.gestionnaire_graphique.question(
         trans_TC(u"Display payoff on remotes' screen?"))
     if not confirm:
         return
     self._le2mserv.gestionnaire_graphique.set_waitmode(self._players)
     yield (self._le2mserv.gestionnaire_experience.run_func(
         self._players, "display_payoffs", self._sequence))
 def _send_message(self, msg):
     try:
         yield (self._tcremote.send_message(msg))
     except Exception as e:
         logger.error(e.message)
     self.add_message(trans_TC(u"You:") + u" {}".format(msg))
     self.widchat.clear_writespace()
     defer.returnValue(None)
    def _display_payoffs(self):
        if self._currentsequence >= 0:
            sequence, ok = QtGui.QInputDialog.getInt(
                self._le2mserv.gestionnaire_graphique.screen,
                trans_TC(u"Sequence choice"),
                trans_TC(u"Choose the sequence"),
                min=0,
                max=self._currentsequence,
                step=1,
                value=0,
            )
            if ok:
                self._ecran_gains = DGains(self._le2mserv, sequence)
                self._ecran_gains.show()

        else:  # no sequence has been run
            return
    def __init__(self, le2mserv):
        self._le2mserv = le2mserv

        # creation of the menu (will be placed in the "part" menu on the
        # server screen
        actions = OrderedDict()
        actions[trans_TC(u"Configure")] = self._configure
        actions[
            trans_TC(u"Display the parameters")
        ] = lambda _: self._le2mserv.gestionnaire_graphique.display_information2(
            utiltools.get_module_info(pms), trans_TC(u"Parameters")
        )
        actions[trans_TC(u"Start")] = lambda _: self._demarrer()
        actions[trans_TC(u"Form groups for the dictator game")] = self._prepare_dictator
        actions[trans_TC(u"Display the question after the dictator game")] = lambda _: self._run_questionapresdictator()
        actions[trans_TC(u"Display payoffs")] = self._display_payoffs

        self._le2mserv.gestionnaire_graphique.add_topartmenu(u"Team Communication", actions)

        # ajout d'onglets ------------------------------------------------------
        self._onglet_looks = Wlist()
        self._onglet_essais = Wlist()
        self._onglet_messages = Wlist()
        self._le2mserv.gestionnaire_graphique.screen.ui.onglets.addTab(self._onglet_looks, trans_TC(u"Looks of grids"))
        self._le2mserv.gestionnaire_graphique.screen.ui.onglets.addTab(self._onglet_essais, trans_TC(u"Tries"))
        self._le2mserv.gestionnaire_graphique.screen.ui.onglets.addTab(self._onglet_messages, trans_TC(u"Messages"))

        # final question
        self._le2mserv.gestionnaire_graphique.screen.action_finalquest.triggered.disconnect()
        self._le2mserv.gestionnaire_graphique.screen.action_finalquest.triggered.connect(
            lambda _: self._display_questfinal()
        )

        self._currentsequence = -1
def _get_html(numero, grille):
    html = "<p>" + trans_TC("Grid") + " {}<br />".format(numero)
    html += "<table style='width: 150px;'>"
    for l in grille:
        html += "<tr>"
        for c in l:
            html += "<td style='width: 15px;'>{}</td>".format(c)
        html += "</tr>"
    html += "</table>"
    return html
 def __init__(self, parent):
     super(WDisplayer, self).__init__(parent)
     self.ui = TC_widDisplayer.Ui_Form()
     self.ui.setupUi(self)
     self.ui.label.setText(
         trans_TC(u"Click on a number\nto see the corresponding grid"))
     font_grille = QtGui.QFont()
     font_grille.setPointSize(14)
     font_grille.setBold(True)
     self.ui.label.setFont(font_grille)
    def _accept(self):
        try:
            self._timer.stop()
        except AttributeError:
            pass

        if not self._automatique:
            confirm = QtGui.QMessageBox.question(
                self, u"Confirmation", trans_TC(u"Do you confirm your choice?"),
                QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)
            if confirm != QtGui.QMessageBox.Yes:
                return
        dec = self._widPrediction.get_value()
        logger.info(u"Send back {}".format(dec))
        self._defered.callback(dec)
        self.accept()
 def _accept(self):
     try:
         self._timer.stop()
     except AttributeError:
         pass
     rep = {"TC_confidence": self._widanswers.get_value(),
            "TC_jobsatisfaction": self._widjobsatisfaction.get_value()}
     if pms.TREATMENT == pms.get_treatment("avec_communication"):
         rep["TC_infosatisfaction"] = self._widinfosatisfaction.get_value()
     if not self._automatique:
         confirm = QtGui.QMessageBox.question(
             self, u"Confirmation", trans_TC(u"Do you confirm your answers?"),
             QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)
         if confirm != QtGui.QMessageBox.Yes:
             return
     logger.info(u"Renvoi {}".format(rep))
     self.accept()
     self._defered.callback(rep)
    def __init__(self, defered, automatique, parent, nbanswers):
        super(DAdditionnalquestions, self).__init__(parent)

        self._defered = defered
        self._automatique = automatique
        self._nbanswers = nbanswers

        layout = QtGui.QVBoxLayout(self)

        self._widanswers = WSpinbox(
            label=texts_TC.get_text_reponses(nbanswers),
            minimum=0, maximum=nbanswers, automatique=self._automatique,
            parent=self)
        layout.addWidget(self._widanswers)

        if pms.TREATMENT == pms.get_treatment("avec_communication"):
            self._widinfosatisfaction = WSlider(
                label=texts_TC.get_text_infosatisfaction(),
                minimum=1, maximum=7, automatique=self._automatique,
                parent=self)
            layout.addWidget(self._widinfosatisfaction)

        self._widjobsatisfaction = WSlider(
            label=texts_TC.get_text_jobsatisfaction(),
            minimum=1, maximum=7, automatique=self._automatique,
            parent=self)
        layout.addWidget(self._widjobsatisfaction)

        buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
        buttons.accepted.connect(self._accept)
        layout.addWidget(buttons)

        if self._automatique:
            self._timer = QtCore.QTimer()
            self._timer.timeout.connect(
                buttons.button(QtGui.QDialogButtonBox.Ok).click)
            self._timer.start(7000)

        self.setWindowTitle(trans_TC(u"Additionnal questions"))
        self.adjustSize()
        self.setFixedSize(self.size())
    def __init__(self, defered, automatique, parent):
        DQuestFinal.__init__(self, defered, automatique, parent)

        disciplines = [v for k, v in sorted(texts_TC.DISCIPLINES.viewitems())]
        disciplines.insert(0, le2mtrans(u"Choose"))
        disciplines.append(le2mtrans(u"Not in the list above"))
        self._study_topic.ui.comboBox.clear()
        self._study_topic.ui.comboBox.addItems(disciplines)

        niveaux = [v for k, v in sorted(texts_TC.ETUDES_ANNEES.viewitems())]
        niveaux.insert(0, le2mtrans(u"Choose"))
        niveaux.append(le2mtrans(u"Not in the list above"))
        self._study_level.ui.comboBox.clear()
        self._study_level.ui.comboBox.addItems(niveaux)

        self._religion_place.setVisible(False)
        self._religion_place.ui.comboBox.setCurrentIndex(1)
        self._religion_name.setVisible(False)
        self._religion_name.ui.comboBox.setCurrentIndex(1)
        self._religion_belief.setVisible(False)
        self._religion_belief.ui.comboBox.setCurrentIndex(1)

        residence = [v for k, v in sorted(texts_TC.COUNTRY_RESIDENCE.viewitems())]
        residence.insert(0, le2mtrans(u"Choose"))
        residence.append(le2mtrans(u"Not in the list above"))
        self._residence = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Country of residence"), items=residence)
        self._gridlayout.addWidget(self._residence, 0, 2)

        # profession
        professions = [v for k, v in sorted(texts_TC.PROFESSIONS.viewitems())]
        professions.insert(0, le2mtrans(u"Choose"))
        professions.append(le2mtrans(u"Not in the list above"))
        self._profession = WCombo(
            label=trans_TC(u"Your profession"), parent=self,
            automatique=self._automatique, items=professions)
        self._gridlayout.addWidget(self._profession, 2, 3)
        self._profession.setEnabled(False)
        self._study.ui.radioButton_1.toggled.connect(
            lambda _: self._enable_widgets(self._study.get_checkedbutton()==1,
                                           self._profession))

        # language skills
        skills = [v for k, v in sorted(texts_TC.LANGUAGE_SKILLS.viewitems())]
        skills.insert(0, le2mtrans(u"Choose"))

        # luxembourgish
        self._luxembourgish_speak = WCombo(
            parent=self, automatique=self._automatique,
            label=u"<strong>" + trans_TC(u"Luxembourgish") + u"</strong>  " +
                  trans_TC(u"Speak"), items=skills)
        self._gridlayout.addWidget(self._luxembourgish_speak, 7, 0)
        self._luxembourgish_understrand = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Understand"), items=skills)
        self._gridlayout.addWidget(self._luxembourgish_understrand, 7, 1)
        self._luxembourgish_read = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Read"), items=skills)
        self._gridlayout.addWidget(self._luxembourgish_read, 7, 2)
        self._luxembourgish_write = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Write"), items=skills)
        self._gridlayout.addWidget(self._luxembourgish_write, 7, 3)

        # french
        self._french_speak = WCombo(
            parent=self, automatique=self._automatique,
            label=u"<strong>" + trans_TC(u"French") + u"</strong>  " +
                  trans_TC(u"Speak"), items=skills)
        self._gridlayout.addWidget(self._french_speak, 8, 0)
        self._french_understrand = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Understand"), items=skills)
        self._gridlayout.addWidget(self._french_understrand, 8, 1)
        self._french_read = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Read"), items=skills)
        self._gridlayout.addWidget(self._french_read, 8, 2)
        self._french_write = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Write"), items=skills)
        self._gridlayout.addWidget(self._french_write, 8, 3)

        # german
        self._german_speak = WCombo(
            parent=self, automatique=self._automatique,
            label=u"<strong>" + trans_TC(u"German") + u"</strong>  " +
                  trans_TC(u"Speak"), items=skills)
        self._gridlayout.addWidget(self._german_speak, 9, 0)
        self._german_understrand = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Understand"), items=skills)
        self._gridlayout.addWidget(self._german_understrand, 9, 1)
        self._german_read = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Read"), items=skills)
        self._gridlayout.addWidget(self._german_read, 9, 2)
        self._german_write = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Write"), items=skills)
        self._gridlayout.addWidget(self._german_write, 9, 3)

        # english
        self._english_speak = WCombo(
            parent=self, automatique=self._automatique,
            label=u"<strong>" + trans_TC(u"English") + u"</strong>  " +
                  trans_TC(u"Speak"), items=skills)
        self._gridlayout.addWidget(self._english_speak, 10, 0)
        self._english_understrand = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Understand"), items=skills)
        self._gridlayout.addWidget(self._english_understrand, 10, 1)
        self._english_read = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Read"), items=skills)
        self._gridlayout.addWidget(self._english_read, 10, 2)
        self._english_write = WCombo(
            parent=self, automatique=self._automatique,
            label=trans_TC(u"Write"), items=skills)
        self._gridlayout.addWidget(self._english_write, 10, 3)

        self.setMinimumSize(0, 0)
        self.setMaximumSize(16777215, 16777215)
        self.adjustSize()
        self.setFixedSize(self.size())
    def _demarrer(self):
        # checks of consistency ================================================
        if divmod(len(self._le2mserv.gestionnaire_joueurs.get_players()), pms.TAILLE_GROUPES)[1] != 0:
            self._le2mserv.gestionnaire_graphique.display_error(
                trans_TC(u"Impossible to form groups of size {} with {} " u"players").format(
                    pms.TAILLE_GROUPES, self._le2mserv.gestionnaire_joueurs.nombre_joueurs
                )
            )
            return
        if not pms.GRILLES:
            self._le2mserv.gestionnaire_graphique.display_error(
                trans_TC(u"Grids must be loaded before to start the part")
            )
            return

        # confirmation start
        confirmation = self._le2mserv.gestionnaire_graphique.question(trans_TC(u"Start TeamCommunication?"))
        if not confirmation:
            return

        # init part ============================================================
        if not self._le2mserv.gestionnaire_experience.has_part("TeamCommunication"):  # init part
            yield (self._le2mserv.gestionnaire_experience.init_part("TeamCommunication", "PartieTC", "RemoteTC", pms))
            self._tous = self._le2mserv.gestionnaire_joueurs.get_players("TeamCommunication")
        else:  # uniquement affichage
            self._le2mserv.gestionnaire_graphique.infoserv(None)
            self._le2mserv.gestionnaire_graphique.infoserv("TeamCommunication".upper(), fg="white", bg="blue")
            self._le2mserv.gestionnaire_graphique.infoclt(None)
            self._le2mserv.gestionnaire_graphique.infoclt("TeamCommunication".upper(), fg="white", bg="blue")
            self._le2mserv.gestionnaire_graphique.infoserv(
                utili18n.le2mtrans(u"Start time: {st}").format(st=strftime("%H:%M:%S"))
            )

        self._currentsequence += 1
        self._le2mserv.gestionnaire_graphique.infoserv(u"Sequence {}".format(self._currentsequence))
        self.onglet_looks.clear()
        self.onglet_essais.clear()
        self.onglet_messages.clear()

        # groups formation
        if self._currentsequence == 0:
            try:
                self._le2mserv.gestionnaire_groupes.former_groupes(
                    liste_joueurs=self._le2mserv.gestionnaire_joueurs.get_players(),
                    taille_groupes=pms.TAILLE_GROUPES,
                    roundrobin=True,
                )
            except ValueError as e:
                self._le2mserv.gestionnaire_graphique.display_error(e.message)
                return
        else:
            self._le2mserv.gestionnaire_groupes.roundrobinnext()

        # configuration of players and remote
        yield (
            self._le2mserv.gestionnaire_experience.run_step(
                u"Configure", self._tous, "configure", self, self._currentsequence
            )
        )
        for j in self._tous:
            j.othergroupmembers = [
                k.get_part("TeamCommunication")
                for k in self._le2mserv.gestionnaire_groupes.get_autres_membres_groupe(j.joueur)
            ]

        # Start of repetitions =================================================
        for period in xrange(1 if pms.NOMBRE_PERIODES else 0, pms.NOMBRE_PERIODES + 1):

            if self._le2mserv.gestionnaire_experience.stop_repetitions:
                break

            # init period
            self._le2mserv.gestionnaire_graphique.infoserv([None, u"Period {}".format(period)])
            self._le2mserv.gestionnaire_graphique.infoclt([None, u"Period {}".format(period)], fg="white", bg="gray")
            yield (self._le2mserv.gestionnaire_experience.run_func(self._tous, "newperiod", period))

            # decision
            yield (self._le2mserv.gestionnaire_experience.run_step(u"Decision", self._tous, "display_decision"))

            # computation of good answers in each group
            self._le2mserv.gestionnaire_graphique.infoserv(u"Good answers")
            for g, m in self._le2mserv.gestionnaire_groupes.get_groupes("TeamCommunication").viewitems():
                nbbonnesrep = sum([j.currentperiod.TC_goodanswers for j in m])
                for j in m:
                    j.currentperiod.TC_goodanswers_group = nbbonnesrep
                self._le2mserv.gestionnaire_graphique.infoserv(u"G{}: {}".format(g.split("_")[2], nbbonnesrep))

            # period payoffs
            self._le2mserv.gestionnaire_experience.compute_periodpayoffs("TeamCommunication")

            # questions about self confidence and satisfaction
            yield (
                self._le2mserv.gestionnaire_experience.run_step(
                    trans_TC(u"Additionnal questions"), self._tous, "display_additionnalquestions"
                )
            )

            # period summary
            yield (self._le2mserv.gestionnaire_experience.run_step(trans_TC(u"Summary"), self._tous, "display_summary"))

        # End of part ==========================================================
        yield (self._le2mserv.gestionnaire_experience.finalize_part("TeamCommunication"))