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

Do not block on opening catalogs #27

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions bluesky_widgets/components/search/searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ def enter(self, name):
old = self._root_catalog
new = old[name]

# Touch an attribute that will trigger a connection attempt. (It's here
# Access an entry to trigger a connection attempt. (It's here
# that an error would be raised if, say, a database is unreachable.)
new.metadata
next(new.items())

# If we get this far, it worked.
self._subcatalogs.append(new)
Expand Down
46 changes: 27 additions & 19 deletions bluesky_widgets/qt/searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)
from .search_input import QtSearchInput
from .search_results import QtSearchResults
from .threading import create_worker

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -46,9 +47,7 @@ def __init__(self, model, *args, **kwargs):
self._back_button.clicked.connect(model.go_back)

# Hook up model Events to Qt Slots.
self.model.events.enter.connect(self.on_enter)
self.model.events.go_back.connect(self.on_go_back)
self.model.events.run_search_ready.connect(self.on_run_search_ready)
self.model.events.run_search_cleared.connect(self.on_run_search_cleared)

self._selector_widgets = [] # QComboBoxes
Expand All @@ -68,26 +67,40 @@ def __init__(self, model, *args, **kwargs):
# box.
self._initialize_selector(list(model.current_catalog))

def on_enter(self, event=None):
"We are entering a subcatalog."
names = list(event.catalog)
self._initialize_selector(names)
self._back_button.setEnabled(True)

def _initialize_selector(self, names):
"Create a combobox to select from subcatalogs."
selector = QtSubcatalogSelector(names)
self._selector_widgets.append(selector)

def on_selection(index):
name = names[index]
try:
self.model.enter(name)
except Exception:
logger.exception("Failed to select %r", name)
selector.setEnabled(False)

def on_errored(err):
logger.exception("Failed to select %r", name, exc_info=err)
# Reset the combobox selection to an empty value and enable it.
selector.setCurrentIndex(-1)
else:
selector.setEnabled(False)
selector.setEnabled(True)

def on_success(return_value):
# return_value is None
if self.model.run_search is None:
# We have a Catalog of Catalogs.
names = list(self.model.current_catalog)
self._initialize_selector(names)
else:
# We have a Catalog of Runs.
self._initialize_run_search(
self.model.run_search.search_input,
self.model.run_search.search_results
)
self._back_button.setEnabled(True)

create_worker(
self.model.enter,
name,
_connect={"errored": on_errored, "returned": on_success}
)

selector.activated.connect(on_selection)
self.layout().addWidget(selector)
Expand All @@ -106,11 +119,6 @@ def on_go_back(self, event):
# This is the last widget. Disable back button.
self._back_button.setEnabled(False)

def on_run_search_ready(self, event):
"We have a catalog of Runs."
self._initialize_run_search(event.search_input, event.search_results)
self._back_button.setEnabled(True)

def _initialize_run_search(self, search_input, search_results):
"Create search input and output for a catalog of Runs."
# Create run search widgets and stash them as state for removal later.
Expand Down