def __init__(self, file=None, initial_selection=None, lazy=True, theme='light', support_increased_line_width=False, show_datetime=False): """ Initialize a new MainWindow. """ QT.QMainWindow.__init__(self) self.setWindowIcon(QT.QIcon(':/neurotic-logo-150.png')) self.setWindowTitle('neurotic') self.resize(600, 300) # lazy loading using Neo RawIO self.lazy = lazy # available themes are 'light', 'dark', and 'original' self.theme = theme # support_increased_line_width=True eliminates the extremely poor # performance associated with TraceViewer's line_width > 1.0, but it # also degrades overall performance somewhat and uses a mode of # pyqtgraph that is reportedly unstable self.support_increased_line_width = support_increased_line_width # show_datetime=True will display the real-world date and time next to # the in-file time, but this may be inaccurate for several reasons, # e.g. if data acquisition was paused and continued after some delay or # if an AxoGraph chart was not started immediately after creation self.show_datetime = show_datetime # windows are appended to this list so that they persist after the # function that spawned them returns self.windows = [] # metadata selector self.metadata_selector = _MetadataSelectorQt() self.setCentralWidget(self.metadata_selector) # create a worker thread for downloading data self.download_thread = QT.QThread() self.download_worker = _DownloadWorker(self.metadata_selector) self.download_worker.moveToThread(self.download_thread) self.request_download.connect(self.download_worker.download) self.download_worker.download_finished.connect( self.on_download_finished) # construct the menus self.create_menus() # open metadata file if file is not None: # try the user-specified file self.metadata_selector.file = file self.metadata_selector.load() if self.metadata_selector.all_metadata is None: # use an example metadata file if the user-specified file failed to # load or one was not provided self.metadata_selector.file = pkg_resources.resource_filename( 'neurotic', 'example/metadata.yml') self.metadata_selector.load() # 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)) except (TypeError, ValueError) as e: print('Bad dataset key, will ignore:', e)
def __init__(self, file=None, initial_selection=None, lazy=True, theme='light', ui_scale='medium', support_increased_line_width=False, show_datetime=False): """ Initialize a new MainWindow. """ QT.QMainWindow.__init__(self) self.setWindowIcon(QT.QIcon(':/neurotic-logo-150.png')) self.setWindowTitle('neurotic') self.resize(600, 300) self.statusBar() # lazy loading using Neo RawIO self.lazy = lazy if theme not in available_themes: logger.error(f'theme "{theme}" is unrecognized') raise ValueError(f'theme "{theme}" is unrecognized') self.theme = theme if ui_scale not in available_ui_scales: logger.error(f'ui scale "{ui_scale}" is unrecognized') raise ValueError(f'ui scale "{ui_scale}" is unrecognized') self.ui_scale = ui_scale self.default_font_size = QT.QFont().pointSize() # support_increased_line_width=True eliminates the extremely poor # performance associated with TraceViewer's line_width > 1.0, but it # also degrades overall performance somewhat and uses a mode of # pyqtgraph that is reportedly unstable self.support_increased_line_width = support_increased_line_width # show_datetime=True will display the real-world date and time next to # the in-file time, but this may be inaccurate for several reasons, # e.g. if data acquisition was paused and continued after some delay or # if an AxoGraph chart was not started immediately after creation self.show_datetime = show_datetime # windows are appended to this list so that they persist after the # function that spawned them returns self.windows = [] # metadata selector self.metadata_selector = _MetadataSelectorQt(self) # loading label self.loading_label = QT.QLabel('Launching, please wait...') self.loading_label.setFrameStyle(QT.QFrame.Panel | QT.QFrame.Sunken) self.loading_label.setAlignment(QT.Qt.AlignCenter) # gdrive auth flow label self.gdrive_auth_label = QT.QLabel('Continue Google Drive authorization\nin your web browser') self.gdrive_auth_label.setFrameStyle(QT.QFrame.Panel | QT.QFrame.Sunken) self.gdrive_auth_label.setAlignment(QT.Qt.AlignCenter) # initially stack the metadata selector above the loading label self.stacked_layout = QT.QStackedLayout() self.stacked_layout.addWidget(self.metadata_selector) # index 0 self.stacked_layout.addWidget(self.loading_label) # index 1 self.stacked_layout.addWidget(self.gdrive_auth_label) # index 2 central_widget = QT.QWidget() central_widget.setLayout(self.stacked_layout) self.setCentralWidget(central_widget) # create a worker thread for network activity (e.g., downloading data) self.network_thread = QT.QThread() self.network_worker = _NetworkWorker(self) self.network_worker.moveToThread(self.network_thread) # set up the network thread to perform data downloads self.request_download.connect(self.network_worker.download) self.network_worker.download_finished.connect(self.on_download_finished) # set up the network thread to perform checks for updates self.request_check_for_updates.connect(self.network_worker.get_latest_release_number) self.network_worker.version_check_finished.connect(self.on_version_check_finished) # set up the network thread to run the Google Drive authorization flow self.request_gdrive_authorization.connect(self.network_worker.authorize_gdrive) self.network_worker.gdrive_authorization_finished.connect(self.on_gdrive_authorization_finished) # create a worker thread for loading datasets self.load_dataset_thread = QT.QThread() self.load_dataset_worker = _LoadDatasetWorker(self) self.load_dataset_worker.moveToThread(self.load_dataset_thread) self.request_load_dataset.connect(self.load_dataset_worker.load_dataset) self.load_dataset_worker.load_dataset_finished.connect(self.on_load_dataset_finished) self.load_dataset_worker.show_status_msg.connect(self.statusBar().showMessage) self.blk = None # construct the menus self.create_menus() # open metadata file if file: # try the user-specified file self.metadata_selector.file = file self.metadata_selector.load() if self.metadata_selector.all_metadata is None: # use an example metadata file if the user-specified file failed to # load or one was not provided self.metadata_selector.file = pkg_resources.resource_filename('neurotic', 'example/metadata.yml') self.metadata_selector.load() # select a dataset if the user provided one if initial_selection: try: self.metadata_selector.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 ' 'ignore', msecs=5000)