def get_text_explanation():
    txt = trans_TC(u"To display a grid, click on its number.")
    txt += trans_TC(u"<br />To indicate the number of '1' included in the grid, "
                    u"enter this number directly in the box under its number")

    if pms.TREATMENT == pms.get_treatment("avec_communication"):
        txt += trans_TC(u"<br />The chat window allows you to communicate "
                        u"freely with other group players.").format(
            pms.TEMPS_PARTIE.minute)
    return txt
 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 remote_display_additionnalquestions(self, nbanswers):
     logger.info(u"{} display_additionnalquestions".format(
         self._le2mclt.uid))
     if self._le2mclt.simulation:
         rep = {"TC_confidence": random.randint(0, nbanswers),
                "TC_jobsatisfaction": random.randint(0, 7)}
         if pms.TREATMENT == pms.get_treatment("avec_communication"):
             rep["TC_infosatisfaction"] = random.randint(0, 7)
         logger.info(u"{} renvoi {}".format(self._le2mclt.uid, rep))
         return rep
     else:
         defered = defer.Deferred()
         ecran_additionnalquestions = DAdditionnalquestions(
             defered, self._le2mclt.automatique, self._le2mclt.screen,
             nbanswers)
         ecran_additionnalquestions.show()
         return defered
    def __init__(self, defered, automatique, parent, tcremote):
        super(GuiDecision, self).__init__(parent)

        self._defered = defered
        self._automatique = automatique
        self._tcremote = tcremote

        layout = QtGui.QVBoxLayout(self)

        self._widexplication = WExplication(
            text=texts_TC.get_text_explanation(), parent=self, size=(650, 80))
        layout.addWidget(self._widexplication)

        self._widcompterebours = WCompterebours(
            parent=self, temps=pms.TEMPS_PARTIE, actionfin=self._accept)
        layout.addWidget(self._widcompterebours)

        self._widdisplayer = WDisplayer(parent=self)
        self._widdisplayer.ui.label.setFixedSize(400, 300)
        self._widgrilles = WGrilles(
            parent=self, displayer=self._widdisplayer.ui.label,
            tcremote=self._tcremote)
        self._widgrilles.setFixedSize(1250, 350)
        layout.addWidget(self._widgrilles)

        hlayout = QtGui.QHBoxLayout()
        hlayout.addWidget(self._widdisplayer)
        hlayout.addSpacerItem(QtGui.QSpacerItem(
            20, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding))
        self.widchat = WChat(parent=self, action_send=self._send_message)
        self.widchat.setStyleSheet("border: 1px solid gray;")
        hlayout.addWidget(self.widchat)
        layout.addLayout(hlayout)

        if pms.TREATMENT == pms.get_treatment("sans_communication"):
            self.widchat.setVisible(False)

        if self._automatique:
            self._timer = QtCore.QTimer()
            self._timer.timeout.connect(self._handle_automatic)
            self._timer.start(random.randint(1000, 15000))

        self.setWindowTitle(u"Décisions")
        self.adjustSize()
        self.setFixedSize(self.size())
 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 _handle_automatic(self):
        if not self._widcompterebours.compterebours.isRunning():
            self._timer.stop()
        grille = random.randint(0, 99)
        try:
            yield (self._tcremote.send_look(grille))
        except Exception as e:
            logger.error(e.message)
        if random.random() >= 0.25:  # on fait un essai
            if random.randint(0, 1):  # on donne la bonne réponse
                nbun = pms.GRILLES[grille]["count"]
            else:
                nbun = random.randint(0, 100)
            self._widgrilles.set_value(grille, nbun)
            try:
                yield (self._tcremote.send_try(grille, nbun))
            except Exception as e:
                logger.error(e.message)

        if pms.TREATMENT == pms.get_treatment("avec_communication"):
            if random.random() >= 0.60:  # on envoit un message
                self.widchat.write(u"Message automatique")
                self.widchat.ui.pushButton.click()
        defer.returnValue(None)