Skip to content

Commit

Permalink
Make standalone app QListWidget a child of _MetadataSelectorQt
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgill86 committed Jan 3, 2021
1 parent 9ccc36c commit b037f98
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions neurotic/gui/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def __init__(self, file=None, initial_selection=None, lazy=True, theme='light',
# select a dataset if the user provided one
if initial_selection is not None:
try:
self.metadata_selector.setCurrentRow(list(self.metadata_selector.all_metadata).index(initial_selection))
self.metadata_selector.dataset_list.setCurrentRow(list(self.metadata_selector.all_metadata).index(initial_selection))
except (TypeError, ValueError) as e:
logger.error(f'Bad dataset key, will ignore: {e}')
self.statusBar().showMessage('ERROR: Bad dataset key, will '
Expand Down Expand Up @@ -721,9 +721,10 @@ def free_resources(self, i):
gc.collect()


class _MetadataSelectorQt(MetadataSelector, QT.QListWidget):
class _MetadataSelectorQt(MetadataSelector, QT.QWidget):
"""
A QListWidget that displays the state of a MetadataSelector.
A QWidget that displays the state of a MetadataSelector, providing a
QListWidget for selecting one dataset.
"""

def __init__(self, mainwindow):
Expand All @@ -732,18 +733,24 @@ def __init__(self, mainwindow):
"""

MetadataSelector.__init__(self)
QT.QListWidget.__init__(self, parent=mainwindow)
QT.QWidget.__init__(self, parent=mainwindow)

self.mainwindow = mainwindow

self.setSelectionMode(QT.QListWidget.SingleSelection)
self.layout = QT.QVBoxLayout()
self.setLayout(self.layout)

font = self.font()
self.dataset_list = QT.QListWidget(self)
self.layout.addWidget(self.dataset_list)

self.dataset_list.setSelectionMode(QT.QListWidget.SingleSelection)

font = self.dataset_list.font()
font.setFamily('Courier')
self.setFont(font)
self.dataset_list.setFont(font)

self.currentRowChanged.connect(self._on_select)
self.itemDoubleClicked.connect(self.mainwindow.start_launch)
self.dataset_list.currentRowChanged.connect(self._on_select)
self.dataset_list.itemDoubleClicked.connect(self.mainwindow.start_launch)

def _on_select(self, currentRow):
"""
Expand Down Expand Up @@ -776,16 +783,16 @@ def load(self):

# clear and repopulate the list,
# which triggers the selection to change
self.clear()
self.dataset_list.clear()
for label in _selector_labels(self.all_metadata):
QT.QListWidgetItem(label, self)
QT.QListWidgetItem(label, self.dataset_list)

if old_selection in self.all_metadata:
# reselect the original selection if it still exists
self.setCurrentRow(list(self.all_metadata).index(old_selection))
self.dataset_list.setCurrentRow(list(self.all_metadata).index(old_selection))
else:
# otherwise select the first item
self.setCurrentRow(0)
self.dataset_list.setCurrentRow(0)


class _DownloadWorker(QT.QObject):
Expand Down

0 comments on commit b037f98

Please sign in to comment.