コード例 #1
0
class ImageReaderThread(ProgressTread):
    """
    thread for reading files. Useful for reading from disc
    """

    image_read_finish = Signal(Image)

    def __init__(self, file_path=None, mask_path=None):
        super().__init__()
        self.reader = TiffImageReader(self.info_function)
        self.file_path = file_path
        self.mask_path = mask_path
        self.image = None

    def set_path(self, file_path, mask_path=None):
        self.file_path = file_path
        self.mask_path = mask_path

    def run(self):
        if self.file_path is None:
            return
        try:
            self.image = self.reader.read(self.file_path, self.mask_path)
            self.image_read_finish.emit(self.image)
        except Exception as e:
            self.error_signal.emit(e)
コード例 #2
0
    def run(self):
        if self.module != "":
            from .. import plugins

            plugins.register()
            main_window_module = importlib.import_module(self.module)
            main_window: BaseMainWindow = main_window_module.MainWindow
            settings: BaseSettings = main_window.get_setting_class()(main_window_module.CONFIG_FOLDER)
            self.errors = settings.load()
            reader = TiffImageReader()
            im = reader.read(main_window.initial_image_path)
            im.file_path = ""
            self.result = partial(main_window, settings=settings, initial_image=im)
コード例 #3
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")))
コード例 #4
0
ファイル: main_window.py プロジェクト: 4DNucleome/PartSeg
    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")))