blob: db3d1379b05f87e3c46fbe1606eb05858baabbab [file] [log] [blame]
Guido van Rossum19a86e71992-01-27 17:00:10 +00001# wdbframewin.py -- frame window for wdb.py
2
3# XXX To do:
4# - display function name in window title
5# - execute arbitrary statements instead of just evaluating expressions
6# - allow setting variables by editing their values
7
Guido van Rossumbabe2bf1992-01-22 22:21:31 +00008
9import stdwin
10from stdwinevents import *
11import basewin
12import sys
13
14WIDTH = 40
Guido van Rossum19a86e71992-01-27 17:00:10 +000015MINHEIGHT = 8
Guido van Rossumbabe2bf1992-01-22 22:21:31 +000016MAXHEIGHT = 16
17
18class FrameWindow(basewin.BaseWindow):
19
20 def init(self, debugger, frame, dict, name):
21 self.debugger = debugger
22 self.frame = frame # Not used except for identity tests
23 self.dict = dict
24 self.name = name
Guido van Rossum19a86e71992-01-27 17:00:10 +000025 nl = max(MINHEIGHT, len(self.dict) + 5)
Guido van Rossumbabe2bf1992-01-22 22:21:31 +000026 nl = min(nl, MAXHEIGHT)
27 width = WIDTH*stdwin.textwidth('0')
28 height = nl*stdwin.lineheight()
29 stdwin.setdefwinsize(width, height)
30 self = basewin.BaseWindow.init(self, '--Frame ' + name + '--')
Guido van Rossum19a86e71992-01-27 17:00:10 +000031 # XXX Should use current function name
Guido van Rossumbabe2bf1992-01-22 22:21:31 +000032 self.initeditor()
33 self.displaylist = ['>>>', '', '-'*WIDTH]
34 self.refreshframe()
35 return self
36
37 def initeditor(self):
38 r = (stdwin.textwidth('>>> '), 0), (30000, stdwin.lineheight())
39 self.editor = self.win.textcreate(r)
40
41 def closeeditor(self):
42 self.editor.close()
43
44 def dispatch(self, event):
45 type, win, detail = event
46 if type == WE_NULL: return # Dummy tested by mainloop
47 if type in (WE_DRAW, WE_COMMAND) \
48 or not self.editor.event(event):
49 basewin.BaseWindow.dispatch(self, event)
50
51 def close(self):
52 del self.debugger.framewindows[self.name]
53 del self.debugger, self.dict
54 self.closeeditor()
55 basewin.BaseWindow.close(self)
56
57 def command(self, detail):
58 if detail == WC_RETURN:
59 self.re_eval()
60 else:
61 dummy = self.editor.event(WE_COMMAND, \
62 self.win, detail)
63
Sjoerd Mullender148644d1993-10-01 14:29:45 +000064 def mouse_down(self, detail):
65 (h, v), clicks, button, mask = detail
Sjoerd Mullenderbe80e0e1993-10-01 14:39:45 +000066 if clicks != 2:
67 return
Sjoerd Mullender148644d1993-10-01 14:29:45 +000068 i = v / stdwin.lineheight()
69 if 5 <= i < len(self.displaylist):
70 import string
71 name = string.splitfields(self.displaylist[i],' = ')[0]
72 if not self.dict.has_key(name):
73 stdwin.fleep()
74 return
75 value = self.dict[name]
76 if not hasattr(value, '__dict__'):
77 stdwin.fleep()
78 return
79 name = 'instance ' + `value`
80 if self.debugger.framewindows.has_key(name):
81 self.debugger.framewindows[name].popup()
82 else:
83 self.debugger.framewindows[name] = \
84 FrameWindow().init(self.debugger,
85 self.frame, value.__dict__,
86 name)
87 return
88 stdwin.fleep()
89
Guido van Rossumbabe2bf1992-01-22 22:21:31 +000090 def re_eval(self):
91 import string, repr
92 expr = string.strip(self.editor.gettext())
93 if expr == '':
94 output = ''
95 else:
96 globals = self.frame.f_globals
Guido van Rossum19a86e71992-01-27 17:00:10 +000097 locals = self.dict
Guido van Rossumbabe2bf1992-01-22 22:21:31 +000098 try:
99 value = eval(expr, globals, locals)
100 output = repr.repr(value)
101 except:
102 output = sys.exc_type + ': ' + `sys.exc_value`
103 self.displaylist[1] = output
104 lh = stdwin.lineheight()
105 r = (-10, 0), (30000, 2*lh)
106 self.win.change(r)
107 self.editor.setfocus(0, len(expr))
108
109 def draw(self, detail):
110 (left, top), (right, bottom) = detail
111 dummy = self.editor.draw(detail)
112 d = self.win.begindrawing()
113 try:
114 lh = d.lineheight()
115 h, v = 0, 0
116 for line in self.displaylist:
117 if v+lh > top and v < bottom:
118 d.text((h, v), line)
119 v = v + lh
120 finally:
121 d.close()
122
123 def refreshframe(self):
124 import repr
125 del self.displaylist[3:]
126 self.re_eval()
127 names = self.dict.keys()
128 for key, label in ('__args__', 'Args: '), \
129 ('__return__', 'Return: '):
130 if self.dict.has_key(key):
131 names.remove(key)
132 value = self.dict[key]
133 label = label + repr.repr(value)
134 self.displaylist.append(label)
135 names.sort()
136 for name in names:
137 value = self.dict[name]
138 line = name + ' = ' + repr.repr(value)
139 self.displaylist.append(line)
140 self.win.setdocsize(0, \
141 stdwin.lineheight() * len(self.displaylist))
142 self.refreshall() # XXX Be more subtle later