def load(self): """ Load or reload the metadata file and populate the QListWidget. """ # remember the current selection old_selection = self._selection try: MetadataSelector.load(self) except Exception as e: print('Bad metadata file:', e) if self.all_metadata is not None: # clear and repopulate the list, # which triggers the selection to change self.clear() for label in _selector_labels(self.all_metadata): QT.QListWidgetItem(label, self) if old_selection in self.all_metadata: # reselect the original selection if it still exists self.setCurrentRow( list(self.all_metadata).index(old_selection)) else: # otherwise select the first item self.setCurrentRow(0)
def load(self): """ Load or reload the metadata file and populate the QListWidget. """ # remember the current selection old_selection = self._selection try: MetadataSelector.load(self) except Exception as e: logger.error(f'Bad metadata file\n{e}') self.mainwindow.statusBar().showMessage('ERROR: Bad metadata file ' '(see console for ' 'details)', msecs=5000) if self.all_metadata is not None: # clear and repopulate the list, # which triggers the selection to change self.clear() for label in _selector_labels(self.all_metadata): QT.QListWidgetItem(label, self) if old_selection in self.all_metadata: # reselect the original selection if it still exists self.setCurrentRow(list(self.all_metadata).index(old_selection)) else: # otherwise select the first item self.setCurrentRow(0)