mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
OP-1117 - updated setting of state on action item
Updated handling of menu display and repaint
This commit is contained in:
parent
90642a191e
commit
f6ccc6aee1
3 changed files with 41 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue