From f6ccc6aee10360a88ea0bba1b66ecce3b8958dd0 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Thu, 20 Jan 2022 14:51:14 +0100 Subject: [PATCH] OP-1117 - updated setting of state on action item Updated handling of menu display and repaint --- openpype/tools/launcher/constants.py | 1 + openpype/tools/launcher/models.py | 26 +++++++++++++++++++------- openpype/tools/launcher/widgets.py | 26 +++++++++++++++++++++----- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/openpype/tools/launcher/constants.py b/openpype/tools/launcher/constants.py index 3747b0f0a4..61f631759b 100644 --- a/openpype/tools/launcher/constants.py +++ b/openpype/tools/launcher/constants.py @@ -8,6 +8,7 @@ ACTION_ID_ROLE = QtCore.Qt.UserRole + 3 ANIMATION_START_ROLE = QtCore.Qt.UserRole + 4 ANIMATION_STATE_ROLE = QtCore.Qt.UserRole + 5 FORCE_NOT_OPEN_WORKFILE_ROLE = QtCore.Qt.UserRole + 6 +ACTION_TOOLTIP_ROLE = QtCore.Qt.UserRole + 7 # Animation length in seconds ANIMATION_LEN = 7 diff --git a/openpype/tools/launcher/models.py b/openpype/tools/launcher/models.py index 305707319d..10922e42cc 100644 --- a/openpype/tools/launcher/models.py +++ b/openpype/tools/launcher/models.py @@ -32,7 +32,7 @@ class ActionModel(QtGui.QStandardItemModel): # Cache of available actions self._registered_actions = list() self.items_by_id = {} - path = appdirs.user_data_dir("openpype", "pype_club") + path = appdirs.user_data_dir("openpype", "pypeclub") self.launcher_registry = JSONSettingRegistry("launcher", path) try: @@ -198,10 +198,7 @@ class ActionModel(QtGui.QStandardItemModel): if self.is_force_not_open_workfile(item, stored): - label = item.text() - label += " (Not opening last workfile)" - item.setData(label, QtCore.Qt.ToolTipRole) - item.setData(True, FORCE_NOT_OPEN_WORKFILE_ROLE) + self.change_action_item(item, True) self.items_by_id[item_id] = item items.append(item) @@ -241,13 +238,18 @@ class ActionModel(QtGui.QStandardItemModel): key=lambda action: (action.order, action.name) ) - def update_force_not_open_workfile_settings(self, is_checked, action): + def update_force_not_open_workfile_settings(self, is_checked, action_id): """Store/remove config for forcing to skip opening last workfile. Args: is_checked (bool): True to add, False to remove - action (ApplicationAction) + action_id (str) """ + action_item = self.items_by_id.get(action_id) + if not action_item: + return + + action = action_item.data(ACTION_ROLE) actual_data = self._prepare_compare_data(action) stored = self.launcher_registry.get_item("force_not_open_workfile") @@ -262,6 +264,16 @@ class ActionModel(QtGui.QStandardItemModel): self.launcher_registry.set_item("force_not_open_workfile", stored) self.launcher_registry._get_item.cache_clear() + self.change_action_item(action_item, is_checked) + + def change_action_item(self, item, checked): + """Modifies tooltip and sets if opening of last workfile forbidden""" + tooltip = item.data(QtCore.Qt.ToolTipRole) + if checked: + tooltip += " (Not opening last workfile)" + + item.setData(tooltip, QtCore.Qt.ToolTipRole) + item.setData(checked, FORCE_NOT_OPEN_WORKFILE_ROLE) def is_application_action(self, action): """Checks if item is of a ApplicationAction type diff --git a/openpype/tools/launcher/widgets.py b/openpype/tools/launcher/widgets.py index da9218e4ea..ae95e2e8d8 100644 --- a/openpype/tools/launcher/widgets.py +++ b/openpype/tools/launcher/widgets.py @@ -139,7 +139,14 @@ class ActionBar(QtWidgets.QWidget): view.clicked.connect(self.on_clicked) view.customContextMenuRequested.connect(self.on_context_menu) + self._context_menu = None + self._discover_on_menu = False + def discover_actions(self): + if self._context_menu is not None: + self._discover_on_menu = True + return + if self._animation_timer.isActive(): self._animation_timer.stop() self.model.discover() @@ -200,20 +207,29 @@ class ActionBar(QtWidgets.QWidget): if index.data(FORCE_NOT_OPEN_WORKFILE_ROLE): checkbox.setChecked(True) + action_id = index.data(ACTION_ID_ROLE) checkbox.stateChanged.connect( lambda: self.on_checkbox_changed(checkbox.isChecked(), - action_item)) + action_id)) action = QtWidgets.QWidgetAction(menu) action.setDefaultWidget(checkbox) menu.addAction(action) + self._context_menu = menu global_point = self.mapToGlobal(point) - _ = menu.exec_(global_point) + menu.exec_(global_point) + self._context_menu = None + if self._discover_on_menu: + self._discover_on_menu = False + self.discover_actions() - def on_checkbox_changed(self, is_checked, action): - self.model.update_force_not_open_workfile_settings(is_checked, action) - self.discover_actions() # repaint + def on_checkbox_changed(self, is_checked, action_id): + self.model.update_force_not_open_workfile_settings(is_checked, + action_id) + self.view.update() + if self._context_menu is not None: + self._context_menu.close() def on_clicked(self, index): if not index or not index.isValid():