From c2e5d13e31b8b52c0fbf7a2561ce45e32c386c47 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 18 Sep 2019 17:10:00 +0200 Subject: [PATCH 1/2] Fix context manager allowing to "switch" to 'No Task' --- avalon/tools/contextmanager/app.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/avalon/tools/contextmanager/app.py b/avalon/tools/contextmanager/app.py index c0512f9d9..aa1c33133 100644 --- a/avalon/tools/contextmanager/app.py +++ b/avalon/tools/contextmanager/app.py @@ -103,7 +103,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): From 2620c2909a4943381e0a3f1c9aa99dc7f96be16b Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 18 Sep 2019 17:56:16 +0200 Subject: [PATCH 2/2] Enable/disable Apply button depending on valid context selection --- avalon/tools/contextmanager/app.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/avalon/tools/contextmanager/app.py b/avalon/tools/contextmanager/app.py index aa1c33133..07b53f2db 100644 --- a/avalon/tools/contextmanager/app.py +++ b/avalon/tools/contextmanager/app.py @@ -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"]) @@ -140,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"""