X-Git-Url: https://git.sthu.org/?a=blobdiff_plain;f=DbgTerminal.py;h=f69d8036fc8e5c3785903acb21f081a823ce268d;hb=e8f5eba24b3fd5cdd839bcfc170a2e3aa16dd05d;hp=6b09426a0698313742ed85402b441cdf4b715c67;hpb=505db8dd1b2862d460c7442e98c0c14ac776a4db;p=pygdb.git diff --git a/DbgTerminal.py b/DbgTerminal.py index 6b09426..f69d803 100644 --- a/DbgTerminal.py +++ b/DbgTerminal.py @@ -4,10 +4,12 @@ __author__ = "shuber" +import gobject import gtk import os import pango import pty +import re import string import sys import time @@ -29,6 +31,9 @@ class DbgTerminal (vte.Terminal): self.history = [""] self.isactive = True self.lastc, self.lastr = 0,0 + self.gotActiveCallback = [] + self.gotInactiveCallback = [] + self.activityChanged = None #Start debugger self.clientCmd = clientCmd @@ -38,6 +43,7 @@ class DbgTerminal (vte.Terminal): #Set up terminal window and initialize debugger self.connect("cursor-moved", self.contents_changed) self.connect("child-exited", quitHandler) + gobject.timeout_add(50, self.checkActivityChanged) #font description fontdesc = pango.FontDescription("monospace 9") @@ -46,7 +52,7 @@ class DbgTerminal (vte.Terminal): def initialize(self): self.childpid = self.fork_command( self.getCommand(), self.getArgv()) - self.waitForActivation(0) + self.waitForPrompt(0) self.setPty(self.client_ptyslave) def stopDbg(self): @@ -56,13 +62,37 @@ class DbgTerminal (vte.Terminal): os.kill(self.childpid, 15); self.childpid = None + def checkActivityChanged(self): + + try: + + #There was activity + if self.activityChanged != None: + + res = self.activityChanged + self.activityChanged = None + + status, param = res + if self.isActive(): + print "got active: ", res + for cb in self.gotActiveCallback: + cb(status, param) + else: + print "got inactive: ", res + for cb in self.gotInactiveCallback: + cb(status, param) + except: + pass + + return True + def contents_changed(self, term): assert( self.getHistoryLen()>0 ) c,r = term.get_cursor_position() - text = self.get_text_range(self.lastr,self.lastc,r,c-1,lambda *w:True) + text = self.get_text_range(self.lastr,0,r,c,lambda *w:True) self.lastc, self.lastr = c,r #Remove annoying \n at the end @@ -73,10 +103,36 @@ class DbgTerminal (vte.Terminal): lines = string.split(text, "\n") #Remove the incomplete line - self.history[-1] += lines[0] + len = max(0,self.getHistoryLen()) + self.history[-1] = lines[0] self.history += lines[1:] + #Check if activity status has been changed + for i in range(len, self.getHistoryLen()): + line = self.history[i] + + res = self.testForInactivity(i) + if res != None: + while self.activityChanged != None: + print "wait for pending activity" + gtk.main_iteration() + + self.setActive(False) + self.activityChanged = res + + res = self.testForActivity(i) + if res != None: + while self.activityChanged != None: + print "wait for pending activity" + gtk.main_iteration() + + self.setActive(True) + self.activityChanged = res + + + + def waitForNewline(self): l = self.getHistoryLen() while not self.getHistoryLen() > l: @@ -85,7 +141,9 @@ class DbgTerminal (vte.Terminal): def getHistoryLen(self): return len(self.history) - def waitForRx(self, rx, start): + def waitForRx(self, pat, start): + + rx = re.compile(pat) curr = start while True: assert( curr>=start ) @@ -96,7 +154,10 @@ class DbgTerminal (vte.Terminal): #Do not forget the last line curr = max(start,self.getHistoryLen()-1) - gtk.main_iteration() + lr, lc = self.lastr, self.lastc + + while (self.lastr, self.lastc) == (lr,lc): + gtk.main_iteration() def getCommand(self): @@ -132,7 +193,13 @@ class DbgTerminal (vte.Terminal): def getExpression(self, expr): raise NotImplementedError() - def waitForActivation(self, his): + def waitForPrompt(self, his): + raise NotImplementedError() + + def testForActivity(self, his): + raise NotImplementedError() + + def testForInactivity(self, his): raise NotImplementedError() def setActive(self, isactive):