예제 #1
0
class BlocSelected(MondonWidget):
    def __init__(self, data_type, callback, parent=None):
        super(BlocSelected, self).__init__(parent=parent)
        self.background_color = color_blanc
        self.set_border(color=color_noir)
        self.data_type = data_type
        self.parent = parent
        self.callback = callback
        self.master_hbox = QHBoxLayout()
        self.master_hbox.setContentsMargins(0, 0, 10, 0)
        self.clear_bt = PixmapButton(parent=self)
        self.init_button()
        self.init_ui()

    def init_ui(self):
        self.master_hbox.addLayout(self.get_content())
        if self.data_type != "bobine":
            self.master_hbox.addWidget(self.clear_bt)
        else:
            self.clear_bt.hide()
            self.master_hbox.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.master_hbox)

    def init_button(self):
        self.clear_bt.clicked.connect(self.handle_clicked_bt_delete)
        self.clear_bt.setStyleSheet(button_delete_bobine_selected_stylesheet)
        self.clear_bt.setContentsMargins(0)
        self.clear_bt.setFixedSize(15, 15)
        self.clear_bt.add_image("commun/assets/images/delete.png")

    def update_widget(self):
        print("update_widget")
        clear_layout(self.master_hbox)
        self.clear_bt = PixmapButton(parent=self)
        self.init_button()
        self.master_hbox.addLayout(self.get_content())
        if self.data_type != "bobine":
            self.master_hbox.addWidget(self.clear_bt)

    def get_content(self):
        content_layout = QVBoxLayout()
        content_layout.setContentsMargins(0, 0, 0, 0)
        if self.data_type == "perfo":
            if self.parent.plan_prod.perfo_selected:
                perfo_ui = PerfoUi(perfo=self.parent.plan_prod.perfo_selected)
                content_ui = QHBoxLayout()
                content_ui.setContentsMargins(1, 5, 0, 5)
                content_ui.addWidget(perfo_ui)
                content_ui.addStretch(0)
                content_layout.addLayout(content_ui)
            else:
                self.clear_bt.hide()
                content_layout.setContentsMargins(0, 15, 0, 15)
                content_layout.addLayout(
                    self.get_ui_select(text="une campagne de perforation"))
            return content_layout
        if self.data_type == "papier":
            if self.parent.plan_prod.bobine_papier_selected:
                if self.parent.plan_prod.refente_selected:
                    refente = self.parent.plan_prod.refente_selected
                    content_ui = QHBoxLayout()
                    content_ui.setSpacing(0)
                    content_ui.setContentsMargins(1, 5, 0, 5)
                    space = QWidget()
                    space.setFixedWidth(980 - refente.laize - refente.dec)
                    content_ui.addWidget(space)
                    content_ui.addWidget(
                        BobineMereUI(bobine=self.parent.plan_prod.
                                     bobine_papier_selected))
                    refente = self.parent.plan_prod.refente_selected
                    content_ui.addWidget(DecBobineRefente(dec=refente.dec))
                    content_ui.addStretch(0)
                    content_layout.addLayout(content_ui)
                else:
                    content_ui = BobineMereUI(
                        bobine=self.parent.plan_prod.bobine_papier_selected)
                    content_layout.addWidget(content_ui)
            else:
                self.clear_bt.hide()
                content_layout.setContentsMargins(0, 15, 0, 15)
                content_layout.addLayout(
                    self.get_ui_select(text="une bobine mère papier"))
            return content_layout
        if self.data_type == "poly":
            if self.parent.plan_prod.bobine_poly_selected:
                if self.parent.plan_prod.refente_selected:
                    refente = self.parent.plan_prod.refente_selected
                    content_ui = QHBoxLayout()
                    content_ui.setSpacing(0)
                    content_ui.setContentsMargins(1, 5, 0, 5)
                    space = QWidget()
                    space.setFixedWidth(980 - refente.laize - refente.dec)
                    content_ui.addWidget(space)
                    content_ui.addWidget(
                        BobineMereUI(
                            bobine=self.parent.plan_prod.bobine_poly_selected))
                    refente = self.parent.plan_prod.refente_selected
                    content_ui.addWidget(DecBobineRefente(dec=refente.dec))
                    content_ui.addStretch(0)
                    content_layout.addLayout(content_ui)
                else:
                    content_ui = BobineMereUI(
                        bobine=self.parent.plan_prod.bobine_poly_selected)
                    content_layout.addWidget(content_ui)
            else:
                self.clear_bt.hide()
                content_layout.addLayout(
                    self.get_ui_select(text="une bobine mère polypro"))
                content_layout.setContentsMargins(0, 15, 0, 15)
            return content_layout
        if self.data_type == "refente":
            if self.parent.plan_prod.refente_selected:
                refente = self.parent.plan_prod.refente_selected
                content_ui = QHBoxLayout()
                content_ui.setSpacing(0)
                content_ui.setContentsMargins(0, 0, 0, 0)
                space = QWidget()
                space.setFixedWidth(980 - refente.laize - refente.dec)
                content_ui.addWidget(space)
                content_ui.addWidget(
                    RefenteUi(refente=refente,
                              bobines_selected=self.parent.plan_prod.
                              bobines_filles_selected))
                content_ui.addWidget(DecBobineRefente(dec=refente.dec))
                content_ui.addStretch(0)
                content_layout.addLayout(content_ui)
            else:
                self.clear_bt.hide()
                content_layout.setContentsMargins(0, 15, 0, 15)
                content_layout.addLayout(
                    self.get_ui_select(text="une refente"))
            return content_layout
        if self.data_type == "bobine":
            content_layout.setContentsMargins(0, 0, 0, 0)
            content_layout.setSpacing(2)
            if self.parent.plan_prod.bobines_filles_selected:
                content_layout.addWidget(LegendBobineSelected())
                for value in group_bobine(bobines=self.parent.plan_prod.
                                          bobines_filles_selected).values():
                    content_layout.addWidget(
                        LineBobineSelected(bobine=value[0], amount=value[1]))
                self.set_border(color=None)
            else:
                self.clear_bt.hide()
                content_layout.setContentsMargins(0, 15, 0, 15)
                content_layout.addLayout(
                    self.get_ui_select(text="une bobine fille"))
                self.set_border(color=color_noir)
            return content_layout

    def is_selected(self):
        if self.data_type == "refente" and self.parent.plan_prod.refente_selected:
            return True
        if self.data_type == "papier" and self.parent.plan_prod.bobine_papier_selected:
            return True
        if self.data_type == "poly" and self.parent.plan_prod.bobine_poly_selected:
            return True
        if self.data_type == "perfo" and self.parent.plan_prod.perfo_selected:
            return True
        if self.data_type == "bobine" and self.parent.plan_prod.bobines_filles_selected:
            return True
        return False

    def handle_clicked_bt_delete(self):
        if self.data_type == "refente" and self.parent.plan_prod.refente_selected:
            self.parent.plan_prod.del_refente_selected()
        if self.data_type == "papier" and self.parent.plan_prod.bobine_papier_selected:
            self.parent.plan_prod.del_papier_selected()
        if self.data_type == "poly" and self.parent.plan_prod.bobine_poly_selected:
            self.parent.plan_prod.del_poly_selected()
        if self.data_type == "perfo" and self.parent.plan_prod.perfo_selected:
            self.parent.plan_prod.del_perfo_selected()
        self.parent.update()

    @staticmethod
    def get_ui_select(text):
        hbox = QHBoxLayout()
        label = QLabel("Double click pour sélectionner {}".format(text))
        label.setStyleSheet(gray_18_label_stylesheet)
        hbox.addWidget(label, alignment=Qt.AlignCenter)
        return hbox

    def mouseDoubleClickEvent(self, e):
        filter_store.set_data_type(self.data_type)
        self.callback()
        super(BlocSelected, self).mouseDoubleClickEvent(e)
