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())
class GuiDecision(QtGui.QDialog): 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()) @defer.inlineCallbacks 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) def reject(self): pass def _accept(self): answers = self._widgrilles.get_values() logger.debug(u"Renvoi {}".format(answers)) self._defered.callback(answers) self.accept() @defer.inlineCallbacks 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 add_message(self, msg): self.widchat.add_text(msg)