def __init__(self, settings: StackSettings, parent=None):
        super().__init__(parent)
        self.settings = settings
        self.calculate_btn = QPushButton("Calculate")
        self.calculate_btn.clicked.connect(self.calculate)
        self.result_view = QTableWidget()
        self.channel_select = ChannelComboBox()
        self.units_select = EnumComboBox(Units)
        self.units_select.set_value(self.settings.get("simple_measurements.units", Units.nm))
        self.units_select.currentIndexChanged.connect(self.change_units)

        layout = QHBoxLayout()
        self.measurement_layout = QVBoxLayout()
        l1 = QHBoxLayout()
        l1.addWidget(QLabel("Units"))
        l1.addWidget(self.units_select)
        self.measurement_layout.addLayout(l1)
        l2 = QHBoxLayout()
        l2.addWidget(QLabel("Channel"))
        l2.addWidget(self.channel_select)
        self.measurement_layout.addLayout(l2)
        layout.addLayout(self.measurement_layout)
        result_layout = QVBoxLayout()
        result_layout.addWidget(self.result_view)
        result_layout.addWidget(self.calculate_btn)
        layout.addLayout(result_layout)
        self.setLayout(layout)
        self.setWindowTitle("Measurement")
        if self.window() == self:
            try:
                geometry = self.settings.get_from_profile("simple_measurement_window_geometry")
                self.restoreGeometry(QByteArray.fromHex(bytes(geometry, "ascii")))
            except KeyError:
                pass
Ejemplo n.º 2
0
 def __init__(self, settings, parent=None):
     super().__init__(parent)
     self.setWindowTitle("Batch processing")
     self.settings = settings
     self.batch_manager = CalculationManager()
     self.file_choose = FileChoose(self.settings, self.batch_manager, self)
     self.calculate_planer = CalculatePlaner(self.settings, self)
     self.addTab(self.calculate_planer, "Prepare workflow")
     self.addTab(self.file_choose, "Input files")
     self.working = False
     with suppress(KeyError):
         geometry = self.settings.get_from_profile("batch_window_geometry")
         self.restoreGeometry(QByteArray.fromHex(bytes(geometry, "ascii")))
Ejemplo n.º 3
0
    def __init__(self,
                 settings: ViewSettings,
                 image_view_names: List[str],
                 reload_list=None,
                 parent=None):
        super().__init__(parent)
        self.color_control = ColorControl(settings, image_view_names)
        self.settings = settings
        self.reload_list = reload_list if reload_list is not None else []

        self.develop = DevelopTab()
        self.addTab(self.color_control, "Color control")
        if state_store.develop:
            self.addTab(self.develop, "Develop")
        if self.window() == self:
            with suppress(KeyError):
                geometry = self.settings.get_from_profile(
                    "advanced_window_geometry")
                self.restoreGeometry(
                    QByteArray.fromHex(bytes(geometry, "ascii")))
