X-Git-Url: https://git.sthu.org/?p=pygdb.git;a=blobdiff_plain;f=DbgTerminal.py;h=ebe4e1a2f147ed16bb8c37474724d02f4811dded;hp=6b09426a0698313742ed85402b441cdf4b715c67;hb=162c3ac77fb35684824a2a8f975800dd9780bf10;hpb=505db8dd1b2862d460c7442e98c0c14ac776a4db diff --git a/DbgTerminal.py b/DbgTerminal.py index 6b09426..ebe4e1a 100644 --- a/DbgTerminal.py +++ b/DbgTerminal.py @@ -4,6 +4,7 @@ __author__ = "shuber" +import gobject import gtk import os import pango @@ -29,6 +30,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 +42,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") @@ -56,6 +61,30 @@ 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): @@ -68,15 +97,40 @@ class DbgTerminal (vte.Terminal): #Remove annoying \n at the end assert(text[-1] == "\n") text = text[:-1] - #Get the lines and remove empty lines lines = string.split(text, "\n") #Remove the incomplete line + 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: @@ -135,6 +189,12 @@ class DbgTerminal (vte.Terminal): def waitForActivation(self, his): raise NotImplementedError() + def testForActivity(self, his): + raise NotImplementedError() + + def testForInactivity(self, his): + raise NotImplementedError() + def setActive(self, isactive): self.isactive = isactive