annotate Lib/stdwin/wdbframewin.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 62ebbcfea827
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
652
0457c441b086 Added MINHEIGHT. Use self.dict as environment for evaluation.
Guido van Rossum <guido@python.org>
parents: 622
diff changeset
1 # wdbframewin.py -- frame window for wdb.py
0457c441b086 Added MINHEIGHT. Use self.dict as environment for evaluation.
Guido van Rossum <guido@python.org>
parents: 622
diff changeset
2
0457c441b086 Added MINHEIGHT. Use self.dict as environment for evaluation.
Guido van Rossum <guido@python.org>
parents: 622
diff changeset
3 # XXX To do:
0457c441b086 Added MINHEIGHT. Use self.dict as environment for evaluation.
Guido van Rossum <guido@python.org>
parents: 622
diff changeset
4 # - display function name in window title
0457c441b086 Added MINHEIGHT. Use self.dict as environment for evaluation.
Guido van Rossum <guido@python.org>
parents: 622
diff changeset
5 # - execute arbitrary statements instead of just evaluating expressions
0457c441b086 Added MINHEIGHT. Use self.dict as environment for evaluation.
Guido van Rossum <guido@python.org>
parents: 622
diff changeset
6 # - allow setting variables by editing their values
0457c441b086 Added MINHEIGHT. Use self.dict as environment for evaluation.
Guido van Rossum <guido@python.org>
parents: 622
diff changeset
7
622
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 import stdwin
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 from stdwinevents import *
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 import basewin
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 import sys
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 WIDTH = 40
652
0457c441b086 Added MINHEIGHT. Use self.dict as environment for evaluation.
Guido van Rossum <guido@python.org>
parents: 622
diff changeset
15 MINHEIGHT = 8
622
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 MAXHEIGHT = 16
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 class FrameWindow(basewin.BaseWindow):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
19
1435
560ec7030817 * Mass change: get rid of all init() methods, in favor of __init__()
Guido van Rossum <guido@python.org>
parents: 1422
diff changeset
20 def __init__(self, debugger, frame, dict, name):
622
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 self.debugger = debugger
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 self.frame = frame # Not used except for identity tests
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 self.dict = dict
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 self.name = name
652
0457c441b086 Added MINHEIGHT. Use self.dict as environment for evaluation.
Guido van Rossum <guido@python.org>
parents: 622
diff changeset
25 nl = max(MINHEIGHT, len(self.dict) + 5)
622
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 nl = min(nl, MAXHEIGHT)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 width = WIDTH*stdwin.textwidth('0')
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 height = nl*stdwin.lineheight()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 stdwin.setdefwinsize(width, height)
1435
560ec7030817 * Mass change: get rid of all init() methods, in favor of __init__()
Guido van Rossum <guido@python.org>
parents: 1422
diff changeset
30 basewin.BaseWindow.__init__(
560ec7030817 * Mass change: get rid of all init() methods, in favor of __init__()
Guido van Rossum <guido@python.org>
parents: 1422
diff changeset
31 self, '--Frame ' + name + '--')
652
0457c441b086 Added MINHEIGHT. Use self.dict as environment for evaluation.
Guido van Rossum <guido@python.org>
parents: 622
diff changeset
32 # XXX Should use current function name
622
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 self.initeditor()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 self.displaylist = ['>>>', '', '-'*WIDTH]
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 self.refreshframe()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 def initeditor(self):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 r = (stdwin.textwidth('>>> '), 0), (30000, stdwin.lineheight())
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 self.editor = self.win.textcreate(r)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 def closeeditor(self):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 self.editor.close()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 def dispatch(self, event):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 type, win, detail = event
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 if type == WE_NULL: return # Dummy tested by mainloop
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 if type in (WE_DRAW, WE_COMMAND) \
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 or not self.editor.event(event):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 basewin.BaseWindow.dispatch(self, event)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 def close(self):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 del self.debugger.framewindows[self.name]
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 del self.debugger, self.dict
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 self.closeeditor()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 basewin.BaseWindow.close(self)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 def command(self, detail):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 if detail == WC_RETURN:
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 self.re_eval()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 else:
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 dummy = self.editor.event(WE_COMMAND, \
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 self.win, detail)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
1344
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
64 def mouse_down(self, detail):
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
65 (h, v), clicks, button, mask = detail
1345
f41433c98c5e Instead of single clicks, use double clicks to get the instance window.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1344
diff changeset
66 if clicks != 2:
f41433c98c5e Instead of single clicks, use double clicks to get the instance window.
Sjoerd Mullender <sjoerd@acm.org>
parents: 1344
diff changeset
67 return
1344
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
68 i = v / stdwin.lineheight()
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
69 if 5 <= i < len(self.displaylist):
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
70 import string
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
71 name = string.splitfields(self.displaylist[i],' = ')[0]
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
72 if not self.dict.has_key(name):
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
73 stdwin.fleep()
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
74 return
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
75 value = self.dict[name]
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
76 if not hasattr(value, '__dict__'):
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
77 stdwin.fleep()
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
78 return
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
79 name = 'instance ' + `value`
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
80 if self.debugger.framewindows.has_key(name):
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
81 self.debugger.framewindows[name].popup()
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
82 else:
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
83 self.debugger.framewindows[name] = \
1435
560ec7030817 * Mass change: get rid of all init() methods, in favor of __init__()
Guido van Rossum <guido@python.org>
parents: 1422
diff changeset
84 FrameWindow(self.debugger,
1344
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
85 self.frame, value.__dict__,
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
86 name)
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
87 return
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
88 stdwin.fleep()
2798d8603bf0 WDB enhancement: Click once on a line with a class instance in the
Sjoerd Mullender <sjoerd@acm.org>
parents: 652
diff changeset
89
622
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 def re_eval(self):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 import string, repr
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 expr = string.strip(self.editor.gettext())
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 if expr == '':
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 output = ''
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 else:
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 globals = self.frame.f_globals
1422
8a90c9bbbdf0 * wdbframewin.py (re_eval): set __privileged__ in globals so private
Guido van Rossum <guido@python.org>
parents: 1345
diff changeset
97 globals['__privileged__'] = 1
652
0457c441b086 Added MINHEIGHT. Use self.dict as environment for evaluation.
Guido van Rossum <guido@python.org>
parents: 622
diff changeset
98 locals = self.dict
622
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 try:
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 value = eval(expr, globals, locals)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 output = repr.repr(value)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 except:
2437
62ebbcfea827 handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
103 if type(sys.exc_type) == type(''):
62ebbcfea827 handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
104 exc_type_name = sys.exc_type
62ebbcfea827 handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
105 else: exc_type_name = sys.exc_type.__name__
62ebbcfea827 handle class exceptions; added runeval; made runctx obsolete
Guido van Rossum <guido@python.org>
parents: 1435
diff changeset
106 output = exc_type_name + ': ' + `sys.exc_value`
622
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 self.displaylist[1] = output
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 lh = stdwin.lineheight()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 r = (-10, 0), (30000, 2*lh)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 self.win.change(r)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 self.editor.setfocus(0, len(expr))
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
112
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 def draw(self, detail):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 (left, top), (right, bottom) = detail
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 dummy = self.editor.draw(detail)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 d = self.win.begindrawing()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 try:
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 lh = d.lineheight()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 h, v = 0, 0
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 for line in self.displaylist:
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 if v+lh > top and v < bottom:
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 d.text((h, v), line)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 v = v + lh
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 finally:
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 d.close()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 def refreshframe(self):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 import repr
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 del self.displaylist[3:]
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 self.re_eval()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 names = self.dict.keys()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 for key, label in ('__args__', 'Args: '), \
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 ('__return__', 'Return: '):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 if self.dict.has_key(key):
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 names.remove(key)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 value = self.dict[key]
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 label = label + repr.repr(value)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 self.displaylist.append(label)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 names.sort()
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 for name in names:
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 value = self.dict[name]
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 line = name + ' = ' + repr.repr(value)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 self.displaylist.append(line)
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 self.win.setdocsize(0, \
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 stdwin.lineheight() * len(self.displaylist))
a0d4c5ef1d5d Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 self.refreshall() # XXX Be more subtle later