Ejemplo n.º 4
0
    def __init__(self,
                 config_folder=CONFIG_FOLDER,
                 title="PartSeg",
                 settings=None,
                 signal_fun=None,
                 initial_image=None):
        super().__init__(config_folder, title, settings,
                         load_functions.load_dict, signal_fun)
        self.channel_info = "result_image"
        self.files_num = 2
        self.setMinimumWidth(600)
        # thi isinstance is only for hinting in IDE
        assert isinstance(self.settings, PartSettings)  # nosec
        self.main_menu = MainMenu(self.settings, self)
        self.channel_control2 = ChannelProperty(self.settings,
                                                start_name="result_image")
        self.raw_image = CompareImageView(self.settings, self.channel_control2,
                                          "raw_image")
        self.measurements = MeasurementWidget(self.settings)
        self.left_stack = StackedWidgetWithSelector()
        self.left_stack.addWidget(self.raw_image, "Image")
        self.left_stack.addWidget(self.measurements, "Measurements")
        self.result_image = ResultImageView(self.settings,
                                            self.channel_control2,
                                            "result_image")
        self.color_bar = ColorBar(self.settings,
                                  [self.raw_image, self.result_image])
        self.info_text = QLabel()
        self.info_text.setMinimumHeight(25)
        self.raw_image.text_info_change.connect(self.info_text.setText)
        self.result_image.text_info_change.connect(self.info_text.setText)
        self.synchronize_tool = SynchronizeView(self.raw_image,
                                                self.result_image, self)
        self.options_panel = Options(self.settings, self.channel_control2,
                                     self.raw_image, self.synchronize_tool)
        # self.main_menu.image_loaded.connect(self.image_read)
        self.settings.image_changed.connect(self.image_read)
        self.advanced_window = SegAdvancedWindow(self.settings,
                                                 reload_list=[self.reload])
        self.batch_window = None  # BatchWindow(self.settings)

        self.multiple_files = MultipleFileWidget(self.settings,
                                                 load_functions.load_dict,
                                                 True)
        self.multiple_files.setVisible(
            self.settings.get("multiple_files_widget", False))

        if initial_image is None:
            reader = TiffImageReader()
            im = reader.read(self.initial_image_path)
            im.file_path = ""
            self.settings.image = im
        elif initial_image is not False:
            self.settings.image = initial_image

        icon = QIcon(os.path.join(PartSegData.icons_dir, "icon.png"))
        self.setWindowIcon(icon)

        menu_bar = self.menuBar()
        file_menu = menu_bar.addMenu("File")
        file_menu.addAction("&Open").triggered.connect(
            self.main_menu.load_data)
        file_menu.addMenu(self.recent_file_menu)
        file_menu.addAction("&Save").triggered.connect(
            self.main_menu.save_file)
        file_menu.addAction("Batch processing").triggered.connect(
            self.main_menu.batch_window)
        view_menu = menu_bar.addMenu("View")
        view_menu.addAction("Settings and Measurement").triggered.connect(
            self.main_menu.advanced_window_show)
        view_menu.addAction("Additional output").triggered.connect(
            self.additional_layers_show)
        view_menu.addAction("Additional output with data").triggered.connect(
            lambda: self.additional_layers_show(True))
        view_menu.addAction("Napari viewer").triggered.connect(
            self.napari_viewer_show)
        view_menu.addAction("Toggle Multiple Files").triggered.connect(
            self.toggle_multiple_files)
        view_menu.addAction("Toggle left panel").triggered.connect(
            self.toggle_left_panel)
        view_menu.addAction("Toggle console").triggered.connect(
            self._toggle_console)
        action = view_menu.addAction("Screenshot right panel")
        action.triggered.connect(self.screenshot(self.result_image))
        action.setShortcut(QKeySequence.Print)
        view_menu.addAction("Screenshot left panel").triggered.connect(
            self.screenshot(self.raw_image))
        image_menu = menu_bar.addMenu("Image operations")
        image_menu.addAction("Image adjustment").triggered.connect(
            self.image_adjust_exec)
        image_menu.addAction("Mask manager").triggered.connect(
            self.main_menu.mask_manager)
        help_menu = menu_bar.addMenu("Help")
        help_menu.addAction("State directory").triggered.connect(
            self.show_settings_directory)
        help_menu.addAction("About").triggered.connect(self.show_about_dialog)

        layout = QGridLayout()
        layout.setSpacing(0)
        info_layout = QHBoxLayout()
        info_layout.addWidget(self.left_stack.selector)
        info_layout.addWidget(self.options_panel.compare_btn)
        info_layout.addWidget(self.info_text, 1, Qt.AlignHCenter)

        image_layout = EqualColumnLayout()
        image_layout.addWidget(self.left_stack)
        image_layout.addWidget(self.result_image)

        layout.setSpacing(0)
        layout.addWidget(self.main_menu, 0, 0, 1, 3)
        layout.addLayout(info_layout, 3, 1, 1, 2)
        layout.addWidget(self.multiple_files, 2, 0)
        layout.addWidget(self.color_bar, 2, 1)
        layout.addLayout(image_layout, 2, 2, 1, 1)
        layout.addWidget(self.options_panel, 0, 3, 3, 1)
        layout.setColumnStretch(2, 1)
        widget = QWidget()
        widget.setLayout(layout)
        self.setCentralWidget(widget)
        with suppress(KeyError):
            geometry = self.settings.get_from_profile("main_window_geometry")
            self.restoreGeometry(QByteArray.fromHex(bytes(geometry, "ascii")))
    def restore_state(self,
                      stream: QXmlStreamReader,
                      testing: bool = False) -> bool:
        '''
        Restores the state from given stream.

        Parameters
        ----------
        stream : QXmlStreamReader
        testing : bool
            If Testing is true, the function only parses the data from the
            given stream but does not restore anything. You can use this check
            for faulty files before you start restoring the state

        Returns
        -------
        value : bool
        '''
        is_floating = bool(int(stream.attributes().value("Floating")))
        logger.debug('Restore DockContainerWidget Floating %s', is_floating)

        if not testing:
            self.d._visible_dock_area_count = -1

            # invalidate the dock area count and clear the area cache
            self.d.dock_areas.clear()
            self.d.last_added_area_cache.clear()

        if is_floating:
            logger.debug('Restore floating widget')
            if not stream.readNextStartElement(
            ) or stream.name() != "Geometry":
                return False

            geometry_string = stream.readElementText(
                QXmlStreamReader.ErrorOnUnexpectedElement)

            geometry = QByteArray.fromHex(geometry_string)
            if geometry.isEmpty():
                return False

            if not testing:
                floating_widget = self.floating_widget()
                floating_widget.restoreGeometry(geometry)

        res, new_root_splitter = self.d.restore_child_nodes(stream, testing)
        if not res:
            return False

        if testing:
            return True

        # If the root splitter is empty, rostoreChildNodes returns a 0 pointer
        # and we need to create a new empty root splitter
        if not new_root_splitter:
            new_root_splitter = self.d.new_splitter(Qt.Horizontal)

        self.d.layout.replaceWidget(self.d.root_splitter, new_root_splitter)
        old_root = self.d.root_splitter
        self.d.root_splitter = new_root_splitter
        old_root.deleteLater()
        return True
