Skip to content

Commit

Permalink
Merge pull request #451 from BigRoy/fix_switch_to_no_task
Browse files Browse the repository at this point in the history
Fix context manager allowing to switch to 'No Task'
  • Loading branch information
davidlatwe authored Sep 19, 2019
2 parents c000ac5 + 2620c29 commit fbd00ad
Showing 1 changed file with 31 additions and 1 deletion.
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

0 comments on commit fbd00ad

Please sign in to comment.