def event_left_dclick(self, event): """Handle the left mouse double click. @param event: The wx event. @type event: wx event """ # The row and column. col = self.grid.GetGridCursorCol() row = self.grid.GetGridCursorRow() # File selection. if col == 0: # The dialog. dialog = RelaxFileDialog(parent=self, style=wx.FD_OPEN) # Show the dialog and catch if no file has been selected. if status.show_gui and dialog.ShowModal() != wx.ID_OK: # Don't do anything. return # The files. filename = dialog.get_file() # Set the file name. self.grid.SetCellValue(row, col, str(filename)) # Skip the event to allow for normal operation. event.Skip()
def load_delay(self, event, vc=False): """The variable delay list loading GUI element. @param event: The wx event. @type event: wx event """ # VD # VC time is not a number if vc: try: vc_factor = float(self.vc_time.GetValue()) except: error_message('VC time is not a number.') return # VD else: vc_factor = 1 # The dialog. dialog = RelaxFileDialog(parent=self, style=wx.FD_OPEN) # Show the dialog and catch if no file has been selected. if status.show_gui and dialog.ShowModal() != wx.ID_OK: # Don't do anything. return # The files. filename = dialog.get_file() # Open the file file = open(filename, 'r') # Read entries index = 0 for line in file: # Evaluate if line is a number try: t = float(line.replace('/n', '')) except: continue # Write delay to peak list grid self.grid.SetCellValue(index, 1, str(t*vc_factor)) # Next peak list index = index + 1 # Too many entries in VD list if index == self.num_rows: error_message('Too many entries in list.') return
def load_peaklist(self, event): """Function to load peak lists to data grid. @param event: The wx event. @type event: wx event """ # The dialog. dialog = RelaxFileDialog(parent=self, message='Select the %s peak list file' % self.label, style=wx.FD_OPEN | wx.FD_MULTIPLE) # Show the dialog and catch if no file has been selected. if status.show_gui and dialog.ShowModal() != wx.ID_OK: # Don't do anything. return # The files. files = dialog.get_file() # Fill values in data grid index = 0 for i in range(self.num_rows): # Add entry if nothing is filled in already if str(self.grid.GetCellValue(i, 0)) == '': # Write peak file self.grid.SetCellValue(i, 0, str(files[index])) # Next file index = index + 1 # Stop if no files left if index == len(files): break # Error message if not all files were loaded if index < (len(files) - 1): error_message('Not all files could be loaded.')
def action_state_save_as(self, event=None): """Save the program state with file name selection. @keyword event: The wx event. @type event: wx event """ # The dialog. dialog = RelaxFileDialog(parent=self, message='Select the relax save state file', defaultFile='state.bz2', wildcard='relax save file (*.bz2)|*.bz2', style=wx.FD_SAVE) # Show the dialog and catch if no file has been selected. if status.show_gui and dialog.ShowModal() != wx.ID_OK: # Don't do anything. return # The file. file_name = dialog.get_file() # Set the file name. self.save_file = file_name # Save. self.state_save()
def load_peaklist(self, event): """Function to load peak lists to data grid. @param event: The wx event. @type event: wx event """ # The dialog. dialog = RelaxFileDialog(parent=self, message='Select the %s peak list file'%self.label, style=wx.FD_OPEN|wx.FD_MULTIPLE) # Show the dialog and catch if no file has been selected. if status.show_gui and dialog.ShowModal() != wx.ID_OK: # Don't do anything. return # The files. files = dialog.get_file() # Fill values in data grid index = 0 for i in range(self.num_rows): # Add entry if nothing is filled in already if str(self.grid.GetCellValue(i, 0)) == '': # Write peak file self.grid.SetCellValue(i, 0, str(files[index])) # Next file index = index + 1 # Stop if no files left if index == len(files): break # Error message if not all files were loaded if index < (len(files)-1): error_message('Not all files could be loaded.')
def state_load(self, event=None, file_name=None): """Load the program state. @keyword event: The wx event. @type event: wx event @keyword file_name: The name of the file to load (for dialogless operation). @type file_name: str """ # Execution lock. if status.exec_lock.locked(): return # Warning. if not self.analysis.init_state or not ds.is_empty(): # The message. msg = "Loading a saved relax state file will cause all unsaved data to be lost. Are you sure you would to open a save file?" # The dialog. if status.show_gui and Question(msg, default=True, size=(400, 150)).ShowModal() == wx.ID_NO: return # Open the dialog. if not file_name: dialog = RelaxFileDialog(parent=self, message='Select the relax save state file', defaultFile='state.bz2', wildcard='relax save files (*.bz2;*.gz)|*.bz2;*.gz|All files (*)|*', style=wx.FD_OPEN) # Show the dialog and catch if no file has been selected. if status.show_gui and dialog.ShowModal() != wx.ID_OK: # Don't do anything. return # The file. file_name = gui_to_str(dialog.get_file()) # Yield to allow the cursor to be changed. wx.Yield() # Change the cursor to waiting, and freeze the GUI. wx.BeginBusyCursor() self.Freeze() # Make sure the GUI returns to normal if a failure occurs. try: # Delete the current tabs. self.analysis.delete_all() # Reset the relax data store. reset() # The new save file name. self.save_file = file_name # Load the relax state. if protected_exec(state.load_state, file_name, verbosity=0): # Update the core of the GUI to match the new data store. self.sync_ds(upload=False) # File loading failure. else: # Reset relax to clear any partially loaded data. reset() # Reinitialise the GUI data store structure. self.init_data() # Reset the cursor, and thaw the GUI. finally: self.Thaw() # Turn off the busy cursor. if wx.IsBusy(): wx.EndBusyCursor()