Ejemplo n.º 6
0
    def __init__(self,
                 config_folder=CONFIG_FOLDER,
                 title="PartSeg",
                 settings=None,
                 signal_fun=None,
                 initial_image=None):
        super().__init__(config_folder, title, settings,
                         io_functions.load_dict, signal_fun)
        self.channel_info = "channelcontrol"
        self.channel_control = ChannelProperty(self.settings,
                                               start_name="channelcontrol")
        self.image_view = StackImageView(self.settings,
                                         self.channel_control,
                                         name="channelcontrol")
        self.image_view.setMinimumWidth(450)
        self.info_text = QLabel()
        self.info_text.setSizePolicy(QSizePolicy.Ignored,
                                     QSizePolicy.Preferred)
        self.image_view.text_info_change.connect(self.info_text.setText)
        self.options_panel = Options(self.settings, self.image_view)
        self.main_menu = MainMenu(self.settings, self)
        self.main_menu.image_loaded.connect(self.image_read)
        self.settings.image_changed.connect(self.image_read)
        self.color_bar = ColorBar(self.settings, self.image_view)
        self.multiple_files = MultipleFileWidget(self.settings,
                                                 io_functions.load_dict)
        self.multiple_files.setVisible(
            self.options_panel.image_properties.multiple_files.isChecked())
        self.options_panel.algorithm_options.batch_process.multiple_result.connect(
            partial(self.multiple_files.save_state_action, custom_name=False))

        icon = QIcon(os.path.join(PartSegData.icons_dir, "icon_stack.png"))
        self.setWindowIcon(icon)

        menu_bar = self.menuBar()
        file_menu = menu_bar.addMenu("File")
        file_menu.addAction("&Open").triggered.connect(
            self.main_menu.load_image)
        file_menu.addMenu(self.recent_file_menu)
        file_menu.addAction("&Save segmentation").triggered.connect(
            self.main_menu.save_segmentation)
        file_menu.addAction("&Save components").triggered.connect(
            self.main_menu.save_result)
        view_menu = menu_bar.addMenu("View")
        view_menu.addAction("Settings and Measurement").triggered.connect(
            self.main_menu.show_advanced_window)
        view_menu.addAction("Additional output").triggered.connect(
            self.additional_layers_show)
        view_menu.addAction("Additional output with data").triggered.connect(
            lambda: self.additional_layers_show(True))
        view_menu.addAction("Napari viewer").triggered.connect(
            self.napari_viewer_show)
        view_menu.addAction("Toggle Multiple Files").triggered.connect(
            self.toggle_multiple_files)
        view_menu.addAction("Toggle console").triggered.connect(
            self._toggle_console)
        action = view_menu.addAction("Screenshot")
        action.triggered.connect(self.screenshot(self.image_view))
        action.setShortcut(QKeySequence.Print)
        image_menu = menu_bar.addMenu("Image operations")
        image_menu.addAction("Image adjustment").triggered.connect(
            self.image_adjust_exec)
        help_menu = menu_bar.addMenu("Help")
        help_menu.addAction("State directory").triggered.connect(
            self.show_settings_directory)
        help_menu.addAction("About").triggered.connect(self.show_about_dialog)

        layout = QVBoxLayout()
        layout.addWidget(self.main_menu)
        sub_layout = QHBoxLayout()
        sub2_layout = QVBoxLayout()
        sub3_layout = QVBoxLayout()
        sub_layout.addWidget(self.multiple_files)
        sub_layout.addWidget(self.color_bar, 0)
        sub3_layout.addWidget(self.image_view, 1)
        sub3_layout.addWidget(self.info_text, 0)
        sub2_layout.addWidget(self.options_panel, 1)
        sub2_layout.addWidget(self.channel_control, 0)

        sub_layout.addLayout(sub3_layout, 1)
        sub_layout.addLayout(sub2_layout, 0)
        layout.addLayout(sub_layout)
        self.widget = QWidget()
        self.widget.setLayout(layout)
        self.setCentralWidget(self.widget)
        if initial_image is None:
            reader = TiffImageReader()
            im = reader.read(self.initial_image_path)
            im.file_path = ""
            self.settings.image = im
        elif initial_image is not False:
            self.settings.image = initial_image
        with suppress(KeyError):
            geometry = self.settings.get_from_profile("main_window_geometry")
            self.restoreGeometry(QByteArray.fromHex(bytes(geometry, "ascii")))