Mercurial > cpython-lru_cache-weakref
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 |
| 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 | 8 |
| 9 import stdwin | |
| 10 from stdwinevents import * | |
| 11 import basewin | |
| 12 import sys | |
| 13 | |
| 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 | 16 MAXHEIGHT = 16 |
| 17 | |
| 18 class FrameWindow(basewin.BaseWindow): | |
| 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 | 21 self.debugger = debugger |
| 22 self.frame = frame # Not used except for identity tests | |
| 23 self.dict = dict | |
| 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 | 26 nl = min(nl, MAXHEIGHT) |
| 27 width = WIDTH*stdwin.textwidth('0') | |
| 28 height = nl*stdwin.lineheight() | |
| 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 | 33 self.initeditor() |
| 34 self.displaylist = ['>>>', '', '-'*WIDTH] | |
| 35 self.refreshframe() | |
| 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 | |
|
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 | 90 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 | |
|
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 | 99 try: |
| 100 value = eval(expr, globals, locals) | |
| 101 output = repr.repr(value) | |
| 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 | 107 self.displaylist[1] = output |
| 108 lh = stdwin.lineheight() | |
| 109 r = (-10, 0), (30000, 2*lh) | |
| 110 self.win.change(r) | |
| 111 self.editor.setfocus(0, len(expr)) | |
| 112 | |
| 113 def draw(self, detail): | |
| 114 (left, top), (right, bottom) = detail | |
| 115 dummy = self.editor.draw(detail) | |
| 116 d = self.win.begindrawing() | |
| 117 try: | |
| 118 lh = d.lineheight() | |
| 119 h, v = 0, 0 | |
| 120 for line in self.displaylist: | |
| 121 if v+lh > top and v < bottom: | |
| 122 d.text((h, v), line) | |
| 123 v = v + lh | |
| 124 finally: | |
| 125 d.close() | |
| 126 | |
| 127 def refreshframe(self): | |
| 128 import repr | |
| 129 del self.displaylist[3:] | |
| 130 self.re_eval() | |
| 131 names = self.dict.keys() | |
| 132 for key, label in ('__args__', 'Args: '), \ | |
| 133 ('__return__', 'Return: '): | |
| 134 if self.dict.has_key(key): | |
| 135 names.remove(key) | |
| 136 value = self.dict[key] | |
| 137 label = label + repr.repr(value) | |
| 138 self.displaylist.append(label) | |
| 139 names.sort() | |
| 140 for name in names: | |
| 141 value = self.dict[name] | |
| 142 line = name + ' = ' + repr.repr(value) | |
| 143 self.displaylist.append(line) | |
| 144 self.win.setdocsize(0, \ | |
| 145 stdwin.lineheight() * len(self.displaylist)) | |
| 146 self.refreshall() # XXX Be more subtle later |