예제 #2
0
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)
예제 #3
0
class LineBobineSelected(MondonWidget):
    def __init__(self, bobine, amount, parent=None):
        super(LineBobineSelected, self).__init__(parent=parent)
        self.parent = parent
        self.set_border(color=color_noir)
        self.bobine = bobine
        self.amount = amount
        self.clear_bt = PixmapButton(parent=self)
        self.init_button()
        self.stock_prev_value = 0
        self.production = QLabel()
        self.stock_prev = QLabel()
        self.etat = QLabel()
        self.init_widget()
        self.update_widget()
        self.setFixedHeight(30)

    def init_button(self):
        # Bouton jour plus
        self.clear_bt.setToolTip("Suppression bobine fille")
        self.clear_bt.clicked.connect(self.handle_clicked_bt_delete)
        self.clear_bt.setStyleSheet(button_delete_bobine_selected_stylesheet)
        self.clear_bt.setContentsMargins(0)
        self.clear_bt.setFixedSize(15, 15)
        self.clear_bt.add_image("commun/assets/images/delete.png")

    def init_widget(self):
        hbox = QHBoxLayout()
        hbox.setContentsMargins(0, 0, 5, 0)
        code = QLabel(str(self.bobine.code))
        code.setAlignment(Qt.AlignVCenter)
        code.setStyleSheet(black_14_label_stylesheet)
        code.setFixedWidth(200)
        hbox.addWidget(code)
        laize = QLabel(str(int(self.bobine.laize)))
        laize.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        laize.setStyleSheet(black_14_label_stylesheet)
        laize.setFixedWidth(80)
        hbox.addWidget(laize)
        amount = QLabel(str(int(self.amount)))
        amount.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        amount.setStyleSheet(black_14_label_stylesheet)
        amount.setFixedWidth(80)
        hbox.addWidget(amount)
        stock_value = str(int(self.bobine.stock_at_time))
        stock = QLabel(stock_value)
        stock.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        stock.setStyleSheet(black_14_label_stylesheet)
        hbox.addWidget(stock)
        stock_therme_value = str(int(self.bobine.stock_therme_at_time))
        stock_therme = QLabel(stock_therme_value)
        stock_therme.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        stock_therme.setStyleSheet(black_14_label_stylesheet)
        hbox.addWidget(stock_therme)
        self.production.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        self.production.setStyleSheet(black_14_bold_label_stylesheet)
        hbox.addWidget(self.production)
        self.stock_prev.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        self.stock_prev.setStyleSheet(black_14_bold_label_stylesheet)
        hbox.addWidget(self.stock_prev)
        self.etat.setAlignment(Qt.AlignVCenter | Qt.AlignCenter)
        hbox.addWidget(self.etat)
        hbox.addWidget(self.clear_bt)
        self.setLayout(hbox)

    def get_etat(self):
        if self.bobine.vente_mensuelle > self.stock_prev_value:
            return "RUPTURE"
        elif self.bobine.vente_annuelle < self.stock_prev_value:
            return "SURSTOCK"
        return "OK"

    def get_production(self):
        tours = settings_store_gestion.plan_prod.tours
        production = self.amount * tours
        return production

    def update_widget(self):
        self.production.setText("+{}".format(self.get_production()))
        self.stock_prev_value = int(self.get_production() +
                                    self.bobine.stock_therme_at_time)
        self.stock_prev.setText(str(self.stock_prev_value))
        etat_value = self.get_etat()
        self.etat.setText(etat_value)
        if etat_value == "RUPTURE":
            etat_label_stylesheet = black_14_bold_label_stylesheet
        elif etat_value == "SURSTOCK":
            etat_label_stylesheet = red_14_bold_label_stylesheet
        else:
            etat_label_stylesheet = black_14_label_stylesheet
        self.etat.setStyleSheet(etat_label_stylesheet)

    def handle_clicked_bt_delete(self):
        from gestion.stores.settings_store import settings_store_gestion
        settings_store_gestion.plan_prod.del_bobine_selected(
            bobine=self.bobine)