Skip to content

Commit

Permalink
Enable/disable Apply button depending on valid context selection
Browse files Browse the repository at this point in the history
  • Loading branch information
BigRoy committed Sep 18, 2019
1 parent c2e5d13 commit 2620c29
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions 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 Down Expand Up @@ -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"""

Expand Down

0 comments on commit 2620c29

Please sign in to comment.