Exemplo n.º 1
0
 def setRecentFile(self, fullname):
     self.removeFromRecentFiles(fullname)
     fullname = util.normalizePath(fullname)
     recent = self.getRecentFiles()
     recent.insert(0, fullname)
     if len(recent) > Preferences.NUMBEROFRECENTFILES:
         recent.pop()
     self.preferences[Preferences.RECENTFILES] = recent
Exemplo n.º 2
0
 def setRecentContext(self, context):
     newContext = util.normalizePath(context)
     recent = self.getRecentContexts()
     if newContext in recent:
         recent.remove(newContext)
     recent.insert(0, newContext)
     if len(recent) > Preferences.NUMBEROFRECENTCONTEXTS:
         recent.pop()
     self.preferences[Preferences.RECENTCONTEXTS] = recent
Exemplo n.º 3
0
 def getRecentContexts(self):
     """return the last active context"""
     contexts = self.getValue(Preferences.RECENTCONTEXTS,
                              [util.getHomeDirectory()])
     cxts = []
     for context in contexts:
         ncontext = util.normalizePath(context)
         if not ncontext in cxts:
             cxts.append(ncontext)
     return cxts
Exemplo n.º 4
0
 def _sendCommandPVS(self, *args, **keywords):
     method = args[0]
     params = args[1:]
     if 'resultfn' in keywords:
         resultfn = keywords['resultfn']
         del keywords['resultfn']
     else:
         resultfn = None
     evt = PVSResponseEvent()
     try:
         silent = keywords[PVSCommunicator.SILENT] if PVSCommunicator.SILENT in keywords else False
         # Spawn a new thread, allowing the WX thread to go back to the main loop.
         # Note that _sendCommand does not directly return a result.
         jsonResult = self.pvsComm.requestPVS(method, *params)
         pvsMode = jsonResult[PVSCommunicator.MODE]
         evt.pvsmode = pvsMode
         evt.context = util.normalizePath(jsonResult[PVSCommunicator.CONTEXT])
         if PVSCommunicator.XMLRPCERROR in jsonResult:
             errorObj = jsonResult[PVSCommunicator.XMLRPCERROR]
             errorObject = {}
             if isinstance(errorObj, str) or isinstance(errorObj, unicode):
                 logging.error("jsonResult[xmlrpc_error] should be a dictionary and not a string")
                 errorObject[PVSCommunicator.CODE] = -100
                 errorObject[PVSCommunicator.MESSAGE] = errorObj
                 errorObject[PVSCommunicator.DATA] = None
             else:
                 errorObject[PVSCommunicator.CODE] = int(errorObj[PVSCommunicator.CODE])
                 errorObject[PVSCommunicator.MESSAGE] = errorObj[PVSCommunicator.MESSAGE]
                 errorObject[PVSCommunicator.DATA] = errorObj[PVSCommunicator.DATA] if PVSCommunicator.DATA in errorObj else None
             raise util.PVSException(message=errorObject[PVSCommunicator.MESSAGE], errorObject=errorObject)
         result = jsonResult[PVSCommunicator.JSONRPCRESULT]
         if isinstance(result, str) or isinstance(result, unicode):
             result2 = json.loads(result)
             #TODO: Keep this for a while, but remove the if statement later if you never get an assertion error.
             #assert (result2 == result), "result '%s' is a json object inside a string"%result
             if result2 != result:
                 logging.error("result '%s' should not be a string here, but an object", result)
                 result = result2
         if PVSCommunicator.ERROR in result:
             errDict = result[PVSCommunicator.ERROR]
             errorObject = self._processJSONErrorObject(errDict)
             raise util.PVSException(message=errorObject[PVSCommunicator.MESSAGE], errorObject=errorObject)
         evt.result = result[PVSCommunicator.RESULT]
         evt.resultfn = resultfn
         wx.PostEvent(util.getMainFrame(), evt)
     except Exception as err:
         # import traceback
         # traceback.print_stack()
         if not silent:
             self._handleError(err)
Exemplo n.º 5
0
 def _sendCommandPVS(self, *args, **keywords):
     method = args[0]
     params = args[1:]
     if 'resultfn' in keywords:
         resultfn = keywords['resultfn']
         del keywords['resultfn']
     else:
         resultfn = None
     evt = PVSResponseEvent()
     try:
         silent = keywords[
             PVSCommunicator.
             SILENT] if PVSCommunicator.SILENT in keywords else False
         # Spawn a new thread, allowing the WX thread to go back to the main loop.
         # Note that _sendCommand does not directly return a result.
         jsonResult = self.pvsComm.requestPVS(method, *params)
         pvsMode = jsonResult[PVSCommunicator.MODE]
         evt.pvsmode = pvsMode
         evt.context = util.normalizePath(
             jsonResult[PVSCommunicator.CONTEXT])
         if PVSCommunicator.XMLRPCERROR in jsonResult:
             errorObj = jsonResult[PVSCommunicator.XMLRPCERROR]
             errorObject = {}
             if isinstance(errorObj, str) or isinstance(errorObj, unicode):
                 logging.error(
                     "jsonResult[xmlrpc_error] should be a dictionary and not a string"
                 )
                 errorObject[PVSCommunicator.CODE] = -100
                 errorObject[PVSCommunicator.MESSAGE] = errorObj
                 errorObject[PVSCommunicator.DATA] = None
             else:
                 errorObject[PVSCommunicator.CODE] = int(
                     errorObj[PVSCommunicator.CODE])
                 errorObject[PVSCommunicator.MESSAGE] = errorObj[
                     PVSCommunicator.MESSAGE]
                 errorObject[PVSCommunicator.DATA] = errorObj[
                     PVSCommunicator.
                     DATA] if PVSCommunicator.DATA in errorObj else None
             raise util.PVSException(
                 message=errorObject[PVSCommunicator.MESSAGE],
                 errorObject=errorObject)
         result = jsonResult[PVSCommunicator.JSONRPCRESULT]
         if isinstance(result, str) or isinstance(result, unicode):
             result2 = json.loads(result)
             #TODO: Keep this for a while, but remove the if statement later if you never get an assertion error.
             #assert (result2 == result), "result '%s' is a json object inside a string"%result
             if result2 != result:
                 logging.error(
                     "result '%s' should not be a string here, but an object",
                     result)
                 result = result2
         if PVSCommunicator.ERROR in result:
             errDict = result[PVSCommunicator.ERROR]
             errorObject = self._processJSONErrorObject(errDict)
             raise util.PVSException(
                 message=errorObject[PVSCommunicator.MESSAGE],
                 errorObject=errorObject)
         evt.result = result[PVSCommunicator.RESULT]
         evt.resultfn = resultfn
         wx.PostEvent(util.getMainFrame(), evt)
     except Exception as err:
         # import traceback
         # traceback.print_stack()
         if not silent:
             self._handleError(err)
Exemplo n.º 6
0
 def removeFromRecentFiles(self, fullname):
     if Preferences.RECENTFILES in self.preferences:
         fullname = util.normalizePath(fullname)
         if fullname in self.preferences[Preferences.RECENTFILES]:
             self.preferences[Preferences.RECENTFILES].remove(fullname)