def LoadWorkspace(self): # On "Import Workspace" load JSON and generate tab objects in tab_list. file_path = QtWidgets.QFileDialog.getOpenFileName( self, 'Import Workspace', os.getcwd() + "/" + self.workspace_file, "JSON (*.json)") try: with open(file_path[0]) as fd: # Remove any old tabs. Clean slate. for i in reversed(range(self.tabs.count())): self.tabs.removeTab(i) self.tab_list.clear() # Generate new tabs. tab_data = json.load(fd) for tab, groups in tab_data.items(): new_tab = Tab(tab, self.play_slider) new_tab.add_plots(groups) new_tab.render_multiplot() self.tabs.addTab(new_tab.get_tab_widget(), new_tab.get_title()) self.tab_list.append(new_tab) self.workspace_file = os.path.split(file_path[0])[1] except Exception: pass # Display data immediately upon upload if MDF already uploaded. self.render_graphs()
def generateTab(self): self.error_window = QtWidgets.QErrorMessage() error_count = 0 message = "" tab_idx = -1 # Check empty fields. if self.title.text() == "": error_count += 1 message += "ERROR {}: You must enter a title.".format(error_count) if len(self.added_dict) == 0: error_count += 1 message += "ERROR {}: You must apply at least one signal.".format( error_count) # Check if tab name unique. If no check if intent is to edit, if self.title.text() in [ tab.get_title() for tab in self.main.tab_list ]: if self.edit == True: tab_idx = [ idx if self.title.text() == tab.get_title() else -1 for idx, tab in enumerate(self.main.tab_list) ] tab_idx = tab_idx[0] else: error_count += 1 message += "ERROR {}: Tab title \"{}\" is already taken.".format( error_count, self.title.text()) # If errors then present else add tab to main window and close. if error_count > 0: self.error_window.showMessage(message) else: newTab = Tab(self.title.text(), self.main.play_slider) newTab.add_plots(self.added_dict) newTab.render_multiplot() # If editing delete old tab and replace with new at same index. Else append. if tab_idx != -1: self.main.tabs.removeTab(tab_idx) self.main.tabs.insertTab(tab_idx, newTab.get_tab_widget(), newTab.get_title()) self.main.tab_list.pop(tab_idx) self.main.tab_list.insert(tab_idx, newTab) else: self.main.tabs.addTab(newTab.get_tab_widget(), newTab.get_title()) self.main.tab_list.append(newTab) self.main.render_graphs() self.close()