~ubuntu-branches/ubuntu/utopic/pida/utopic

« back to all changes in this revision

Viewing changes to pida/utils/pgd/main.py

  • Committer: Bazaar Package Importer
  • Author(s): Jan Luebbe
  • Date: 2007-04-17 16:08:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070417160806-3ttlb6igf94x9i03
Tags: 0.4.4-1
* New upstream release (closes: #419129)
* Add dependency on python-glade2 (closes: #418716)
* Update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*- 
 
2
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
 
3
 
 
4
# Copyright (c) 2006 Ali Afshar
 
5
 
 
6
#Permission is hereby granted, free of charge, to any person obtaining a copy
 
7
#of this software and associated documentation files (the "Software"), to deal
 
8
#in the Software without restriction, including without limitation the rights
 
9
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
10
#copies of the Software, and to permit persons to whom the Software is
 
11
#furnished to do so, subject to the following conditions:
 
12
 
 
13
#The above copyright notice and this permission notice shall be included in
 
14
#all copies or substantial portions of the Software.
 
15
 
 
16
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
19
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
20
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
21
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
22
#SOFTWARE.
 
23
 
 
24
# Main entry point into application so check sanity
 
25
#import sanity
 
26
#sanity.check_sanity()
 
27
#del sanity
 
28
 
 
29
import os
 
30
import sys
 
31
 
 
32
import gtk
 
33
import gobject
 
34
 
 
35
import debugsession
 
36
from console import Console
 
37
from mainwindow import MainWindow
 
38
#from sourceviewer import SourceViewer
 
39
from toolbar import Toolbar, StatusBar
 
40
from threadviewer import ThreadsViewer
 
41
from breakpointviewer import BreakpointViewer
 
42
from namespaceviewer import LocalsViewer, GlobalsViewer
 
43
from stackviewer import StackViewer, StackItem
 
44
 
 
45
 
 
46
class Application(object):
 
47
 
 
48
    def __init__(self, viewfactory, options):
 
49
        self.options = options
 
50
        self.main_window = viewfactory(self)
 
51
        self.session_manager = debugsession.SessionManager(self)
 
52
        self.console = Console(self)
 
53
        self.main_window.console = self.console
 
54
        self.stack = StackViewer(self)
 
55
        #self.namespace = AllNamespaceViewer(self)
 
56
        self.threads = ThreadsViewer(self)
 
57
        #self.source = SourceViewer(self)
 
58
        self.globals = GlobalsViewer(self)
 
59
        self.locals = LocalsViewer(self)
 
60
        self.status = StatusBar(self)
 
61
        self.breaks = BreakpointViewer(self)
 
62
        self.toolbar = Toolbar(self)
 
63
        debugsession.connect_events(self)
 
64
 
 
65
    def launch(self, filename):
 
66
        def _l(filename):
 
67
            import threading
 
68
            if filename is not None:
 
69
                def _t():
 
70
                    self.session_manager.launch(True, filename)
 
71
                t = threading.Thread(target=_t)
 
72
                t.start()
 
73
        _l(filename)
 
74
        #gobject.idle_add(_l, filename)
 
75
 
 
76
    def update_threads(self, event):
 
77
        current_thread = event.m_current_thread
 
78
        threads_list = event.m_thread_list
 
79
        def _u(threads_list, current_thread):
 
80
            self.threads.update_threads(threads_list, current_thread)
 
81
        gobject.idle_add(_u, threads_list, current_thread)
 
82
 
 
83
    def update_thread_broken(self, event):
 
84
        tid = event.m_tid
 
85
        def _u(tid):
 
86
            self.threads.broken_thread(tid)
 
87
        gobject.idle_add(_u, tid)
 
88
 
 
89
    def update_no_threads(self, event):
 
90
        print 'nothreads'
 
91
 
 
92
    def update_state(self, event):
 
93
        state = event.m_state
 
94
        def _u(state):
 
95
            self.status.update_running_status(state)
 
96
        def _u2(state):
 
97
            self.toolbar.update_state(state)
 
98
        def _u3(state):
 
99
            self.master.update_state(state)
 
100
        gobject.idle_add(_u, state)
 
101
        gobject.idle_add(_u2, state)
 
102
        gobject.idle_add(_u3, state)
 
103
 
 
104
    def update_frame(self, event):
 
105
        index = event.m_frame_index
 
106
        def _u(index):
 
107
            self.stack.select_frame(index)
 
108
        gobject.idle_add(_u, index)
 
109
        self.update_source(-index - 1)
 
110
 
 
111
    def update_stack(self, event):
 
112
        stack = event.m_stack
 
113
        self._last_stack = stack
 
114
        def _u(stack):
 
115
            self.stack.update_stack(stack)
 
116
        gobject.idle_add(_u, stack)
 
117
        self.update_source(-1)
 
118
 
 
119
    def update_source(self, index):
 
120
        def _u(index):
 
121
            si =StackItem(index, *self._last_stack['stack'][index])
 
122
            self.source_goto(si.filename, si.linenumber)
 
123
        gobject.idle_add(_u, index)
 
124
            
 
125
    def update_namespace(self, event):
 
126
        def _u():
 
127
            self.locals.update_namespace()
 
128
            self.globals.update_namespace()
 
129
        gobject.idle_add(_u)
 
130
 
 
131
    def update_bp(self, event):
 
132
        def _u(event):
 
133
            act = event.m_action
 
134
            if event.m_bp is not None:
 
135
                filename = event.m_bp.m_filename
 
136
                linenumber = event.m_bp.m_lineno
 
137
                index = event.m_bp.m_id
 
138
                indices = None
 
139
            else:
 
140
                filename = None
 
141
                linenumber = None
 
142
                index = None
 
143
                indices = event.m_id_list
 
144
            self.breaks.update_bp(act, index, indices, filename, linenumber)
 
145
            self.master.update_bp(act, index, indices, filename, linenumber)
 
146
        gobject.idle_add(_u, event)
 
147
        
 
148
 
 
149
 
 
150
def start(*args):
 
151
    options = debugsession.start(*args)
 
152
    app = Application(MainWindow, options)
 
153
    app.console.start()
 
154
    app.main_window.show_all()
 
155
    if sys.argv[1:]:
 
156
        fn = sys.argv[-1]
 
157
        if os.path.exists(fn):
 
158
            app.launch(fn)
 
159
    gtk.main()
 
160
 
 
161
def embed(parent, viewfactory, filename=None):
 
162
    def start_embedded(*args):
 
163
        options = debugsession.start(*args)
 
164
        app = Application(viewfactory, options)
 
165
        app.console.start()
 
166
        app.main_window.show_all()
 
167
        parent.app = app
 
168
        if filename:
 
169
            fn = filename
 
170
            if os.path.exists(fn):
 
171
                app.launch(fn)
 
172
    return debugsession.main(start_embedded)
 
173
 
 
174
 
 
175
def main():
 
176
    debugsession.main(start)
 
177
 
 
178
 
 
179
if __name__ == '__main__':
 
180
    from gtk import gdk
 
181
    gdk.threads_init()
 
182
    main()