当前位置: 首页>>代码示例>>Python>>正文


Python UI.setDebugger方法代码示例

本文整理汇总了Python中ui.UI.setDebugger方法的典型用法代码示例。如果您正苦于以下问题:Python UI.setDebugger方法的具体用法?Python UI.setDebugger怎么用?Python UI.setDebugger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ui.UI的用法示例。


在下文中一共展示了UI.setDebugger方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Debugger

# 需要导入模块: from ui import UI [as 别名]
# 或者: from ui.UI import setDebugger [as 别名]
class Debugger(SocketManagerListener):
    def __init__(self):
        self.__ui = UI()
        self.__ui.setDebugger(self)

        self.__socketmanager = SocketManager()
        self.__socketmanager.setListener(self)

        self.__sessions = []
        self.__currentSession = None
        self.__commands = []
        self.__quit = False
        self.__newSessionCommands = []
        self.__currentLines = None
        self.__commandQueue = []
        self.__commandQueueLock = RLock()

    def getUI(self): return self.__ui
    def getSocketManager(self): return self.__socketmanager

    def getCurrentSession(self): return self.__currentSession
    def setCurrentSession(self, session): self.__currentSession = session

    def getNewSessionCommands(self): return self.__newSessionCommands[:]
    def setNewSessionCommands(self, commands): self.__newSessionCommands = commands
    
    def getSessions(self): return self.__sessions[:]

    def addSession(self, session):
        self.__sessions.append(session)
        if self.__currentSession is None: self.__currentSession = session

    def removeSession(self, session):
        self.__sessions.remove(session)
        if self.__currentSession == session: self.__currentSession = None

    def getCurrentRuntime(self):
        if self.getCurrentSession(): return self.getCurrentSession().getCurrentRuntime()
        else: return None
        
    def getCurrentThread(self):
        runtime = self.getCurrentRuntime()
        if runtime: return runtime.getCurrentThread()
        else: return None

    def addCommand(self, name, data):
        existing = [True for name0, realname0, command0 in self.__commands if name == name0]
        if existing: raise DebuggerError, "Command name already registered: %s" % name
        if type(data) == type(()): self.__commands.append((name, data[0], data[1]))
        else: self.__commands.append((name, name, data))

    def getCommandNames(self): return [realname for name, realname, command in self.__commands]

    def getCommandInvoker(self, line):
        try: name, arguments = line.split(' ', 1)
        except ValueError: name, arguments = line.strip(), ""
        try: name, options = name.split('/', 1)
        except ValueError: name, options = name, ""

        perfect = [(realname0, command0) for name0, realname0, command0 in self.__commands if name == name0]
        if perfect: return CommandInvoker(self, perfect[0][1], perfect[0][0], options, arguments)

        candidates = [(name0, realname0, command0) for name0, realname0, command0 in self.__commands if len(name) <= len(name0) and name0.startswith(name)]
        if len(candidates) == 1: return CommandInvoker(self, candidates[0][2], candidates[0][1], options, arguments)

        if len(candidates) == 0: message = "Unknown command: %s" % name
        else: message = "Ambiguous command.  Candidates are: %s" % ", ".join([name0 for name0, realname0, command0 in candidates])

        raise DebuggerError, message

    def execute(self, lines, withCurrentSession=None, withCurrentRuntime=None):
        currentSessionBefore = self.__currentSession
        currentRuntimeBefore = currentSessionBefore and currentSessionBefore.getCurrentRuntime()

        if withCurrentRuntime: withCurrentSession = withCurrentRuntime.getSession()
        if withCurrentSession:
            self.__currentSession = withCurrentSession
            if withCurrentRuntime:
                withCurrentSession.setCurrentRuntime(withCurrentRuntime)

        try:
            previousLines = self.__currentLines
            self.__currentLines = lines[:]
            while self.__currentLines:
                line = self.__currentLines.pop(0)
                if line:
                    output = self.getCommandInvoker(line)()
                    if output: self.getUI().writeln(*output)
        finally:
            self.__currentLines = previousLines
            if withCurrentSession:
                self.__currentSession = currentSessionBefore
                if withCurrentRuntime and currentSessionBefore:
                    currentSessionBefore.setCurrentRuntime(currentRuntimeBefore)

    def executeLater(self, lines, withCurrentSession=None, withCurrentRuntime=None):
        self.__commandQueueLock.acquire()
        try: self.__commandQueue.append((lines, withCurrentSession, withCurrentRuntime))
        finally: self.__commandQueueLock.release()

#.........这里部分代码省略.........
开发者ID:prestocore,项目名称:browser,代码行数:103,代码来源:debugger.py


注:本文中的ui.UI.setDebugger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。