class TrackerWindow(QMainWindow): BT_SIZE = QSize(30, 30) MARGIN = QMargins(5, 5, 5, 5) PADDING = 10 def __init__(self, on_close): super(TrackerWindow, self).__init__(None) self.on_close = on_close self.live_speed = LiveSpeed(parent=self) self.bt_retour = PixmapButton(parent=self) self.init_widget() def init_widget(self): central_widget = QWidget(self) central_widget.setContentsMargins(self.MARGIN) hbox = QHBoxLayout() hbox.addWidget(self.live_speed) self.bt_retour.setFixedSize(self.BT_SIZE) self.bt_retour.setStyleSheet(button_stylesheet) self.bt_retour.clicked.connect(self.new_main_window) self.bt_retour.addImage("commun/assets/images/fleche_precedent.png") hbox.addWidget(self.bt_retour) central_widget.setLayout(hbox) self.setCentralWidget(central_widget) @staticmethod def new_main_window(): app.create_main_window() def closeEvent(self, event): self.on_close() def draw_fond(self, p): """ Dessine un rectangle de la taille du bloc :param p: parametre de dessin """ draw_rectangle(p, self.PADDING, self.PADDING, self.width() - self.PADDING * 2, self.height() - self.PADDING * 2, color_bleu_gris) def paintEvent(self, event): p = QPainter() p.begin(self) self.draw(p) p.end() def draw(self, p): self.draw_fond(p)
def create_line_raison(self, raison, first_type): """ S'occupe de créer une ligne associé a une raison :return: Le layout de la ligne """ hbox = QHBoxLayout() # On met le label et la croix en couleur en fonction du type if raison.type == "Prévu": label_stylesheet = blue_title_label_stylesheet bt_cross_stylesheet = button_blue_cross_stylesheet elif raison.type == "Imprévu": label_stylesheet = red_title_label_stylesheet bt_cross_stylesheet = button_red_cross_stylesheet else: label_stylesheet = gray_title_label_stylesheet bt_cross_stylesheet = button_gray_cross_stylesheet # On regarde si le type est égale au first type pour ajouter le radiobutton si besoin if raison.type == first_type and raison.type != "Nettoyage": radio_bt = RadioButton(parent=self) radio_bt.is_selected = raison.primaire == 1 radio_bt.setStyleSheet(bt_cross_stylesheet) self.radio_button_manager.add(radio_bt) radio_bt.setFixedSize(self.HEIGHT_LINE, self.HEIGHT_LINE) hbox.addWidget(radio_bt, alignment=Qt.AlignVCenter) # Création du label type type_label = QLabel(raison.type) type_label.setStyleSheet(label_stylesheet) type_label.setAlignment(Qt.AlignCenter) type_label.setFixedWidth(self.WIDTH_TYPE) type_label.setFixedHeight(self.HEIGHT_LINE) # On ajoute le label au layout hbox.addWidget(type_label) # Création du label raison raison_label = QLabel(raison.raison) # On met le label en couleur en fonction du type et on définit la largeur raison_label.setStyleSheet(label_stylesheet) raison_label.setFixedHeight(self.HEIGHT_LINE) # On ajoute le label au layout hbox.addWidget(raison_label) # On crée un bouton pour supprimer la ligne bt_cross = PixmapButton(parent=self) bt_cross.setFixedSize(self.HEIGHT_LINE, self.HEIGHT_LINE) bt_cross.addImage("commun/assets/images/white_cross.png") bt_cross.setStyleSheet(bt_cross_stylesheet) bt_cross.clicked.connect( lambda: self.delete_line_raison(raison.raison)) # On ajoute le bouton au layout hbox.addWidget(bt_cross) hbox.setSpacing(0) return hbox
def init_widget(self): self.hbox.setContentsMargins(0, 0, 0, 0) self.hbox.setSpacing(0) bt_acceuil = PixmapButton("Production") bt_acceuil.setFixedWidth(self.WIDTH_BT) self.list_bt["prod"] = bt_acceuil bt_acceuil.clicked.connect(lambda: self.on_click("prod")) self.hbox.addWidget(bt_acceuil) self.bt_stat.setFixedWidth(self.WIDTH_BT) self.bt_stat.hide() self.list_bt["chart_stat"] = self.bt_stat self.bt_stat.clicked.connect(lambda: self.on_click("chart_stat")) self.hbox.addWidget(self.bt_stat) self.bt_rapport.setFixedWidth(self.WIDTH_BT) self.bt_rapport.hide() self.list_bt["rapport"] = self.bt_rapport self.bt_rapport.clicked.connect(lambda: self.on_click("rapport")) self.hbox.addWidget(self.bt_rapport) # self.bt_team_gestion.setFixedWidth(self.WIDTH_BT) # self.bt_team_gestion.hide() # self.list_bt["team_gestion"] = self.bt_team_gestion # self.bt_team_gestion.clicked.connect(lambda: self.on_click("team_gestion")) # self.hbox.addWidget(self.bt_team_gestion) self.hbox.addStretch(1) self.label_user.setStyleSheet(white_16_label_stylesheet) self.hbox.addWidget(self.label_user) bt_user = PixmapButton(parent=self) bt_user.addImage("commun/assets/images/user_icon.png") bt_user.setStyleSheet(button_green_stylesheet) bt_user.setFixedSize(self.height(), self.height()) bt_user.clicked.connect(self.on_click_user) self.hbox.addWidget(bt_user) self.setLayout(self.hbox)
class RapportMenu(MondonWidget): PIXMAPBUTTON_SIZE = QSize(40, 40) BUTTON_HEIGHT = 40 BUTTON_WIDTH = 100 PAGE_W = 770 PAGE_H = 1100 MINIMUN_WIDTH_LABEL = 350 def __init__(self, parent=None): super(RapportMenu, self).__init__(parent=parent) self.background_color = color_bleu_gris self.bt_impression = PixmapButton(parent=self) self.bt_save = PixmapButton(parent=self) self.bt_jour_plus = PixmapButton(parent=self) self.bt_jour_moins = PixmapButton(parent=self) self.bt_live = QPushButton("Aujourd'hui") self.label_date = QLabel() self.rapport = Rapport(parent=self) self.rapport.hide() self.init_button() self.init_widget() self.update_button() self.update_label() def on_settings_changed(self, prev_live, prev_day_ago, prev_zoom): self.update_button() self.update_label() def init_widget(self): menu_hbox = QHBoxLayout() left_hbox = QHBoxLayout() left_hbox.addWidget(self.bt_live) left_hbox.addStretch(1) menu_hbox.addLayout(left_hbox) date_hbox = QHBoxLayout() date_hbox.addStretch(1) date_hbox.addWidget(self.bt_jour_moins) self.label_date.setStyleSheet(white_22_label_stylesheet) date_hbox.addWidget(self.label_date) date_hbox.addWidget(self.bt_jour_plus) date_hbox.addStretch(1) menu_hbox.addLayout(date_hbox) right_hbox = QHBoxLayout() right_hbox.addStretch(1) right_hbox.addWidget(self.bt_save) right_hbox.addWidget(self.bt_impression) menu_hbox.addLayout(right_hbox) self.setLayout(menu_hbox) def init_button(self): # Bouton sauvegarder self.bt_save.clicked.connect(self.get_pdf) self.bt_save.setStyleSheet(button_stylesheet) self.bt_save.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_save.setContentsMargins(8) self.bt_save.addImage("commun/assets/images/save_as.png") # Bouton impression self.bt_impression.clicked.connect(self.impression) self.bt_impression.setStyleSheet(button_stylesheet) self.bt_impression.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_impression.addImage("commun/assets/images/impression.png") # Bouton jour plus self.bt_jour_plus.clicked.connect(self.jour_plus) self.bt_jour_plus.setStyleSheet(button_stylesheet) self.bt_jour_plus.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_jour_plus.addImage("commun/assets/images/fleche_suivant.png") # Bouton jour moins self.bt_jour_moins.clicked.connect(self.jour_moins) self.bt_jour_moins.setStyleSheet(button_stylesheet) self.bt_jour_moins.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_jour_moins.addImage( "commun/assets/images/fleche_precedent.png") # Bouton live self.bt_live.clicked.connect(self.live) self.bt_live.setFixedSize(self.BUTTON_WIDTH, self.BUTTON_HEIGHT) self.bt_live.setStyleSheet(button_little_stylesheet) def update_button(self): self.bt_jour_plus.setEnabled(settings_store.day_ago > 0) self.bt_live.setEnabled(settings_store.day_ago > 0) def update_label(self): ts = timestamp_at_day_ago(settings_store.day_ago) date = timestamp_to_date(ts).capitalize() self.label_date.setMinimumWidth(self.MINIMUN_WIDTH_LABEL) self.label_date.setAlignment(Qt.AlignCenter) self.label_date.setText(date) @staticmethod def live(): settings_store.set_day_ago(0) def get_pdf(self): defaut_path = 'I:\Programme mondon\Rapport production bobines' ts = timestamp_at_day_ago(settings_store.day_ago) defaut_name = "{} Rapport production bobines".format( timestamp_to_inverse_date(ts)) file_names = QFileDialog.getSaveFileName(self, caption='Enregistrer sous', directory='{}\{}.pdf'.format( defaut_path, defaut_name), filter="Fichiers pdf (*.pdf)") if not file_names[0]: return save_pdf(self.rapport, filename=file_names[0], preview=True) def externat_get_pdf(self): ts = timestamp_at_day_ago(settings_store.day_ago) file_names =\ 'I:\Programme mondon/rp_prod/{} Rapport production bobines.pdf'.format(timestamp_to_inverse_date(ts)) save_pdf(self.rapport, filename=file_names, preview=False) def impression(self): # Creation du printer printer = QPrinter() dialog = QPrintDialog(printer, self) if dialog.exec_() != QDialog.Accepted: return printer.setPageMargins(10, 10, 10, 10, QPrinter.Point) # Calcul le ratio de redimensionnement page_width = printer.pageRect().width() page_height = printer.pageRect().height() widget_width = self.rapport.width() widget_height = self.rapport.height() ratio = min(page_width / widget_width, page_height / widget_height) # Calcul du positionnement pos_x = max(0, (page_width - ratio * widget_width) / 2) pos_y = max(0, (page_height - ratio * widget_height) / 2) # Render le widget dans une image QPicture pour stocker # les directives de dessin picture = QPicture() widget_painter = QPainter(picture) widget_painter.scale(ratio, ratio) self.rapport.render(widget_painter) widget_painter.end() # Render la QPicture en utilisant le QPrinter picture_painter = QPainter() picture_painter.begin(printer) picture_painter.drawPicture(QPointF(pos_x, pos_y), picture) picture_painter.end() @staticmethod def jour_moins(): settings_store.set_day_ago(settings_store.day_ago + 1) @staticmethod def jour_plus(): settings_store.set_day_ago(settings_store.day_ago - 1)
class TeamGestionMenu(MondonWidget): MINIMUN_WIDTH_LABEL = 200 PIXMAPBUTTON_SIZE = QSize(30, 30) def __init__(self, parent=None): super(TeamGestionMenu, self).__init__(parent=parent) self.background_color = color_bleu_gris self.hbox = QHBoxLayout(self) self.bt_plus = PixmapButton(parent=self) self.bt_moins = PixmapButton(parent=self) self.label_date = QLabel() self.label_type_stat = QLabel("Gestion des équipes") self.init_button() self.init_widget() self.update_button() self.update_label() def init_widget(self): self.hbox.setSpacing(20) left_hbox = QHBoxLayout() left_hbox.addStretch(1) self.hbox.addLayout(left_hbox) center_hbox = QHBoxLayout() center_hbox.addStretch(4) center_hbox.addWidget(self.bt_moins) center_hbox.addStretch(1) self.label_date.setStyleSheet(white_22_label_stylesheet) self.label_date.setMinimumWidth(self.MINIMUN_WIDTH_LABEL) self.label_date.setAlignment(Qt.AlignCenter) center_hbox.addWidget(self.label_date) center_hbox.addStretch(1) center_hbox.addWidget(self.bt_plus) center_hbox.addStretch(4) self.hbox.addLayout(center_hbox) right_hbox = QHBoxLayout() right_hbox.addStretch(1) self.label_type_stat.setStyleSheet(green_maj_label_stylesheet) right_hbox.addWidget(self.label_type_stat) self.hbox.addLayout(right_hbox) self.setLayout(self.hbox) def on_settings_team_gestion_changed(self): self.update_button() self.update_label() def update_label(self): self.label_date.setText(settings_team_gestion_store.time_stat) def update_button(self): disabled_bt_moins = False disabled_bt_plus = False if settings_team_gestion_store.week_ago >= LIMIT_JOURS_GESTION_EQUIPE: disabled_bt_plus = True limit_week_stat = 1508709600 if timestamp_at_week_ago( settings_team_gestion_store.week_ago) == limit_week_stat: disabled_bt_moins = True self.bt_moins.setDisabled(disabled_bt_moins) self.bt_plus.setDisabled(disabled_bt_plus) def init_button(self): # Bouton time plus self.bt_plus.clicked.connect(self.time_more) self.bt_plus.setStyleSheet(button_stylesheet) self.bt_plus.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_plus.addImage("commun/assets/images/fleche_suivant.png") # Bouton time moins self.bt_moins.clicked.connect(self.time_less) self.bt_moins.setStyleSheet(button_stylesheet) self.bt_moins.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_moins.addImage("commun/assets/images/fleche_precedent.png") @staticmethod def time_more(): settings_team_gestion_store.update_week_ago(-1) @staticmethod def time_less(): settings_team_gestion_store.update_week_ago(1)
class ChartMenu(MondonWidget): PIXMAPBUTTON_SIZE = QSize(40, 40) BUTTON_HEIGHT = 40 BUTTON_WIDTH = 100 MINIMUN_WIDTH_LABEL = 350 def __init__(self, parent): super(ChartMenu, self).__init__(parent=parent) self.set_background_color(color_bleu_gris) self.bt_jour_plus = PixmapButton(parent=self) self.bt_jour_moins = PixmapButton(parent=self) self.bt_zoom_plus = PixmapButton(parent=self) self.bt_zoom_moins = PixmapButton(parent=self) self.bt_live = QPushButton("En direct") self.label_date = QLabel() self.live_speed = LiveSpeed(self) self.init_widget() self.update_label() self.update_button() def init_widget(self): self.init_button() self.update_label() master_hbox = QHBoxLayout() left_hbox = QHBoxLayout() left_hbox.addWidget(self.bt_live) self.live_speed.mouseDoubleClickEvent = self.create_window_live_speed left_hbox.addWidget(self.live_speed) left_hbox.addStretch(1) master_hbox.addLayout(left_hbox) center_hbox = QHBoxLayout() center_hbox.addWidget(self.bt_jour_moins) center_hbox.addStretch(1) center_hbox.addWidget(self.label_date) self.label_date.setStyleSheet(white_22_label_stylesheet) center_hbox.addStretch(1) center_hbox.addWidget(self.bt_jour_plus) master_hbox.addLayout(center_hbox) right_hbox = QHBoxLayout() right_hbox.addStretch(1) right_hbox.addWidget(self.bt_zoom_moins) right_hbox.addWidget(self.bt_zoom_plus) master_hbox.addLayout(right_hbox) self.setLayout(master_hbox) def init_button(self): # Bouton jour plus self.bt_jour_plus.clicked.connect(self.jour_plus) self.bt_jour_plus.setStyleSheet(button_stylesheet) self.bt_jour_plus.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_jour_plus.addImage("commun/assets/images/fleche_suivant.png") # Bouton jour moins self.bt_jour_moins.clicked.connect(self.jour_moins) self.bt_jour_moins.setStyleSheet(button_stylesheet) self.bt_jour_moins.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_jour_moins.addImage("commun/assets/images/fleche_precedent.png") # Bouton zoom plus self.bt_zoom_plus.clicked.connect(self.zoom_plus) self.bt_zoom_plus.setStyleSheet(button_stylesheet) self.bt_zoom_plus.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_zoom_plus.addImage("commun/assets/images/zoom_plus.png") # Bouton zoom moins self.bt_zoom_moins.clicked.connect(self.zoom_moins) self.bt_zoom_moins.setStyleSheet(button_stylesheet) self.bt_zoom_moins.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_zoom_moins.addImage("commun/assets/images/zoom_moins.png") # Bouton live self.bt_live.clicked.connect(self.live) self.bt_live.setFixedSize(self.BUTTON_WIDTH, self.BUTTON_HEIGHT) self.bt_live.setStyleSheet(button_little_stylesheet) def on_settings_changed(self, prev_live, prev_day_ago, prev_zoom): self.update_button() self.update_label() def update_button(self): self.bt_live.hide() if settings_store.day_ago == 0 else self.bt_live.show() self.live_speed.show() if settings_store.day_ago == 0 else self.live_speed.hide() self.bt_jour_plus.setEnabled(settings_store.day_ago > 0) self.bt_zoom_moins.setEnabled(settings_store.zoom > 1) self.bt_zoom_plus.setEnabled(32 > settings_store.zoom) def update_label(self): ts = timestamp_at_day_ago(settings_store.day_ago) date = timestamp_to_date(ts).capitalize() self.label_date.setMinimumWidth(self.MINIMUN_WIDTH_LABEL) self.label_date.setAlignment(Qt.AlignCenter) self.label_date.setText(date) @staticmethod def zoom_moins(): new_zoom = max(1, int(settings_store.zoom/2)) settings_store.set_zoom(new_zoom) @staticmethod def zoom_plus(): settings_store.set_zoom(settings_store.zoom * 2) @staticmethod def jour_moins(): settings_store.set_day_ago(settings_store.day_ago + 1) @staticmethod def jour_plus(): settings_store.set_day_ago(settings_store.day_ago - 1) @staticmethod def live(): settings_store.set_day_ago(0) @staticmethod def create_window_live_speed(event): app.create_tracker_window()
class ChartBarMenu(MondonWidget): MINIMUN_WIDTH_LABEL = 200 PIXMAPBUTTON_SIZE = QSize(30, 30) def __init__(self, parent=None): super(ChartBarMenu, self).__init__(parent=parent) self.background_color = color_bleu_gris self.hbox = QHBoxLayout(self) self.bt_plus = PixmapButton(parent=self) self.bt_moins = PixmapButton(parent=self) self.label_date = QLabel() self.label_type_stat = QLabel() self.init_button() self.init_widget() self.update_button() self.update_label() def init_widget(self): self.hbox.setSpacing(20) left_hbox = QHBoxLayout() left_hbox.addStretch(1) self.hbox.addLayout(left_hbox) center_hbox = QHBoxLayout() center_hbox.addStretch(4) center_hbox.addWidget(self.bt_moins) center_hbox.addStretch(1) self.label_date.setStyleSheet(white_22_label_stylesheet) self.label_date.setMinimumWidth(self.MINIMUN_WIDTH_LABEL) self.label_date.setAlignment(Qt.AlignCenter) center_hbox.addWidget(self.label_date) center_hbox.addStretch(1) center_hbox.addWidget(self.bt_plus) center_hbox.addStretch(4) self.hbox.addLayout(center_hbox) right_hbox = QHBoxLayout() right_hbox.addStretch(1) self.label_type_stat.setStyleSheet(green_maj_label_stylesheet) right_hbox.addWidget(self.label_type_stat) self.hbox.addLayout(right_hbox) self.setLayout(self.hbox) def on_settings_stat_changed(self): self.update_button() self.update_label() def update_label(self): self.label_date.setText(settings_stat_store.time_stat) self.label_type_stat.setText(settings_stat_store.data_type.upper()) def update_button(self): self.bt_plus.setEnabled(settings_stat_store.week_ago > 0 or settings_stat_store.month_ago > 0) disabled_bt_moins = False limit_week_stat = 1508709600 if settings_stat_store.data_type == "métrage" else 1514761200 if timestamp_at_week_ago( settings_stat_store.week_ago ) == limit_week_stat and settings_stat_store.week_ago >= 0: disabled_bt_moins = True limit_month_stat = 1509490800 if settings_stat_store.data_type == "métrage" else 1514761200 if timestamp_at_month_ago(settings_stat_store.month_ago) == limit_month_stat \ and settings_stat_store.month_ago >= 0: disabled_bt_moins = True limit_year_stat = 1514761200 if timestamp_at_year_ago(settings_stat_store.year_ago) == limit_year_stat \ and settings_stat_store.year_ago >= 0: disabled_bt_moins = True self.bt_moins.setDisabled(disabled_bt_moins) def init_button(self): # Bouton time plus self.bt_plus.clicked.connect(self.time_more) self.bt_plus.setStyleSheet(button_stylesheet) self.bt_plus.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_plus.addImage("commun/assets/images/fleche_suivant.png") # Bouton time moins self.bt_moins.clicked.connect(self.time_less) self.bt_moins.setStyleSheet(button_stylesheet) self.bt_moins.setFixedSize(self.PIXMAPBUTTON_SIZE) self.bt_moins.addImage("commun/assets/images/fleche_precedent.png") @staticmethod def time_more(): settings_stat_store.update_time_ago(-1) @staticmethod def time_less(): settings_stat_store.update_time_ago(1)