def openSource(self, sourcename, specsession=None): if specsession is None: if sourcename in sps.getspeclist(): specsession=True else: specsession=False self.openFile(sourcename, specsession=specsession)
def openSource(self, sourcename, specsession=None): if specsession is None: if sourcename in sps.getspeclist(): specsession = True elif BLISS and sourcename in RedisTools.get_sessions_list(): specsession = "bliss" else: specsession = False self.openFile(sourcename, specsession=specsession)
def openSpec(self): speclist = sps.getspeclist() if not len(speclist): qt.QMessageBox.information(self, "No SPEC Shared Memory Found", "No shared memory source available") return if QTVERSION < "4.0.0": print("should I keep Qt3 version?") return menu = qt.QMenu() for spec in speclist: if hasattr(qt, "QString"): menu.addAction(qt.QString(spec), lambda i=spec: self.openFile(i, specsession=True)) else: menu.addAction(spec, lambda i=spec: self.openFile(i, specsession=True)) menu.exec_(self.cursor().pos())
def SetSource (self,source_name=None): """ Sets a new source for data retrieving, an spec version. If spec exists, self.Source will be this spec name. Parameters: source_name: name of spec version """ if source_name==self.SourceName: return 1 if (source_name != None) and (source_name in sps.getspeclist()): self.SourceName=source_name self.Source=self.SourceName return 1 else: self.SourceName=None self.Source=None return 0
def openSpec(self): speclist = sps.getspeclist() if not len(speclist): qt.QMessageBox.information(self, "No SPEC Shared Memory Found", "No shared memory source available") return menu = qt.QMenu() for spec in speclist: if hasattr(qt, "QString"): menu.addAction(qt.QString(spec), lambda i=spec:self.openFile(i, specsession=True)) else: menu.addAction(spec, lambda i=spec:self.openFile(i, specsession=True)) menu.exec_(self.cursor().pos())
def __RefreshPageOrig (source_obj,self,page): """ Virtual method, implements seeking for changes in data. Returns non-zero if the page was changed. If not implemented in the derived class, this class doesn't support dinamic changes monitoring. As pages can be copied to different Data objects, and can store the original RefreshPage method for updating, source_obj refers to the object that was origin of the page data, while self indicates the object that actually owns the page with index page. It was done this way because if it is stored the reference to the unbound method, python doesn't allow you to call it with an object of different data type. Important: Derived classes shall update the page: self.Pages[page] but not: source_obj.Pages[page] """ if (self.GetItemPageInfo("SourceType",page)==SOURCE_TYPE): specname=self.GetItemPageInfo("SourceName",page) arrayname=self.GetItemPageInfo("Key",page) updatecounter=self.GetItemPageInfo("updatecounter",page) if (updatecounter!=None) and (arrayname!=None) and (specname!=None): if specname in sps.getspeclist(): if arrayname in sps.getarraylist(specname): counter=sps.updatecounter (specname,arrayname) if (counter != updatecounter): info=self.GetPageInfo(page) info.update(self.__GetArrayInfo(arrayname)) if info["row"]!="ALL": data= sps.getdatarow(specname,arrayname,info["row"]) elif info["col"]!="ALL": data= sps.getdatacol(specname,arrayname,info["col"]) else: data=sps.getdata (specname,arrayname) self.Pages[page].Array=data return 1 infoname= self.GetItemPageInfo("EnvKey") infoupdc= self.GetItemPageInfo("env_updatecounter") if (infoupdc!=None) and (infoname!=None) and (specname!=None): if infoname in sps.getarraylist(specname): counter= sps.updatecounter(specname,infoname) if (counter!=infoupdc): info= self.GetPageInfo(page) info.update(self.__GetArrayInfo(arrayname)) return 1 return 0
def LoadSource(self,key_list="ALL",append=0,invalidate=1,row="ALL",col="ALL"): """ Creates a given number of pages, getting data from the actual source (set by SetSource) Parameters: key_list: list of all keys to be read from source. It is a list of string, shared memory array names, to be read from the file. It can be also one single string, if only one array is to be read. append: If non-zero appends to the end of page list. Otherwise, initializes the page list invalidate: if non-zero performas an invalidade call after loading row: If set to an integer, loads a single row (0-based indexed) col: If set to an integer, loads a single column (0-based indexed) """ #AS if append==0: Data.Delete(self) if type(key_list) == type(" "): key_list=(key_list,) output =[] if self.SourceName in sps.getspeclist(): if key_list == "ALL": key_list = sps.getarraylist(self.SourceName) for array in key_list: if array in sps.getarraylist(self.SourceName): info = self.__GetArrayInfo(array) info["row"] = row info["col"] = col if info["row"]!="ALL": data= sps.getdatarow(self.SourceName, array,info["row"]) if data is not None: data=numpy.reshape(data,(1, data.shape[0])) elif info["col"]!="ALL": data= sps.getdatacol(self.SourceName, array, info["col"]) if data is not None: data=numpy.reshape(data, (data.shape[0], 1)) else: data=sps.getdata (self.SourceName, array) #self.AppendPage(info,data) output.append([info,data]) if len(output) == 1: return output[0] else: return output
def getDataObject(self, key_list, selection=None): if type(key_list) != types.ListType: nolist = True key_list = [key_list] else: output = [] nolist = False if self.name in sps.getspeclist(): sourcekeys = self.getSourceInfo()['KeyList'] for key in key_list: #a key corresponds to an array name if key not in sourcekeys: raise KeyError("Key %s not in source keys" % key) #array = key #create data object data = DataObject.DataObject() data.info = self.__getArrayInfo(key) data.info['selection'] = selection data.data = sps.getdata(self.name, key) if nolist: if selection is not None: scantest = (data.info['flag'] & sps.TAG_SCAN) == sps.TAG_SCAN if ((key in ["SCAN_D"]) or scantest) \ and 'cntlist' in selection: data.x = None data.y = None data.m = None if 'nopts' in data.info: nopts = data.info['nopts'] elif 'nopts' in data.info['envdict']: nopts = int(data.info['envdict']['nopts']) + 1 else: nopts = data.info['rows'] if not 'LabelNames' in data.info: data.info['LabelNames'] =\ selection['cntlist'] * 1 newMemoryProblem = len(data.info['LabelNames']) != len(selection['cntlist']) # check the current information is up-to-date # (new HKL handling business) actualLabelSelection = {'x':[], 'y':[], 'm':[]} for tmpKey in ['x', 'y', 'm']: if tmpKey in selection: for labelIndex in selection[tmpKey]: actualLabelSelection[tmpKey].append( \ selection['cntlist'][labelIndex]) if 'x' in selection: for labelindex in selection['x']: #label = selection['cntlist'][labelindex] label = data.info['LabelNames'][labelindex] if label not in data.info['LabelNames']: raise ValueError("Label %s not in scan labels" % label) index = data.info['LabelNames'].index(label) if data.x is None: data.x = [] data.x.append(data.data[:nopts, index]) if 'y' in selection: #for labelindex in selection['y']: for label in actualLabelSelection['y']: #label = data.info['LabelNames'][labelindex] if label not in data.info['LabelNames']: raise ValueError("Label %s not in scan labels" % label) index = data.info['LabelNames'].index(label) if data.y is None: data.y = [] data.y.append(data.data[:nopts, index]) if 'm' in selection: #for labelindex in selection['m']: for label in actualLabelSelection['m']: #label = data.info['LabelNames'][labelindex] if label not in data.info['LabelNames']: raise ValueError("Label %s not in scan labels" % label) index = data.info['LabelNames'].index(label) if data.m is None: data.m = [] data.m.append(data.data[:nopts, index]) data.info['selectiontype'] = "1D" data.info['scanselection'] = True if newMemoryProblem: newSelection = copy.deepcopy(selection) for tmpKey in ['x', 'y', 'm']: if tmpKey in selection: for i in range(len(selection[tmpKey])): if tmpKey == "x": label = data.info['LabelNames'][selection[tmpKey][i]] else: label = selection['cntlist'][selection[tmpKey][i]] newSelection[tmpKey][i] = data.info['LabelNames'].index(label) data.info['selection'] = newSelection data.info['selection']['cntlist'] = data.info['LabelNames'] selection = newSelection data.data = None return data if (key in ["XIA_DATA"]) and 'XIA' in selection: if selection["XIA"]: if 'Detectors' in data.info: for i in range(len(selection['rows']['y'])): selection['rows']['y'][i] = \ data.info['Detectors'].index(selection['rows']['y'][i]) + 1 del selection['XIA'] return data.select(selection) else: if data.data is not None: data.info['selectiontype'] = "%dD" % len(data.data.shape) if data.info['selectiontype'] == "2D": data.info["imageselection"] = True return data else: output.append(data.select(selection)) return output else: return None
def openFile(self, filename=None, justloaded=None, specsession=False): _logger.debug("openfile = %s", filename) staticDialog = False if specsession == "bliss": specsession = False session = filename node = RedisTools.get_node(session) if not node: txt = "No REDIS information retrieved from session %s" % \ session raise IOError(txt) filename = RedisTools.get_session_filename(node) if not len(filename): txt = "Cannot retrieve last output filename from session %s" % \ session raise IOError(txt) if not os.path.exists(filename): txt = "Last output file <%s> does not exist" % filename raise IOError(txt) filename = [filename] key = os.path.basename(filename[0]) try: self._emitSourceSelectedOrReloaded(filename, key) except: _logger.error("Problem opening %s" % filename[0]) key = "%s" % session self._emitSourceSelectedOrReloaded([session], key) return if not specsession: if justloaded is None: justloaded = True if filename is None: if self.lastInputDir is not None: if not os.path.exists(self.lastInputDir): self.lastInputDir = None wdir = self.lastInputDir filelist, fileFilter = PyMcaFileDialogs.getFileList( self, filetypelist=self.fileTypeList, message="Open a new source file", currentdir=wdir, mode="OPEN", getfilter=True, single=False, currentfilter=self.lastFileFilter) if not len(filelist): return if not len(filelist[0]): return filename = [] for f in filelist: filename.append(qt.safe_str(f)) if not len(filename): return if len(filename): self.lastInputDir = os.path.dirname(filename[0]) PyMcaDirs.inputDir = os.path.dirname(filename[0]) self.lastFileFilter = fileFilter justloaded = True if justloaded: if type(filename) != type([]): filename = [filename] if not os.path.exists(filename[0]): if '%' not in filename[0]: raise IOError("File %s does not exist" % filename[0]) #check if it is a stack if len(filename) > 1: key = "STACK from %s to %s" % (filename[0], filename[-1]) else: key = os.path.basename(filename[0]) else: key = filename if key not in sps.getspeclist(): qt.QMessageBox.critical( self, "SPS Error", "No shared memory source named %s" % key) return self._emitSourceSelectedOrReloaded(filename, key)
def getDataObject(self, key_list, selection=None): if type(key_list) not in [type([])]: nolist = True key_list = [key_list] else: output = [] nolist = False if self.name in sps.getspeclist(): sourcekeys = self.getSourceInfo()['KeyList'] for key in key_list: #a key corresponds to an array name if key not in sourcekeys: raise KeyError("Key %s not in source keys" % key) #array = key #create data object data = DataObject.DataObject() data.info = self.__getArrayInfo(key) data.info['selection'] = selection data.data = sps.getdata(self.name, key) if nolist: if selection is not None: scantest = (data.info['flag'] & sps.TAG_SCAN) == sps.TAG_SCAN if ((key in ["SCAN_D"]) or scantest) \ and 'cntlist' in selection: data.x = None data.y = None data.m = None if 'nopts' in data.info: nopts = data.info['nopts'] elif 'nopts' in data.info['envdict']: nopts = int(data.info['envdict']['nopts']) + 1 else: nopts = data.info['rows'] if not 'LabelNames' in data.info: data.info['LabelNames'] =\ selection['cntlist'] * 1 newMemoryProblem = len( data.info['LabelNames']) != len( selection['cntlist']) # check the current information is up-to-date # (new HKL handling business) actualLabelSelection = {'x': [], 'y': [], 'm': []} for tmpKey in ['x', 'y', 'm']: if tmpKey in selection: for labelIndex in selection[tmpKey]: actualLabelSelection[tmpKey].append( \ selection['cntlist'][labelIndex]) if 'x' in selection: for labelindex in selection['x']: #label = selection['cntlist'][labelindex] label = data.info['LabelNames'][labelindex] if label not in data.info['LabelNames']: raise ValueError( "Label %s not in scan labels" % label) index = data.info['LabelNames'].index( label) if data.x is None: data.x = [] data.x.append(data.data[:nopts, index]) if 'y' in selection: #for labelindex in selection['y']: for label in actualLabelSelection['y']: #label = data.info['LabelNames'][labelindex] if label not in data.info['LabelNames']: raise ValueError( "Label %s not in scan labels" % label) index = data.info['LabelNames'].index( label) if data.y is None: data.y = [] data.y.append(data.data[:nopts, index]) if 'm' in selection: #for labelindex in selection['m']: for label in actualLabelSelection['m']: #label = data.info['LabelNames'][labelindex] if label not in data.info['LabelNames']: raise ValueError( "Label %s not in scan labels" % label) index = data.info['LabelNames'].index( label) if data.m is None: data.m = [] data.m.append(data.data[:nopts, index]) data.info['selectiontype'] = "1D" data.info['scanselection'] = True if newMemoryProblem: newSelection = copy.deepcopy(selection) for tmpKey in ['x', 'y', 'm']: if tmpKey in selection: for i in range(len(selection[tmpKey])): if tmpKey == "x": label = data.info[ 'LabelNames'][ selection[tmpKey][i]] else: label = selection['cntlist'][ selection[tmpKey][i]] newSelection[tmpKey][ i] = data.info[ 'LabelNames'].index(label) data.info['selection'] = newSelection data.info['selection']['cntlist'] = data.info[ 'LabelNames'] selection = newSelection data.data = None return data if (key in ["XIA_DATA"]) and 'XIA' in selection: if selection["XIA"]: if 'Detectors' in data.info: for i in range(len( selection['rows']['y'])): selection['rows']['y'][i] = \ data.info['Detectors'].index(selection['rows']['y'][i]) + 1 del selection['XIA'] return data.select(selection) else: if data.data is not None: data.info['selectiontype'] = "%dD" % len( data.data.shape) if data.info['selectiontype'] == "2D": data.info["imageselection"] = True return data else: output.append(data.select(selection)) return output else: return None
def openFile(self, filename=None, justloaded=None, specsession = False): _logger.debug("openfile = %s", filename) staticDialog = False if not specsession: if justloaded is None: justloaded = True if filename is None: if self.lastInputDir is not None: if not os.path.exists(self.lastInputDir): self.lastInputDir = None wdir = self.lastInputDir filelist, fileFilter = PyMcaFileDialogs.getFileList(self, filetypelist=self.fileTypeList, message="Open a new source file", currentdir=wdir, mode="OPEN", getfilter=True, single=False, currentfilter=self.lastFileFilter) if not len(filelist): return if not len(filelist[0]): return filename=[] for f in filelist: filename.append(qt.safe_str(f)) if not len(filename): return if len(filename): self.lastInputDir = os.path.dirname(filename[0]) PyMcaDirs.inputDir = os.path.dirname(filename[0]) self.lastFileFilter = fileFilter justloaded = True if justloaded: if type(filename) != type([]): filename = [filename] if not os.path.exists(filename[0]): if '%' not in filename[0]: raise IOError("File %s does not exist" % filename[0]) #check if it is a stack if len(filename) > 1: key = "STACK from %s to %s" % (filename[0], filename[-1]) else: key = os.path.basename(filename[0]) else: key = filename if key not in sps.getspeclist(): qt.QMessageBox.critical(self, "SPS Error", "No shared memory source named %s" % key) return ddict = {} ddict["event"] = "NewSourceSelected" if key in self.mapCombo.keys(): if self.mapCombo[key] == filename: #Reloaded event ddict["event"] = "SourceReloaded" else: i = 0 while key in self.mapCombo.keys(): key += "_%d" % i ddict["combokey"] = key ddict["sourcelist"] = filename self.mapCombo[key] = filename if ddict["event"] =="NewSourceSelected": nitems = self.fileCombo.count() self.fileCombo.insertItem(nitems, key) self.fileCombo.setCurrentIndex(nitems) else: if hasattr(qt, "QString"): nitem = self.fileCombo.findText(qt.QString(key)) else: nitem = self.fileCombo.findText(key) self.fileCombo.setCurrentIndex(nitem) self.sigSourceSelectorSignal.emit(ddict)
def openFile(self, filename=None,justloaded=None, specsession = False): if DEBUG: print("openfile = ",filename) staticDialog = False if not specsession: if justloaded is None: justloaded = True if filename is None: if self.lastInputDir is not None: if not os.path.exists(self.lastInputDir): self.lastInputDir = None wdir = self.lastInputDir if wdir is None: wdir = os.getcwd() if (sys.version < '3.0') and PyMcaDirs.nativeFileDialogs: filetypes = "" for filetype in self.fileTypeList: filetypes += filetype+"\n" try: # API 1 filelist = qt.QFileDialog.getOpenFileNames(self, "Open a new source file", wdir, filetypes, self.lastFileFilter) except: # API 2 filelist, self.lastFileFilter =\ qt.QFileDialog.getOpenFileNamesAndFilter(\ self, "Open a new source file", wdir, filetypes, self.lastFileFilter) staticDialog = True else: fdialog = qt.QFileDialog(self) fdialog.setModal(True) fdialog.setWindowTitle("Open a new source file") if hasattr(qt, "QStringList"): strlist = qt.QStringList() else: strlist = [] for filetype in self.fileTypeList: strlist.append(filetype) if QTVERSION < '5.0.0': fdialog.setFilters(strlist) fdialog.selectFilter(self.lastFileFilter) else: fdialog.setNameFilters(strlist) fdialog.selectNameFilter(self.lastFileFilter) fdialog.setFileMode(fdialog.ExistingFiles) fdialog.setDirectory(wdir) ret = fdialog.exec_() if ret == qt.QDialog.Accepted: filelist = fdialog.selectedFiles() if QTVERSION < '5.0.0': self.lastFileFilter = qt.safe_str(\ fdialog.selectedFilter()) else: self.lastFileFilter = qt.safe_str(\ fdialog.selectedNameFilter()) fdialog.close() del fdialog else: fdialog.close() del fdialog return #filelist.sort() filename=[] for f in filelist: filename.append(qt.safe_str(f)) if not len(filename): return if len(filename): self.lastInputDir = os.path.dirname(filename[0]) PyMcaDirs.inputDir = os.path.dirname(filename[0]) if staticDialog: if len(filename[0]) > 3: #figure out the selected filter extension = filename[0][-3:] self.lastFileFilter = self.fileTypeList[-1] for fileFilter in self.fileTypeList: if extension == fileFilter[-4:-1]: self.lastFileFilter = fileFilter break justloaded = True if justloaded: if type(filename) != type([]): filename = [filename] if not os.path.exists(filename[0]): if '%' not in filename[0]: raise IOError("File %s does not exist" % filename[0]) #check if it is a stack if len(filename) > 1: key = "STACK from %s to %s" % (filename[0], filename[-1]) else: key = os.path.basename(filename[0]) else: key = filename if key not in sps.getspeclist(): qt.QMessageBox.critical(self, "SPS Error", "No shared memory source named %s" % key) return ddict = {} ddict["event"] = "NewSourceSelected" if key in self.mapCombo.keys(): if self.mapCombo[key] == filename: #Reloaded event ddict["event"] = "SourceReloaded" else: i = 0 while key in self.mapCombo.keys(): key += "_%d" % i ddict["combokey"] = key ddict["sourcelist"] = filename self.mapCombo[key] = filename if ddict["event"] =="NewSourceSelected": nitems = self.fileCombo.count() self.fileCombo.insertItem(nitems, key) self.fileCombo.setCurrentIndex(nitems) else: if hasattr(qt, "QString"): nitem = self.fileCombo.findText(qt.QString(key)) else: nitem = self.fileCombo.findText(key) self.fileCombo.setCurrentIndex(nitem) self.sigSourceSelectorSignal.emit(ddict)
def openFile(self, filename=None, justloaded=None, specsession=False): if DEBUG: print("openfile = ", filename) staticDialog = False if not specsession: if justloaded is None: justloaded = True if filename is None: if self.lastInputDir is not None: if not os.path.exists(self.lastInputDir): self.lastInputDir = None wdir = self.lastInputDir filelist, fileFilter = PyMcaFileDialogs.getFileList( self, filetypelist=self.fileTypeList, message="Open a new source file", currentdir=wdir, mode="OPEN", getfilter=True, single=False, currentfilter=self.lastFileFilter) if not len(filelist): return if not len(filelist[0]): return filename = [] for f in filelist: filename.append(qt.safe_str(f)) if not len(filename): return if len(filename): self.lastInputDir = os.path.dirname(filename[0]) PyMcaDirs.inputDir = os.path.dirname(filename[0]) self.lastFileFilter = fileFilter justloaded = True if justloaded: if type(filename) != type([]): filename = [filename] if not os.path.exists(filename[0]): if '%' not in filename[0]: raise IOError("File %s does not exist" % filename[0]) #check if it is a stack if len(filename) > 1: key = "STACK from %s to %s" % (filename[0], filename[-1]) else: key = os.path.basename(filename[0]) else: key = filename if key not in sps.getspeclist(): qt.QMessageBox.critical( self, "SPS Error", "No shared memory source named %s" % key) return ddict = {} ddict["event"] = "NewSourceSelected" if key in self.mapCombo.keys(): if self.mapCombo[key] == filename: #Reloaded event ddict["event"] = "SourceReloaded" else: i = 0 while key in self.mapCombo.keys(): key += "_%d" % i ddict["combokey"] = key ddict["sourcelist"] = filename self.mapCombo[key] = filename if ddict["event"] == "NewSourceSelected": nitems = self.fileCombo.count() self.fileCombo.insertItem(nitems, key) self.fileCombo.setCurrentIndex(nitems) else: if hasattr(qt, "QString"): nitem = self.fileCombo.findText(qt.QString(key)) else: nitem = self.fileCombo.findText(key) self.fileCombo.setCurrentIndex(nitem) self.sigSourceSelectorSignal.emit(ddict)
def openFile(self, filename=None,justloaded=None, specsession = False): if DEBUG: print("openfile = ",filename) staticDialog = False if not specsession: if justloaded is None: justloaded = True if filename is None: if self.lastInputDir is not None: if not os.path.exists(self.lastInputDir): self.lastInputDir = None wdir = self.lastInputDir if wdir is None: wdir = os.getcwd() if (sys.version < '3.0') and PyMcaDirs.nativeFileDialogs: filetypes = "" for filetype in self.fileTypeList: filetypes += filetype+"\n" try: # API 1 filelist = qt.QFileDialog.getOpenFileNames(self, "Open a new source file", wdir, filetypes, self.lastFileFilter) except: # API 2 filelist, self.lastFileFilter =\ qt.QFileDialog.getOpenFileNamesAndFilter(\ self, "Open a new source file", wdir, filetypes, self.lastFileFilter) staticDialog = True else: fdialog = qt.QFileDialog(self) fdialog.setModal(True) fdialog.setWindowTitle("Open a new source file") if hasattr(qt, "QStringList"): strlist = qt.QStringList() else: strlist = [] for filetype in self.fileTypeList: strlist.append(filetype) fdialog.setFilters(strlist) fdialog.selectFilter(self.lastFileFilter) fdialog.setFileMode(fdialog.ExistingFiles) fdialog.setDirectory(wdir) ret = fdialog.exec_() if ret == qt.QDialog.Accepted: filelist = fdialog.selectedFiles() self.lastFileFilter = qt.safe_str(\ fdialog.selectedFilter()) fdialog.close() del fdialog else: fdialog.close() del fdialog return #filelist.sort() filename=[] for f in filelist: filename.append(qt.safe_str(f)) if not len(filename): return if len(filename): self.lastInputDir = os.path.dirname(filename[0]) PyMcaDirs.inputDir = os.path.dirname(filename[0]) if staticDialog: if len(filename[0]) > 3: #figure out the selected filter extension = filename[0][-3:] self.lastFileFilter = self.fileTypeList[-1] for fileFilter in self.fileTypeList: if extension == fileFilter[-4:-1]: self.lastFileFilter = fileFilter break justloaded = True if justloaded: if type(filename) != type([]): filename = [filename] if not os.path.exists(filename[0]): if '%' not in filename[0]: raise IOError("File %s does not exist" % filename[0]) #check if it is a stack if len(filename) > 1: key = "STACK from %s to %s" % (filename[0], filename[-1]) else: key = os.path.basename(filename[0]) else: key = filename if key not in sps.getspeclist(): qt.QMessageBox.critical(self, "SPS Error", "No shared memory source named %s" % key) return ddict = {} ddict["event"] = "NewSourceSelected" if key in self.mapCombo.keys(): if self.mapCombo[key] == filename: #Reloaded event ddict["event"] = "SourceReloaded" else: i = 0 while key in self.mapCombo.keys(): key += "_%d" % i ddict["combokey"] = key ddict["sourcelist"] = filename self.mapCombo[key] = filename if ddict["event"] =="NewSourceSelected": nitems = self.fileCombo.count() self.fileCombo.insertItem(nitems, key) self.fileCombo.setCurrentIndex(nitems) else: if hasattr(qt, "QString"): nitem = self.fileCombo.findText(qt.QString(key)) else: nitem = self.fileCombo.findText(key) self.fileCombo.setCurrentIndex(nitem) self.sigSourceSelectorSignal.emit(ddict)
def getDataObject(self, key_list, selection=None): if type(key_list) != types.ListType: nolist = True key_list = [key_list] else: output = [] nolist = False if self.name in sps.getspeclist(): sourcekeys = self.getSourceInfo()['KeyList'] for key in key_list: #a key corresponds to an array name if key not in sourcekeys: raise KeyError("Key %s not in source keys" % key) #array = key #create data object data = DataObject.DataObject() data.info = self.__getArrayInfo(key) data.info['selection'] = selection data.data = sps.getdata(self.name, key) if nolist: if selection is not None: scantest = (data.info['flag'] & sps.TAG_SCAN) == sps.TAG_SCAN if ((key in ["SCAN_D"]) or scantest) \ and 'cntlist' in selection: data.x = None data.y = None data.m = None if 'nopts' in data.info['envdict']: nopts = int(data.info['envdict']['nopts']) + 1 else: nopts = data.info['rows'] if not 'LabelNames' in data.info: data.info['LabelNames'] =\ selection['cntlist'] * 1 if 'x' in selection: for labelindex in selection['x']: label = data.info['LabelNames'][labelindex] if label not in data.info['LabelNames']: raise ValueError("Label %s not in scan labels" % label) index = data.info['LabelNames'].index(label) if data.x is None: data.x = [] data.x.append(data.data[:nopts, index]) if 'y' in selection: for labelindex in selection['y']: label = data.info['LabelNames'][labelindex] if label not in data.info['LabelNames']: raise ValueError("Label %s not in scan labels" % label) index = data.info['LabelNames'].index(label) if data.y is None: data.y = [] data.y.append(data.data[:nopts, index]) if 'm' in selection: for labelindex in selection['m']: label = data.info['LabelNames'][labelindex] if label not in data.info['LabelNames']: raise ValueError("Label %s not in scan labels" % label) index = data.info['LabelNames'].index(label) if data.m is None: data.m = [] data.m.append(data.data[:nopts, index]) data.info['selectiontype'] = "1D" data.info['scanselection'] = True data.data = None return data if (key in ["XIA_DATA"]) and 'XIA' in selection: if selection["XIA"]: if 'Detectors' in data.info: for i in range(len(selection['rows']['y'])): selection['rows']['y'][i] = \ data.info['Detectors'].index(selection['rows']['y'][i]) + 1 del selection['XIA'] return data.select(selection) else: if data.data is not None: data.info['selectiontype'] = "%dD" % len(data.data.shape) if data.info['selectiontype'] == "2D": data.info["imageselection"] = True return data else: output.append(data.select(selection)) return output else: return None