def OnOpen(self, evt): """ File > Open handler """ filename = FileDialog( self.view, self.dialog_dirs, 'open', 'Select a calibration file to open', wildcard=WILDCARD_CALIB ) if (filename): success = self.model.load(filename) if not success: errmsg = "Warning: some errors were encountered while loading the calibration file:\n\n %s" % '\n '.join(self.model.load_errors) errdlg = wx.MessageDialog(self.view, errmsg, "Error", wx.OK | wx.ICON_WARNING) errdlg.ShowModal() errdlg.Destroy() self.model_to_view() self.UpdateView(self.UPDATE_EXPOSURES | self.UPDATE_FILTERS) if self.show_calibration_matrix: self.ShowCalibrationMatrix() self.CalibrationValid(True) self.Changed(False)
def OnExportXtals(self, evt): """ File > Export Crystals handler """ filename = FileDialog( self.view, self.dialog_dirs, 'xtals', 'Select file to export crystals to', wildcard=WILDCARD_XTAL_EXPORT, save=True ) if not filename: return if os.path.exists(filename): qdlg = wx.MessageDialog(self.view, "Overwrite File?", "Warning", wx.YES | wx.NO | wx.ICON_WARNING) ret = qdlg.ShowModal() qdlg.Destroy() if ret == wx.NO: return with open(filename, 'w') as f: f.write("# miniXS crystal boundaries\n") f.write("# x1\ty1\tx2\ty2\n") for (x1,y1),(x2,y2) in self.model.xtals: f.write("%d\t%d\t%d\t%d\n" % (x1,y1,x2,y2))
def OnSave(self, evt): """ File > Save handler """ header_only = False if self.calibration_valid == False: errdlg = wx.MessageDialog(self.view, "Warning: You have changed parameters since last calibrating. Saving now will only save the parameters, and not the matrix itself.", "Error", wx.OK | wx.CANCEL | wx.ICON_WARNING) ret = errdlg.ShowModal() errdlg.Destroy() if ret == wx.ID_OK: header_only = True else: return filename = FileDialog( self.view, self.dialog_dirs, 'save', 'Select file to save calibration to', wildcard=WILDCARD_CALIB, save=True ) if filename: self.view_to_model() self.model.save(filename, header_only=header_only) self.Changed(False)
def OnSave(self, evt): header_only = False filename = FileDialog(self.view, self.dialog_dirs, 'xes', 'Enter a filename to save to', wildcard=WILDCARD_DATA, save=True) if not filename: return # check if file exists if os.path.exists(filename): errdlg = wx.MessageDialog( self.view, "This will overwrite the file:\n%s" % filename, "Warning", wx.OK | wx.CANCEL | wx.ICON_WARNING) ret = errdlg.ShowModal() errdlg.Destroy() if ret != wx.ID_OK: return # save the file self.model.save(filename)
def OnAddExposures(self, evt): filenames = FileDialog(self.view, self.dialog_dirs, 'exposure', 'Select exposure file(s)', wildcard=WILDCARD_EXPOSURE, multiple=True) if not filenames: return invalid_files = [] for f in filenames: try: self.AppendExposure(f) except IOError: invalid_files.append(f) continue if invalid_files: errmsg = "The following files were not recognized:\n\n " + '\n '.join( invalid_files) errdlg = wx.MessageDialog(self.view, errmsg, "Error", wx.OK | wx.ICON_WARNING) errdlg.ShowModal() errdlg.Destroy()
def OnAddExposures(self, evt): filenames = FileDialog(self.view, self.dialog_dirs, 'exposure', 'Select exposure file(s)', wildcard=WILDCARD_EXPOSURE, multiple=True) if not filenames: return invalid_files = [] for f in filenames: try: e = mx.exposure.Exposure(f) except IOError: invalid_files.append(f) continue self.model.exposure_files.append(f) base = os.path.basename(f) self.view.exposure_listbox.AppendAndEnsureVisible(base) self.exposures.append(e) self.combined_exposure.load_multi(self.model.exposure_files) self.view.SetExposureCount(len(self.exposures)) if invalid_files: errmsg = "The following files were not recognized:\n\n " + '\n '.join( invalid_files) errdlg = wx.MessageDialog(self.view, errmsg, "Error", wx.OK | wx.ICON_WARNING) errdlg.ShowModal() errdlg.Destroy()
def OnImportXtals(self, evt): """ File > Import Crystals handler """ filename = FileDialog( self.view, self.dialog_dirs, 'xtals', 'Select file to import crystals from', wildcard=WILDCARD_XTAL, ) if not filename: return error = None t = filetype.determine_filetype(filename) if t == filetype.FILE_CALIBRATION: ci = Calibration() ci.load(filename, header_only=True) self.model.xtals = ci.xtals elif t == filetype.FILE_XTALS or t == filetype.FILE_UNKNOWN: data = None try: data = np.loadtxt(filename) self.model.xtals = [ [[x1,y1],[x2,y2]] for x1,y1,x2,y2 in data ] except ValueError: if data is not None: if len(data.shape) == 1: num = data.shape[0] else: num = data.shape[1] if num != 4: error = "Crystal file must contain 4 columns." else: error = "Invalid file." else: error = "Invalid file." else: error = "Invalid filetype." if error: print error errmsg = "Unable to load crystal boundaries:\n\n%s" % error errdlg = wx.MessageDialog(self.view, errmsg, "Error", wx.OK | wx.ICON_ERROR) errdlg.ShowModal() errdlg.Destroy() self.range_tool.rects = self.model.xtals self.view.image_view.Refresh() self.CalibrationValid(False) self.Changed()
def OnLoadScan(self, evt): filename = FileDialog( self.view, self.dialog_dirs, 'scan', 'Select a text file', wildcard=WILDCARD_SCAN ) if filename: self.scan_dialog.set_filename(filename)
def OnOpen(self, evt): filename = FileDialog(self.view, self.dialog_dirs, 'xes', 'Select an xes file to open', wildcard=WILDCARD_DATA) if not filename: return self.load(filename) self.UpdateImageView()
def OnOpen(self, evt): filename = FileDialog(self.view, self.dialog_dirs, 'xes', 'Select an xes file to open', wildcard=WILDCARD_XES) if not filename: return self.load(filename) self.SetViewMode(VIEW_MODE_SPECTRUM)
def OnLoadCalibration(self, evt): filename = FileDialog(self.view, self.dialog_dirs, 'calib', 'Select a calibration file to open', wildcard=WILDCARD_CALIB) if not filename: return self.SetCalibrationFilename(filename) if len(self.exposures) == 0: self.SetViewMode(VIEW_MODE_CALIB)
def OnSelectExposures(self, evt): filenames = FileDialog( self.view, self.dialog_dirs, 'exposures', 'Select Exposure Files', wildcard=WILDCARD_EXPOSURE, multiple=True ) if filenames is None: return for f in filenames: self.view.exposure_list.AppendExposure(f) self.UpdateView(self.UPDATE_EXPOSURES) self.CalibrationValid(False)
def OnSave(self, evt): header_only = False if self.spectrum_invalid == True: errdlg = wx.MessageDialog( self.view, "Warning: You have changed parameters since last processing the spectrum. Saving now will only save the parameters, and not the spectrum itself.", "Error", wx.OK | wx.CANCEL | wx.ICON_WARNING) ret = errdlg.ShowModal() errdlg.Destroy() if ret == wx.ID_OK: header_only = True else: return filename = FileDialog(self.view, self.dialog_dirs, 'xes', 'Enter a filename to save to', wildcard=WILDCARD_XES, save=True) if not filename: return # check if file exists if os.path.exists(filename): errdlg = wx.MessageDialog( self.view, "This will overwrite the file:\n%s" % filename, "Warning", wx.OK | wx.CANCEL | wx.ICON_WARNING) ret = errdlg.ShowModal() errdlg.Destroy() if ret != wx.ID_OK: return # save the file self.model.save(filename, header_only=header_only)