Jack Jansen | 4892ab7 | 1996-09-24 15:35:50 +0000 | [diff] [blame^] | 1 | """twit - The Window-Independent Tracer. |
| 2 | |
| 3 | Interface: |
| 4 | twit.main() Enter debugger in inactive interactive state |
| 5 | twit.run(stmt, globals, locals) Enter debugger and start running stmt |
| 6 | twit.post_mortem(traceback) Enter debugger in post-mortem mode on traceback |
| 7 | twit.pm() Enter debugger in pm-mode on sys.last_traceback |
| 8 | |
| 9 | main program: nothing but a bit of glue to put it all together. |
| 10 | |
| 11 | Jack Jansen, CWI, August 1996.""" |
| 12 | |
| 13 | import os |
| 14 | if os.name == 'mac': |
| 15 | import MacOS |
| 16 | MacOS.splash(515) # Try to show the splash screen |
| 17 | import mactwit_mod; twit_mod = mactwit_mod |
| 18 | import mactwit_stack; twit_stack = mactwit_stack |
| 19 | import mactwit_app; twit_app = mactwit_app |
| 20 | import mactwit_browser; twit_browser = mactwit_browser |
| 21 | import mactwit_edit; twit_edit = mactwit_edit |
| 22 | else: |
| 23 | try: |
| 24 | import _tkinter |
| 25 | have_tk = 1 |
| 26 | except ImportError: |
| 27 | have_tk = 0 |
| 28 | if have_tk: |
| 29 | import tktwit_mod; twit_mod = tktwit_mod |
| 30 | import tktwit_stack; twit_stack = tktwit_stack |
| 31 | import tktwit_app; twit_app = tktwit_app |
| 32 | else: |
| 33 | print 'Please implementent twit_mod, twit_stack and twit_app and try again:-)' |
| 34 | sys.exit(1) |
| 35 | |
| 36 | import TwitCore |
| 37 | import sys |
| 38 | |
| 39 | class Twit(twit_app.Application, TwitCore.Application): |
| 40 | |
| 41 | def new_module_browser(self, *args): |
| 42 | return apply(TWIT_ModuleBrowser, args) |
| 43 | |
| 44 | def new_stack_browser(self, *args): |
| 45 | return apply(TWIT_StackBrowser, args) |
| 46 | |
| 47 | def new_var_browser(self, *args): |
| 48 | return apply(TWIT_VarBrowser, args) |
| 49 | |
| 50 | def edit(self, *args): |
| 51 | return apply(twit_edit.edit, args) |
| 52 | |
| 53 | class TWIT_ModuleBrowser(twit_mod.ModuleBrowser, TwitCore.ModuleBrowser): |
| 54 | pass |
| 55 | |
| 56 | class TWIT_StackBrowser(twit_stack.StackBrowser, TwitCore.StackBrowser): |
| 57 | pass |
| 58 | |
| 59 | def TWIT_VarBrowser(parent, var): |
| 60 | return twit_browser.VarBrowser(parent).open(var) |
| 61 | |
| 62 | def Initialize(): |
| 63 | # Gross... |
| 64 | TwitCore.AskString = twit_app.AskString |
| 65 | TwitCore.SetWatch = twit_app.SetWatch |
| 66 | TwitCore.SetCursor = twit_app.SetCursor |
| 67 | |
| 68 | def main(): |
| 69 | twit_app.Initialize() |
| 70 | TwitCore.Initialize() |
| 71 | Initialize() |
| 72 | if os.name == 'mac': |
| 73 | MacOS.splash() |
| 74 | Twit(None, None) |
| 75 | |
| 76 | def run(statement, globals=None, locals=None): |
| 77 | twit_app.Initialize() |
| 78 | TwitCore.Initialize() |
| 79 | Initialize() |
| 80 | Twit((statement, globals, locals), None) |
| 81 | |
| 82 | def post_mortem(t): |
| 83 | twit_app.Initialize() |
| 84 | TwitCore.Initialize() |
| 85 | Initialize() |
| 86 | Twit(None, t) |
| 87 | |
| 88 | def pm(): |
| 89 | post_mortem(sys.last_traceback) |
| 90 | |
| 91 | if __name__ == '__main__': |
| 92 | main() |
| 93 | |
| 94 | |