Major change: Discovered the vte.Terminal class and moved to that one!
[pygdb.git] / DbgWindow.py
1 #!/usr/bin/python
2 #shuber, 2008-06-04
3
4 __author__ = "shuber"
5
6
7 import gtk
8 import pty
9 import string
10 import time
11 import threading
12 import vte
13
14 import ClientIOWindow
15
16
17 class DbgWindow (gtk.Window):
18
19 clientIOWnd = None
20 lastrow = 0
21 history = []
22
23
24
25 def __init__(self, clientCmd):
26
27 #Set up some members
28 self.clientCmd = clientCmd
29
30 #Set up GTK stuff
31 gtk.Window.__init__(self)
32 self.connect("destroy", lambda *w: gtk.main_quit())
33
34 #Set title and add terminal
35 self.set_title("Debugger I/O")
36 self.terminal = vte.Terminal()
37 self.terminal.history = []
38 self.terminal.history_length = 5
39 self.add(self.terminal)
40
41 #Set up terminal window and initialize debugger
42 self.terminal.connect("child-exited", lambda *w: gtk.main_quit())
43 self.terminal.connect("cursor-moved", self.contents_changed)
44 self._initializeDbg()
45
46 #Show the window
47 self.show_all()
48
49
50 def _initializeDbg(self):
51
52 #Start debugger
53 self.terminal.fork_command( self.getDbgCommand(), self.getDbgArgv())
54
55 #Open pseudo-terminal where to-be-debugged process reads/writes to
56 self.client_ptymaster, self.client_ptyslave = pty.openpty()
57 self.setDbgPty(self.client_ptyslave)
58
59
60 def contents_changed(self, term):
61 c,r = term.get_cursor_position()
62
63 if self.lastrow < r:
64 text = self.terminal.get_text_range(self.lastrow,0,r-1,-1,lambda *w:True)
65 self.history += string.split(text, "\n")
66 self.lastrow = r
67
68 def waitForDbgNewline(self):
69 r = self.lastrow
70 while not self.lastrow > r:
71 gtk.main_iteration()
72
73 def waitForDbgRx(self, rx):
74 while True:
75 start = len(self.history)
76 gtk.main_iteration()
77
78 for line in self.history[start:]:
79 if rx.search(line):
80 return line
81
82
83 def getDbgCommand(self):
84 return self.getDbgArgv()[0];
85
86 def getDbgArgv(self):
87 raise NotImplementedError()
88
89 def setDbgPty(self, pty):
90 raise NotImplementedError()
91
92 def setDbgRun(self):
93 raise NotImplementedError()
94
95 def setDbgQuit(self):
96 raise NotImplementedError()
97
98 def setDbgContinue(self):
99 raise NotImplementedError()
100
101 def setDbgBreakpoint(self, file, lineno):
102 raise NotImplementedError()
103
104 def getDbgExpression(self, expr):
105 raise NotImplementedError()
106
107 def getDbgLastLine(self):
108 if len(self.history) == 0:
109 return None
110
111 return self.history[-1]
112
113 def feed_dbg(self, text):
114 self.terminal.feed_child(text)
115
116
117 def showClientIOWindow(self):
118 if not self.clientIOWnd:
119 self.clientIOWnd = ClientIOWindow.ClientIOWindow(self, self.client_ptymaster)
120
121
122
123
124 def launchDebugger(wnd):
125
126 wnd.showClientIOWindow()
127
128 wnd.setDbgBreakpoint("main.cpp", 15)
129 wnd.setDbgRun()
130 res = wnd.getDbgExpression("a")
131 print "Result = ", res
132
133 wnd.setDbgQuit()
134
135 gtk.main()
136
137
138
139
140