From 14d4c75a123b203f2d27a73316d122fea88426b3 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Tue, 10 Dec 2024 17:24:20 +0100 Subject: [PATCH] add publish report viewer to admin actions --- .../publisher/publish_report_viewer/window.py | 68 +++++++++++-------- client/ayon_core/tools/tray/ui/tray.py | 17 +++++ 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/client/ayon_core/tools/publisher/publish_report_viewer/window.py b/client/ayon_core/tools/publisher/publish_report_viewer/window.py index 6921c5d162..77db65588a 100644 --- a/client/ayon_core/tools/publisher/publish_report_viewer/window.py +++ b/client/ayon_core/tools/publisher/publish_report_viewer/window.py @@ -484,22 +484,6 @@ def __init__(self, *args, **kwargs): self._time_delegate = time_delegate self._remove_btn = remove_btn - def _update_remove_btn(self): - viewport = self.viewport() - height = viewport.height() + self.header().height() - pos_x = viewport.width() - self._remove_btn.width() - 5 - pos_y = height - self._remove_btn.height() - 5 - self._remove_btn.move(max(0, pos_x), max(0, pos_y)) - - def _on_rows_inserted(self): - header = self.header() - header.resizeSections(QtWidgets.QHeaderView.ResizeToContents) - self._update_remove_btn() - - def resizeEvent(self, event): - super().resizeEvent(event) - self._update_remove_btn() - def showEvent(self, event): super().showEvent(event) self._model.refresh() @@ -507,8 +491,9 @@ def showEvent(self, event): header.resizeSections(QtWidgets.QHeaderView.ResizeToContents) self._update_remove_btn() - def _on_selection_change(self): - self.selection_changed.emit() + def resizeEvent(self, event): + super().resizeEvent(event) + self._update_remove_btn() def add_filepaths(self, filepaths): self._model.add_filepaths(filepaths) @@ -518,6 +503,30 @@ def remove_item_by_id(self, item_id): self._model.remove_item_by_id(item_id) self._fill_selection() + def get_current_report(self): + index = self.currentIndex() + item_id = index.data(ITEM_ID_ROLE) + return self._model.get_report_by_id(item_id) + + def refresh(self): + self._model.refresh() + self._fill_selection() + + def _update_remove_btn(self): + viewport = self.viewport() + height = viewport.height() + self.header().height() + pos_x = viewport.width() - self._remove_btn.width() - 5 + pos_y = height - self._remove_btn.height() - 5 + self._remove_btn.move(max(0, pos_x), max(0, pos_y)) + + def _on_rows_inserted(self): + header = self.header() + header.resizeSections(QtWidgets.QHeaderView.ResizeToContents) + self._update_remove_btn() + + def _on_selection_change(self): + self.selection_changed.emit() + def _on_remove_clicked(self): index = self.currentIndex() item_id = index.data(ITEM_ID_ROLE) @@ -533,11 +542,6 @@ def _fill_selection(self): if index.isValid(): self.setCurrentIndex(index) - def get_current_report(self): - index = self.currentIndex() - item_id = index.data(ITEM_ID_ROLE) - return self._model.get_report_by_id(item_id) - class LoadedFilesWidget(QtWidgets.QWidget): report_changed = QtCore.Signal() @@ -577,15 +581,18 @@ def dropEvent(self, event): self._add_filepaths(filepaths) event.accept() + def refresh(self): + self._view.refresh() + + def get_current_report(self): + return self._view.get_current_report() + def _on_report_change(self): self.report_changed.emit() def _add_filepaths(self, filepaths): self._view.add_filepaths(filepaths) - def get_current_report(self): - return self._view.get_current_report() - class PublishReportViewerWindow(QtWidgets.QWidget): default_width = 1200 @@ -624,9 +631,12 @@ def __init__(self, parent=None): self.resize(self.default_width, self.default_height) self.setStyleSheet(style.load_stylesheet()) - def _on_report_change(self): - report = self._loaded_files_widget.get_current_report() - self.set_report(report) + def refresh(self): + self._loaded_files_widget.refresh() def set_report(self, report_data): self._main_widget.set_report(report_data) + + def _on_report_change(self): + report = self._loaded_files_widget.get_current_report() + self.set_report(report) diff --git a/client/ayon_core/tools/tray/ui/tray.py b/client/ayon_core/tools/tray/ui/tray.py index dbaf13dfe9..98e3c783c4 100644 --- a/client/ayon_core/tools/tray/ui/tray.py +++ b/client/ayon_core/tools/tray/ui/tray.py @@ -36,6 +36,9 @@ from ayon_core.tools.launcher.ui import LauncherWindow from ayon_core.tools.loader.ui import LoaderWindow from ayon_core.tools.console_interpreter.ui import ConsoleInterpreterWindow +from ayon_core.tools.publisher.publish_report_viewer import ( + PublishReportViewerWindow, +) from .addons_manager import TrayAddonsManager from .host_console_listener import HostListener @@ -89,6 +92,7 @@ def __init__(self, tray_widget, main_window): self._launcher_window = None self._browser_window = None self._console_window = ConsoleInterpreterWindow() + self._publish_report_viewer_window = PublishReportViewerWindow() self._update_check_timer = update_check_timer self._update_check_interval = update_check_interval @@ -161,6 +165,13 @@ def initialize_addons(self): ) console_action.triggered.connect(self._show_console_window) + publish_report_viewer_action = ITrayAddon.add_action_to_admin_submenu( + "Publish report viewer", tray_menu + ) + publish_report_viewer_action.triggered.connect( + self._show_publish_report_viewer + ) + self._addons_manager.initialize(tray_menu) # Add default actions under addon actions @@ -575,6 +586,12 @@ def _show_console_window(self): self._console_window.raise_() self._console_window.activateWindow() + def _show_publish_report_viewer(self): + self._publish_report_viewer_window.refresh() + self._publish_report_viewer_window.show() + self._publish_report_viewer_window.raise_() + self._publish_report_viewer_window.activateWindow() + class SystemTrayIcon(QtWidgets.QSystemTrayIcon): """Tray widget.