Skip to content

Commit

Permalink
Bug Fix: UI refresh on reference update (#48)
Browse files Browse the repository at this point in the history
* Remove context menu executing flag
* Special event handling for Alias
* Sort the main file model by display role value.
* Bump minimum version for qtwidgets.
  • Loading branch information
staceyoue authored May 15, 2023
1 parent 9d8c505 commit b64393b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
26 changes: 21 additions & 5 deletions hooks/tk-alias_scene_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,17 @@ def update(self, item):
if node_type == "reference":
self.update_reference(path, extra_data, sg_data)

# Alias events triggered from any reference update will update the file data model
# Return False to indicate that the file data model does not need to perform an update
return False
try:
api_alias_version = alias_api.__alias_version__
major_version = int(api_alias_version.split(".")[0])
except:
major_version = -1

if major_version >= 2023:
# Alias events triggered from any reference update will update the file data model
# Return False to indicate that the file data model does not need to perform an update
return False
return True

def update_reference(self, path, extra_data, sg_data):
"""
Expand Down Expand Up @@ -219,12 +227,15 @@ def register_scene_change_callback(self, scene_change_callback):
# Define the list of Alias event to that will trigger the scene change callback.
events = [
alias_api.AlMessageType.PostRetrieve,
alias_api.AlMessageType.ReferenceFileDeleted,
alias_api.AlMessageType.StageActive,
]

# Alias event messages that are only available in version >= 2023.0
if hasattr(alias_api.AlMessageType, "ReferenceFileAdded"):
events.append(alias_api.AlMessageType.ReferenceFileAdded)
# Only add the deleted event if the added event is available - otherwise
# add/remove references doesn't work completely
events.append(alias_api.AlMessageType.ReferenceFileDeleted)

# Create the scene change callback to register with the Alias event watcher.
scene_change_cb = (
Expand All @@ -244,9 +255,14 @@ def register_scene_change_callback(self, scene_change_callback):
def unregister_scene_change_callback(self):
"""Unregister the scene change callbacks by disconnecting any signals."""

event_watcher = self.parent.engine.event_watcher
if not event_watcher:
# Engine already shutdown and removed event callbacks
return

# Unregister the event callbacks from the engine's event watcher
for callback, events in self.__alias_event_callbacks:
self.parent.engine.event_watcher.unregister_alias_callback(callback, events)
event_watcher.unregister_alias_callback(callback, events)

def __handle_event_callback(self, event_result, scene_change_callback):
"""
Expand Down
2 changes: 1 addition & 1 deletion info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ supported_engines:
# the frameworks required to run this app
frameworks:
- {"name": "tk-framework-shotgunutils", "version": "v5.x.x", "minimum_version": "v5.8.2"}
- {"name": "tk-framework-qtwidgets", "version": "v2.x.x", "minimum_version": "v2.10.5"}
- {"name": "tk-framework-qtwidgets", "version": "v2.x.x", "minimum_version": "v2.10.6"}
27 changes: 5 additions & 22 deletions python/tk_multi_breakdown2/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ def __init__(self, parent=None):
# retrieved async.
self._dynamic_loading = False

# Keep track of when a menu is executing. This is to avoid triggering unwanted DCC
# event callbacks when menu actions are executed.
self.__context_menu_executing = False

# create a single instance of the task manager that manages all
# asynchronous work/tasks
self._bg_task_manager = BackgroundTaskManager(self, max_threads=2)
Expand Down Expand Up @@ -183,6 +179,9 @@ def __init__(self, parent=None):
)

self._file_proxy_model = FileProxyModel(self)
self._file_proxy_model.setDynamicSortFilter(True)
self._file_proxy_model.setSortRole(QtCore.Qt.DisplayRole)
self._file_proxy_model.sort(0, QtCore.Qt.AscendingOrder)
self._file_proxy_model.setSourceModel(self._file_model)
self._ui.file_view.setModel(self._file_proxy_model)

Expand Down Expand Up @@ -803,12 +802,7 @@ def _show_context_menu(self, widget, pnt):
lambda: self._set_details_panel_visibility(True)
)
context_menu.addAction(show_details_action)

self.__context_menu_executing = True
try:
context_menu.exec_(pnt)
finally:
self.__context_menu_executing = False
context_menu.exec_(pnt)

def _show_history_item_context_menu(self, view, index, pos):
"""
Expand Down Expand Up @@ -861,12 +855,7 @@ def _show_history_item_context_menu(self, view, index, pos):

menu = QtGui.QMenu()
menu.addActions(actions)

self.__context_menu_executing = True
try:
menu.exec_(view.mapToGlobal(pos))
finally:
self.__context_menu_executing = False
menu.exec_(view.mapToGlobal(pos))

def _set_details_panel_visibility(self, visible):
"""
Expand Down Expand Up @@ -1000,12 +989,6 @@ def _scene_changed(self, event_type="reload", data=None):
:type data: str | dict
"""

if self.__context_menu_executing:
# Ignore DCC event callbacks that are triggered from executing a context menu
# action. If these actions do require an event callback, the action can manually
# execute the callback if needed. This is to avoid unwanted model reloads.
return

invalidate_filtering = False
is_reload = event_type == "reload"

Expand Down
3 changes: 3 additions & 0 deletions python/tk_multi_breakdown2/file_item_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ def data(self, index, role=QtCore.Qt.DisplayRole):
# It is a file item
file_item = model_item.file_item

if role == QtCore.Qt.DisplayRole:
return file_item.sg_data.get("name") or file_item.node_name

if role == QtCore.Qt.DecorationRole:
if not model_item.thumbnail_icon:
model_item.set_thumbnail(file_item.thumbnail_path)
Expand Down

0 comments on commit b64393b

Please sign in to comment.