from PyQt6.QtWidgets import QVBoxLayout, QHBoxLayout, QWidget, QApplication from PyQt6.QtGui import QImage from .ImageCanvas import ImageCanvas from .ImageManagePanel import ImageManagePanel from .DialogsPanel import DialogsPanel class ImageEditor(QWidget): def __init__(self): super().__init__() self.setWindowTitle("Image Editor") self.setGeometry(100, 100, 800, 600) self.canvas = ImageCanvas() self.img_manager = ImageManagePanel() self.img_manager.on_update.connect(self.display_image) self.img_manager.on_close.connect(lambda : self.canvas.clear()) self.dialogs_panel = DialogsPanel(self.img_manager) self.dialogs_panel.result_ready.connect(self.display_image) main_layout = QHBoxLayout() side_panel = QVBoxLayout() side_panel.addWidget(self.img_manager, 1) side_panel.addWidget(self.dialogs_panel, 9) preview_panel = QVBoxLayout() preview_panel.addWidget(self.canvas) main_layout.addLayout(side_panel,2) main_layout.addLayout(preview_panel, 3) self.setLayout(main_layout) self.setAcceptDrops(True) def dragEnterEvent(self, event): if event.mimeData().hasUrls(): event.acceptProposedAction() def dropEvent(self, event): files = [url.toLocalFile() for url in event.mimeData().urls()] if files: self.img_manager.open(files[0]) def display_image(self, image): height, width, channel = image.shape bytes_per_line = 3 * width self.canvas.updatePixmap(QImage(image.data, width, height, bytes_per_line, QImage.Format.Format_RGB888))