Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix context manager allowing to switch to 'No Task' #451

Merged
merged 2 commits into from
Sep 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion avalon/tools/contextmanager/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ def __init__(self, parent=None):
self._task_view = task_view
self._task_model = task_model
self._assets = assets
self._accept_button = accept_btn

self._context_asset = asset_label
self._context_task = task_label

assets.selection_changed.connect(self.on_asset_changed)
accept_btn.clicked.connect(self.on_accept_clicked)
task_view.selectionModel().selectionChanged.connect(
self.on_task_changed)
assets.assets_refreshed.connect(self.on_task_changed)
assets.refresh()

self.select_asset(api.Session["AVALON_ASSET"])
Expand All @@ -103,7 +107,16 @@ def refresh_context_view(self):
self._context_task.setText("Task: {}".format(task))

def _get_selected_task_name(self):
task_index = self._task_view.currentIndex()

# Make sure we actually get the selected entry as opposed to the
# active index. This way we know the task is actually selected and the
# view isn't just active on something that is unselectable like
# "No Task"
selected = self._task_view.selectionModel().selectedRows()
if not selected:
return

task_index = selected[0]
return task_index.data(QtCore.Qt.DisplayRole)

def _get_selected_asset_name(self):
Expand Down Expand Up @@ -131,6 +144,23 @@ def on_asset_changed(self):
if self._last_selected_task:
self.select_task(self._last_selected_task)

if not self._get_selected_task_name():
# If no task got selected after the task model reset
# then a "selection change" signal is not emitted.
# As such we need to explicitly force the callback.
self.on_task_changed()

def on_task_changed(self):
"""Callback on task change."""

# Toggle the "Accept" button enabled state
asset = self._get_selected_asset_name()
task = self._get_selected_task_name()
if not asset or not task:
self._accept_button.setEnabled(False)
else:
self._accept_button.setEnabled(True)

def on_accept_clicked(self):
"""Apply the currently selected task to update current task"""

Expand Down