class GuiRecapitulatif(QtGui.QDialog): """ Dialog for the summary, for repeated game or one-shot. If ecran_historique is set it replaces the default GuiHistorique """ def __init__(self, remote, defered, automatique, parent, period, historique, summary_text, triangle_transactions, star_transactions): """ :param defered: :param automatique: :param parent: :param period: :param historique: :param summary_text: :param history_screen: :param size_histo: the size of the history table. The width of the explanation area will be the same than the width of the history table :return: """ super(GuiRecapitulatif, self).__init__(parent) self._remote = remote self._defered = defered self._automatique = automatique layout = QtGui.QVBoxLayout(self) # period label and history button -------------------------------------- self.ecran_historique = GuiHistorique( self, historique, size=SIZE_HISTO) layout_period = QtGui.QHBoxLayout() label_period = QtGui.QLabel(le2mtrans("Period") + " {}".format(period)) layout_period.addWidget(label_period) layout_period.addSpacerItem( QtGui.QSpacerItem(20, 5, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)) button_history = QtGui.QPushButton(le2mtrans("History")) button_history.clicked.connect(self.ecran_historique.show) layout_period.addWidget(button_history) layout.addLayout(layout_period) # timer self._compte_rebours = WCompterebours( parent=self, temps=pms.SUMMARY_TIME, actionfin=self._display_warning) layout.addWidget(self._compte_rebours) # explanation zone ----------------------------------------------------- self.widexplication = WExplication(text=summary_text, parent=self, size=(SIZE_HISTO[0], 80)) layout.addWidget(self.widexplication) # transactions --------------------------------------------------------- try: max_triangle_price = max(triangle_transactions.MRI_trans_price) except ValueError: # no transaction max_triangle_price = 1 try: max_star_price = max(star_transactions.MRI_trans_price) except ValueError: max_star_price = 1 max_price = max(max_triangle_price, max_star_price) transactions_layout = QtGui.QGridLayout() layout.addLayout(transactions_layout) # triangle --- triangle_label = QtGui.QLabel(trans_MRI(u"Triangle")) triangle_label.setStyleSheet("font-weight: bold;") transactions_layout.addWidget(triangle_label, 0, 0) self._triangle_transaction_zone = TransactionZone(zone_size=(450, 250)) try: for i, item in triangle_transactions.iterrows(): price = item.MRI_trans_price buyer = item.MRI_trans_buyer seller = item.MRI_trans_seller implied, buyer_or_seller = False, None if buyer == self._remote.le2mclt.uid or \ seller == self._remote.le2mclt.uid: implied = True buyer_or_seller = pms.BUYER if \ buyer == self._remote.le2mclt.uid else pms.SELLER color = "blue" if implied else "black" self._triangle_transaction_zone.add_transaction( price, buyer_or_seller, color) except ValueError: # no transactions pass transactions_layout.addWidget(self._triangle_transaction_zone, 1, 0) self._triangle_transactions_graph = GraphicalZone( triangle_transactions, max_price, pms.TRIANGLE, zone_size=(450, 250)) transactions_layout.addWidget(self._triangle_transactions_graph, 2, 0) # star --- star_label = QtGui.QLabel(trans_MRI(u"Star")) star_label.setStyleSheet("font-weight: bold;") transactions_layout.addWidget(star_label, 0, 2) self._star_transaction_zone = TransactionZone(zone_size=(450, 250)) try: for i, item in star_transactions.iterrows(): price = item.MRI_trans_price buyer = item.MRI_trans_buyer seller = item.MRI_trans_seller implied, buyer_or_seller = False, None if buyer == self._remote.le2mclt.uid or \ seller == self._remote.le2mclt.uid: implied = True buyer_or_seller = pms.BUYER if \ buyer == self._remote.le2mclt.uid else pms.SELLER color = "blue" if implied else "black" self._star_transaction_zone.add_transaction( price, buyer_or_seller, color) except ValueError: # no transactions pass transactions_layout.addWidget(self._star_transaction_zone, 1, 2) self._star_transactions_graph = GraphicalZone( star_transactions, max_price, pms.STAR, zone_size=(450, 250)) transactions_layout.addWidget(self._star_transactions_graph, 2, 2) separator = QtGui.QFrame() separator.setFrameShape(QtGui.QFrame.VLine) transactions_layout.addWidget( separator, 0, 1, transactions_layout.rowCount(), 1) # history table -------------------------------------------------------- # in this screen we only keep the header and the last line of the # history histo_recap = [historique[0], historique[-1]] self.tablemodel = TableModelHistorique(histo_recap) self.widtableview = WTableview(parent=self, tablemodel=self.tablemodel, size=(SIZE_HISTO[0], 100)) self.widtableview.ui.tableView.verticalHeader().setResizeMode( QtGui.QHeaderView.Stretch) layout.addWidget(self.widtableview) buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok) buttons.accepted.connect(self._accept) layout.addWidget(buttons) # automatique if self._automatique: self._timer_automatique = QtCore.QTimer() self._timer_automatique.timeout.connect( buttons.button(QtGui.QDialogButtonBox.Ok).click) self._timer_automatique.start(7000) # taille et titre self.setWindowTitle(le2mtrans(u"Summary")) # self.adjustSize() # self.setFixedSize(self.size()) def _accept(self): """ :return: """ try: self._timer_automatique.stop() except AttributeError: pass try: self._compte_rebours.stop() except AttributeError: pass logger.info(u"callback: Ok summary") self._defered.callback(1) self.accept() def reject(self): pass def _display_warning(self): self._compte_rebours.setStyleSheet("color: red;")
class DEffort(QtGui.QDialog): def __init__(self, defered, automatique, parent, periode, historique, grilles): QtGui.QDialog.__init__(self, parent) self._defered = defered self._automatique = automatique self._grilles = grilles self._historique = GuiHistorique(self, historique, size=(HISTO_WIDTH, 500)) layout = QtGui.QVBoxLayout() self.setLayout(layout) # period and history button wperiod = WPeriod(period=periode, ecran_historique=self._historique, parent=self) layout.addWidget(wperiod) explanation = WExplication( parent=self, text=texts_PGGS.get_text_explanation_grilles(), size=(600, 100)) layout.addWidget(explanation) self._countdown = WCompterebours(self, temps=pms.TIME_TO_FILL_GRILLES, actionfin=self._accept) layout.addWidget(self._countdown) grid_layout = QtGui.QGridLayout() layout.addLayout(grid_layout) self._widgets_grilles = list() current_line = 0 for i, g in enumerate(self._grilles): self._widgets_grilles.append(WGrid(g, self._automatique)) grid_layout.addWidget(self._widgets_grilles[-1], current_line, i - current_line * pms.NB_GRILLES_PER_LINE) if i > 0 and (i + 1) % pms.NB_GRILLES_PER_LINE == 0: current_line += 1 buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok) buttons.accepted.connect(self._accept) layout.addWidget(buttons) self.adjustSize() self.setFixedSize(self.size()) self.setWindowTitle(trans_PGGS(u"Tasks")) def reject(self): pass def _accept(self): if self._countdown.is_running(): confirmation = QtGui.QMessageBox.question( self, "Confirmation", trans_PGGS( u"Do you want to quit before the end of the timer?"), QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Yes) if confirmation != QtGui.QMessageBox.Yes: return else: self._countdown.stop() answers = sum([int(g.is_ok()) for g in self._widgets_grilles]) if not self._automatique: QtGui.QMessageBox.information( self, "Information", trans_PGGS(u"You've found {} grids.").format(answers)) logger.info("send back {}".format(answers)) self.accept() self._defered.callback(answers)