from PyQt6.QtWidgets import QWidget, QVBoxLayout, QPushButton, QGroupBox from PyQt6.QtCore import pyqtSignal import numpy as np from .dialogs import DIALOGS DIALOG_PROPERTY = "dialog" class DialogsPanel(QWidget): result_ready = pyqtSignal(np.ndarray) def __init__(self, image_manager): super().__init__() self.image_mgr = image_manager self.image_mgr.on_close.connect(lambda : self.buttons_set_enabled(False)) self.image_mgr.on_open.connect(lambda : self.buttons_set_enabled(True)) self.dialog_buttons = [] main_layout = QVBoxLayout() self.setLayout(main_layout) operations_group_box = QGroupBox("Operations") layout = QVBoxLayout() layout.setContentsMargins(75,25,75,25) for DIALOG in DIALOGS: btn = QPushButton(DIALOG.dialog_name(), self) btn.setProperty(DIALOG_PROPERTY, DIALOG) btn.clicked.connect(self.open_dialog) btn.setEnabled(False) self.dialog_buttons.append(btn) layout.addWidget(btn) operations_group_box.setLayout(layout) main_layout.addWidget(operations_group_box) def buttons_set_enabled(self, state): for btn in self.dialog_buttons: btn.setEnabled(state) def open_dialog(self): dialog_factory = self.sender().property(DIALOG_PROPERTY) self.dialog = dialog_factory(self.image_mgr.mgr.image()) self.dialog.result_ready().connect(lambda img : self.result_ready.emit(img)) self.dialog.accepted.connect(self.on_accepted) self.dialog.rejected.connect(self.on_rejected) self.dialog.exec() def on_accepted(self): self.image_mgr.mgr.update(self.dialog.last_processed) self.dialog = None def on_rejected(self): self.image_mgr.mgr.refresh()