コード例 #1
0
 def mousePressEvent(self, event):
     """Override Qt method"""
     if event.button() == Qt.MidButton:
         index = self.tabBar().tabAt(event.pos())
         if index >= 0:
             self.sig_close_tab.emit(index)
             event.accept()
             return
     QTabWidget.mousePressEvent(self, event)
コード例 #2
0
    def initUI(self):
        self.setWindowTitle('Photo Editor')

        outer_layout = QHBoxLayout()
        self.setLayout(outer_layout)

        images = QVBoxLayout()
        input_image = QGroupBox("Before")
        input_img_layout = QHBoxLayout()
        input_image.setLayout(input_img_layout)
        self.input_image_widget = QLabel()
        self.input_image_widget.setScaledContents(True)
        input_img_layout.addWidget(self.input_image_widget)
        images.addWidget(input_image)

        output_image = QGroupBox("After")
        output_img_layout = QHBoxLayout()
        output_image.setLayout(output_img_layout)
        self.output_image_widget = QLabel()
        self.output_image_widget.setScaledContents(True)
        output_img_layout.addWidget(self.output_image_widget)
        images.addWidget(output_image)

        outer_layout.addLayout(images)

        step_and_operation = QVBoxLayout()
        outer_layout.addLayout(step_and_operation)

        steps = QGroupBox("Steps")
        steps_layout = QHBoxLayout()

        steps.setLayout(steps_layout)
        for i in range(NUM_STEPS + 1):
            step_label = QLabel()
            steps_layout.addWidget(step_label)

            def get_callback(j):
                def callback(e):
                    self.current_stage = j
                    for k in range(len(all_filters)):
                        self.actions[j][k].write_states_to_ui()
                    self.update_UI()
                    self.operation_tabs.setCurrentIndex(self.selected_actions[j])

                return callback

            if i > 0:
                step_label.mousePressEvent = get_callback(i - 1)
            self.step_image_widgets[i] = step_label

        step_and_operation.addWidget(steps)

        infos = QHBoxLayout()
        step_and_operation.addLayout(infos)

        histogram = QGroupBox("Histogram")
        curves = QGroupBox("Curves")
        infos.addWidget(histogram)
        infos.addWidget(curves)

        hist_info = QLabel()
        filter_info = QLabel()
        self.hist_info_widget = hist_info
        self.hist_info_widget.setScaledContents(True)
        self.filter_info_widget = filter_info
        self.filter_info_widget.setScaledContents(True)

        histogram_layout = QVBoxLayout()
        histogram.setLayout(histogram_layout)
        histogram_layout.addWidget(hist_info)

        curve_layout = QVBoxLayout()
        curves.setLayout(curve_layout)
        curve_layout.addWidget(filter_info)

        operation = QGroupBox("Operation")
        step_and_operation.addWidget(operation)
        operation_layout = QVBoxLayout()
        operation.setLayout(operation_layout)
        operation_tabs = QTabWidget()
        operation_layout.addWidget(operation_tabs)

        operation_tabs.currentChanged.connect(self.filter_changed)
        self.operation_tabs = operation_tabs

        for i, f in enumerate(all_filters):
            widget, sliders = f.get_tab_widget_and_sliders(self)
            for j in range(NUM_STEPS):
                self.actions[j][i].sliders = sliders
            operation_tabs.addTab(widget, f.get_name())
            operation_tabs.mousePressEvent = lambda e: self.update_UI()

        moves_layout = QHBoxLayout()
        operation_layout.addLayout(moves_layout)
        btn_prev = QPushButton("Previous step", self)
        btn_next = QPushButton("Next step", self)
        btn_save = QPushButton("Done!", self)
        label_progress = QLabel(self)
        moves_layout.addWidget(btn_prev)
        moves_layout.addWidget(btn_next)
        moves_layout.addWidget(btn_save)
        moves_layout.addWidget(label_progress)
        self.label_progress = label_progress
        btn_prev.clicked.connect(self.move_to_prev)
        btn_next.clicked.connect(self.move_to_next)
        btn_save.clicked.connect(self.save)

        self.resize(800, 800)
        self.move(0, 0)
        self.update_UI()
        self.show()