Example #1
0
    def openDetector(self):
        # initialize epics mca
        detector = self.defaults_options.detector
        text, ok = QInputDialog.getText(self.widget,
                                        'EPICS MCA',
                                        'Enter MCA PV name: ',
                                        text=detector)

        if ok:
            mcaTemp = self.mca
            status = self.initMCA('epics', text)
            if status == 0:
                if self.controllers_initialized == False:
                    status = self.initControllers()
                if status == 0:
                    self.data_updated()
                    acquiring = self.mca.get_acquire_status()
                    self.mca.dataAcquired.signal.connect(
                        self.dataReceivedEpics)
                    self.mca.acq_stopped.signal.connect(
                        self.file_save_controller.acq_stopped)
                    if acquiring == 1:
                        self.mca.acqOn()
                    elif acquiring == 0:
                        self.mca.acqOff()
                    self.update_titlebar()
                    self.defaults_options.detector = text
                    try:
                        mcaUtil.save_defaults_settings(self.defaults_options)
                    except:
                        pass
            else:
                self.mca = mcaTemp
                mcaUtil.displayErrorMessage('init')
Example #2
0
 def openFile(self, *args, **kwargs):
     filename = kwargs.get('filename', None)
     if filename is None:
         filename = open_file_dialog(
             self.widget, "Open spectrum file.",
             self.mca_controller.working_directories.savedata)
     if filename != '' and filename is not None:
         if os.path.isfile(filename):
             if self.mca_controller.Foreground != 'file':
                 success = self.mca_controller.initMCA('file',
                                                       filename) == 0
             else:
                 [filename, success
                  ] = self.mca_controller.mca.read_file(file=filename,
                                                        netcdf=0,
                                                        detector=0)
             if success:
                 self.mca_controller.working_directories.savedata = os.path.dirname(
                     str(filename))  #working directory xrd files
                 mcaUtil.save_folder_settings(
                     self.mca_controller.working_directories)
                 # best to initialize controllers only once per session
                 if not self.mca_controller.controllers_initialized:
                     self.mca_controller.initControllers()
                 self.mca_controller.data_updated()
             else:
                 mcaUtil.displayErrorMessage('fr')
         else:
             mcaUtil.displayErrorMessage('fr')
Example #3
0
 def calibrate_energy_module(self):
     if self.mca != None:
         self.ce = mcaCalibrateEnergy(self.mca)
         if self.ce.nrois < 2:
             mcaUtil.displayErrorMessage('calroi')
             self.ce.destroy()
         else:
             self.ce.raise_widget()
Example #4
0
 def calibrate_tth_module(self):
     if self.mca != None:
         phase = self.working_directories.phase
         self.ctth = mcaCalibrate2theta(self.mca, jcpds_directory=phase)
         if self.ctth.nrois < 1:
             mcaUtil.displayErrorMessage('calroi')
             self.ctth.destroy()
         else:
             self.ctth.raise_widget()
Example #5
0
    def saveFile(self, filename):
        if self.mca_controller.mca != None:
            exists = os.path.isfile(filename)
            if not exists:
                write = True
            else:
                if os.access(filename, os.R_OK):
                    base = os.path.basename(filename)
                    if self.file_options.warn_overwrite:
                        choice = QtWidgets.QMessageBox.question(
                            None, 'Confirm Save As', base +
                            " already exists. \nDo you want to replace it?",
                            QtWidgets.QMessageBox.Yes
                            | QtWidgets.QMessageBox.No)
                        write = choice == QtWidgets.QMessageBox.Yes
                    else:
                        write = True
                else:
                    write = False
            if write:
                fileout, success = self.mca_controller.mca.write_file(
                    file=filename, netcdf=0)
                if success:
                    #self.update_titlebar()
                    self.update_epics_filename()

                    self.mca_controller.working_directories.savedata = os.path.dirname(
                        str(fileout))  # working directory xrd files
                    mcaUtil.save_folder_settings(
                        self.mca_controller.working_directories)
                    new_file = increment_filename(filename)
                    if new_file != filename:
                        self.widget.actionSave_next.setText(
                            'Save next: ' + os.path.basename(new_file))
                        self.widget.actionSave_next.setEnabled(True)
                    else:
                        self.widget.actionSave_next.setText('Save next')
                        self.widget.actionSave_next.setEnabled(False)
                else:
                    mcaUtil.displayErrorMessage('fs')
            else:
                mcaUtil.displayErrorMessage('fs')
    def save_config(self, filename):
        params_out = copy.copy(self.model.params)
        peaks = self.files_controller.spectra_model.get_cut_peaks()
        file_use = self.files_controller.get_file_use()
        params_out['mcadata_use'] = file_use
        params_out['E_cut'] = peaks
        mcadata = self.files_controller.spectra_model.get_file_list()
        params_out['mcadata'] = mcadata

        options_out = json_compatible_dict(params_out)
        try:
            with open(filename, 'w') as outfile:
                json.dump(options_out, outfile, sort_keys=True, indent=4)
                outfile.close()
            self.model.set_config_file(filename)
            self.loaded_params = copy.copy(params_out)
            self.file_loaded_or_saved.emit()
            return 0

        except:
            displayErrorMessage('opt_save')
            return 1
    def set_params(self, set_params):
        self.current_tth = None
        file_groups = set_params['mcadata']

        if 'mcadata_use' in set_params:
            file_use = set_params['mcadata_use']
        else:
            file_use = []
        inputdatadirectory = self.model.params['inputdatadirectory']

        directory = self.check_if_files_exist(inputdatadirectory, file_groups)

        if directory is not None:
            self.spectra_model.inputdatadirectory = directory
            self.spectra_model.load_files_from_config(file_groups, file_use)
            self.model.params['inputdatadirectory'] = directory
            self.files_loaded_callback()
            self.update_files_widget()
            self.peak_cut_controller.load_peaks_from_config()
            self.emit_spectra()
        else:
            if len(file_groups):
                displayErrorMessage('opt_read')
 def load_config_file(self, *args, **kwargs):
     filename = kwargs.get('filename', None)
     if filename is not None:
         if not os.path.exists(filename):
             filename = None
     if filename is None:
         filename = open_file_dialog(None, "Open config file.")
     if filename:
         config_file = filename
         self.model.set_config_file(config_file)
         try:
             self.model.cofigure_from_file()
         except:
             pass
         if self.model.configured:
             self.undo_params = {}
             mp = self.model.params
             self.loaded_params = copy.copy(mp)
             self.configure_components(mp)
             self.file_loaded_or_saved.emit()
             #self.back_up_config()
         else:
             displayErrorMessage('opt_read')