Bug fix: closing the file
[codimension.git] / src / debugger / context.py
blobee566235774611d9800c61c458d431f9e59d9a41
2 # -*- coding: utf-8 -*-
4 # codimension - graphics python two-way code editor and analyzer
5 # Copyright (C) 2010-2012 Sergey Satskiy <sergey.satskiy@gmail.com>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # $Id$
23 " debugger context viewer "
26 from stackviewer import StackViewer
27 from threadsviewer import ThreadsViewer
28 from variablesviewer import VariablesViewer
30 from PyQt4.QtCore import Qt, SIGNAL
31 from PyQt4.QtGui import QVBoxLayout, QWidget, QSplitter
34 class DebuggerContext( QWidget ):
35 " Implements the debugger context viewer "
37 def __init__( self, debugger, parent = None ):
38 QWidget.__init__( self, parent )
39 self.__debugger = debugger
40 self.connect( self.__debugger, SIGNAL( 'ClientLine' ),
41 self.__onClientLine )
42 self.connect( self.__debugger, SIGNAL( 'ClientStack' ),
43 self.onClientStack )
44 self.connect( self.__debugger, SIGNAL( 'ClientThreadList' ),
45 self.__onClientThreadList )
46 self.connect( self.__debugger, SIGNAL( 'ClientVariables' ),
47 self.__onClientVariables )
48 self.connect( self.__debugger, SIGNAL( 'ClientVariable' ),
49 self.__onClientVariable )
50 self.connect( self.__debugger, SIGNAL( 'ClientThreadSet' ),
51 self.__onClientThreadSet )
53 self.currentStack = None
54 self.__createLayout()
55 return
57 def __createLayout( self ):
58 " Creates the widget layout "
60 verticalLayout = QVBoxLayout( self )
61 verticalLayout.setContentsMargins( 1, 1, 1, 1 )
63 self.splitter = QSplitter( Qt.Vertical )
65 self.variablesViewer = VariablesViewer( self.__debugger,
66 self.splitter )
67 self.stackViewer = StackViewer( self.__debugger, self.splitter )
68 self.threadsViewer = ThreadsViewer( self.__debugger, self.splitter )
70 self.splitter.addWidget( self.variablesViewer )
71 self.splitter.addWidget( self.stackViewer )
72 self.splitter.addWidget( self.threadsViewer )
74 self.splitter.setCollapsible( 0, False )
75 self.splitter.setCollapsible( 1, False )
76 self.splitter.setCollapsible( 2, False )
78 verticalLayout.addWidget( self.splitter )
79 return
81 def clear( self ):
82 " Clears everything "
83 self.variablesViewer.clear()
84 self.stackViewer.clear()
85 self.threadsViewer.clear()
86 return
88 def __onClientLine( self, fileName, line, forStack ):
89 " Handles the signal from the debugged program "
90 if not forStack:
91 self.__debugger.remoteThreadList()
92 self.__debugger.remoteClientVariables( 1, 0 ) # globals
93 self.__debugger.remoteClientVariables( 0, 0 ) # locals
94 return
96 def onClientStack( self, stack ):
97 " Handles the signal from the debugged program "
98 self.stackViewer.populate( stack )
99 return
101 def __onClientThreadList( self, currentThreadID, threadList ):
102 " Handles the thread list from the remote client "
103 self.threadsViewer.populate( currentThreadID, threadList )
104 return
106 def __onClientVariables( self, scope, variables ):
107 " Handles the client variables lists "
108 frameNumber = self.stackViewer.getFrameNumber()
109 if scope in [ -1, 0 ]:
110 # Empty list for local variables
111 self.variablesViewer.updateVariables( False, frameNumber, variables )
112 else:
113 self.variablesViewer.updateVariables( True, frameNumber, variables )
114 return
116 def __onClientVariable( self, scope, variables ):
117 " Handles the client variable list "
118 if scope in [ -1, 0 ]:
119 self.variablesViewer.updateVariable( False, variables )
120 else:
121 self.variablesViewer.updateVariable( True, variables )
122 return
124 def __onClientThreadSet( self ):
125 " Handles the event of setting the current thread by the client "
126 self.__debugger.remoteClientVariables( 1, 0 ) # globals
127 self.__debugger.remoteClientVariables( 0, 0 ) # locals
128 return
130 def switchControl( self, isInIDE ):
131 " Switches the UI depending where the control flow is "
132 self.variablesViewer.switchControl( isInIDE )
133 self.stackViewer.switchControl( isInIDE )
134 self.threadsViewer.switchControl( isInIDE )
135 return
137 def getCurrentFrameNumber( self ):
138 " Provides the current frame number "
139 return self.stackViewer.getFrameNumber()