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 refreshSpecList(self): speclist = sps.getspeclist() if self.specCombo.count(): selected = str(self.specCombo.currentText()) else: selected = None self.specCombo.clear() if len(speclist): for spec in speclist: self.specCombo.insertItem(spec) self.selectSpec(selected or speclist[0])
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 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 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 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 QTVERSION < '4.0.0': filetypes = "" for filetype in self.fileTypeList: filetypes += filetype+"\n" if sys.platform == 'win32': filelist = qt.QFileDialog.getOpenFileNames( filetypes, wdir, self, "openFile", "Open a new EdfFile") else: filedialog = qt.QFileDialog(self, "Open new EdfFile(s)", 1) if self.lastInputDir is not None: filedialog.setDir(self.lastInputDir) filedialog.setMode(filedialog.ExistingFiles) filedialog.setFilters(filetypes) if filedialog.exec_loop() == qt.QDialog.Accepted: filelist= filedialog.selectedFiles() else: return else: #if sys.platform == 'win32': #if (QTVERSION < '4.3.0') and (sys.platform != 'darwin'): if (sys.version < '3.0') and PyMcaDirs.nativeFileDialogs: filetypes = "" for filetype in self.fileTypeList: filetypes += filetype+"\n" if sys.version < '3.0': filelist = qt.QFileDialog.getOpenFileNames(self, "Open a new source file", wdir, filetypes, self.lastFileFilter) else: 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() if QTVERSION < '4.0.0': self.fileCombo.insertItem(key) self.fileCombo.setCurrentItem(nitems) else: 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) if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL("SourceSelectorSignal"), (ddict,)) else: self.emit(qt.SIGNAL("SourceSelectorSignal"), 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