def select_folders(self): ''' Select simulations by selecting one folder at a time and reading all input files inside of them. If simulations where selected, update the GUI through update_GUI(). Attributes ---------- selected_files: list of str Save the selected input files. ''' # Choose files and start selection in the standard run folder. title = "Select folder" selected_folders = [] selected_folders = askopendirnames(title=title, initialdir=self.initialdir["Folders"]) # Extract the files in the folder if selected_folders is not None: selected_folders = [ pathlib.Path(f) for f in selected_folders ] selected_files = get_filesInFolder(selected_folders, end=".in") # Update the GUI if selected_files is not None: if len(selected_files) != 0: self.root.input_files = list(set(self.root.input_files + selected_files)) update_GUI(self.root) return
def clear_simulations(self): ''' Remove all the selected simulations. Remove corresponding folder titles and input_files labels, crosses and checkmarks in the simulations labelFrame. Next update the GUI through update_GUI(). Attributes ---------- input_files: dict[folder][input_file] = tk.IntVar() Remove the input_files, fodlers and variables. widgets: dict['folder']['title', 'label', 'button', 'check'] = list of widgets; dict['folder']['var_lbl'] = list of tk.StringVar Destroy the widgets of each input_file, remove the widgets from the list and destroy the key in the dictionary. frame_folders: dict['folder'] = ttk.Frame(master=self.scrollableCanvas.scrollable_frame) Destroy the frames and remove them from the dictionary. ''' # Remove all the items from the tree view self.tree.delete(*self.tree.get_children()) self.tree_folders = [] # Remove the labels from the research frame self.root.tab_Simulations.class_research.clear_simulations() # Remove the input files self.root.input_files = [] # Update the GUI update_GUI(self.root) if True: return
def update_menu(self, i): if i == 1: self.folderIsExperiment = True if i == 2: self.folderIsExperiment = False if i == 3: self.openMenuToChooseKnobAndKey() if len(self.root.input_files) != 0 and i in [1, 2]: self.create_researchObject() update_GUI(self.root) return
def on_closing(*args): # Save the stella knob and key self.experiment_knob = self.var_knob.get() self.experiment_key = self.var_key.get() # Create a new research object if len(self.root.input_files) != 0: self.create_researchObject() update_GUI(self.root) # Close the window research_window.destroy()
def update_btn(x): # When an option is chosen from the popup menu, change the text on the button self.button_resolution.config(text=x) # Get the setting for ignoring the resolution if x == "Ignore resolution": self.ignore_resolution = True if x == "Include resolution": self.ignore_resolution = False # Remake the simulation object with the new setting self.create_researchObject() # Update the GUI update_GUI(self.root)
def load_research(self): print("LOAD RESEARCH") # Choose files and start selection in the standard run folder. title = "Select pickle file" filetypes = (("in files", "*.pickle"), ("all files", "*.*")) initialdir = CONFIG['PATHS']['stellapy'] + "/config/research/" selected_files = tk.filedialog.askopenfilenames(initialdir=initialdir, title=title, filetypes=filetypes) # Only continue if a file was selected if len(selected_files) > 0 and selected_files != None: # Remove the input_files that are displayed now self.root.tab_Simulations.class_simulations.clear_simulations() # Open the file with pickle pickly_file = open(selected_files[0], 'rb') self.root.Research = pickle.load(pickly_file) pickly_file.close() # Display the current input_files for experiment in self.root.Research.experiments: for simulation in experiment.simulations: self.root.input_files += simulation.input_files self.root.tab_Simulations.class_simulations.update_treeView() # Update the resolution button self.ignore_resolution = self.root.Research.ignore_resolution if self.ignore_resolution == True: x = "Ignore resolution" if self.ignore_resolution == False: x = "Include resolution" self.button_resolution.config(text=x) # Update the varied parameters button self.number_variedVariables = self.root.Research.number_variedVariables if self.number_variedVariables == -1: x = "No grouping" if self.number_variedVariables == 0: x = "0 varied parameters" if self.number_variedVariables == 1: x = "1 varied parameter" if self.number_variedVariables == 2: x = "2 varied parameters" if self.number_variedVariables == 3: x = "3 varied parameters" if self.number_variedVariables == 4: x = "4 varied parameters" if self.number_variedVariables == 5: x = "5 varied parameters" self.button_variedParam.config(text=x) # Remember the stella kob and key self.experiment_knob = self.root.Research.experiment_knob self.experiment_key = self.root.Research.experiment_key # Update the GUI update_GUI(self.root) return # Prevent the collapsing of the header comment on the next line if True: return
def update_btn2(x): # When an option is chosen from the popup menu, change the text on the button self.button_variedParam.config(text=x) # Get the setting for ignoring the resolution if x == "0 varied parameters": self.number_variedVariables = 0 if x == "1 varied parameter": self.number_variedVariables = 1 if x == "2 varied parameters": self.number_variedVariables = 2 if x == "3 varied parameters": self.number_variedVariables = 3 if x == "4 varied parameters": self.number_variedVariables = 4 if x == "5 varied parameters": self.number_variedVariables = 5 # Remake the simulation object with the new setting self.create_researchObject() # Update the GUI update_GUI(self.root)
def deleterow(self, event): '''Delete selected row''' # Get the information of the selected row if len(self.tree.selection()) != 0: rowiid_parent = self.tree.selection()[0] rowiids = self.tree.get_children(item=rowiid_parent) # Delete all the child notes if the selected row was a folder for rowiid in rowiids: # Get the values of the row values = list(self.tree.item(rowiid, 'values')) # Delete the selected row try: self.tree.delete(rowiid) except: pass # Delete the corresponding input file try: self.root.input_files.remove(pathlib.Path(values[1])) except: pass # Now delete the parent node values = list(self.tree.item(rowiid_parent, 'values')) # Delete the input file or the folder try: # Delete the corresponding input file self.root.input_files.remove(pathlib.Path(values[1])) except: # Detele the folder index = None for tree_folder in self.tree_folders: self.tree.selection_set(tree_folder) folder_iid = self.tree.selection()[0] if folder_iid == rowiid_parent: index = self.tree_folders.index(tree_folder) self.tree_folders.pop(index) # Delete the selected row try: self.tree.delete(rowiid_parent) except: pass # Update the GUI update_GUI(self.root) if True: return
def select_files(self): ''' Select simulations by choosing multiple files with the extension ".in". If simulations where selected, update the GUI through update_GUI(). Attributes ---------- selected_files: list of str Save the selected input files. ''' # Choose files and start selection in the standard run folder. title = "Select input file" filetypes = (("in files","*.in"),("all files","*.*")) selected_files = askopenfilenames(initialdir=self.initialdir["Files"],title=title,filetypes=filetypes) # Update the GUI if selected_files is not None: if len(selected_files) != 0: selected_files = [ pathlib.Path(i) for i in selected_files ] self.root.input_files = list(set(self.root.input_files + selected_files)) update_GUI(self.root) return