示例#1
0
    def openBlissOrSpec(self):
        if not BLISS:
            return self.openSpec()
        sessionList = RedisTools.get_sessions_list()
        if not len(sessionList):
            return self.openSpec()
        activeList = []
        for session in sessionList:
            node = RedisTools.get_node(session)
            if node:
                activeList.append(session)
        if not len(activeList):
            _logger.info("Bliss sessions found but no info in REDIS")
            return self.openSpec()
        sessionList = activeList

        menu = qt.QMenu()
        for session in sessionList:
            if hasattr(qt, "QString"):
                menu.addAction(
                    qt.QString(session),
                    lambda i=session: self.openFile(i, specsession="bliss"))
            else:
                menu.addAction(
                    session,
                    lambda i=session: self.openFile(i, specsession="bliss"))
        menu.exec_(self.cursor().pos())
示例#2
0
    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)
示例#3
0
 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]
     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)