view/threads.py

Go to the documentation of this file.
00001 # Copyright (c) 2006 Cristian L. Vlasceanu
00002 #
00003 # Permission is hereby granted, free of charge, to any person
00004 # obtaining a copy of this software and associated documentation
00005 # files (the "Software"), to deal in the Software without
00006 # restriction, including without limitation the rights to use,
00007 # copy, modify, merge, publish, distribute, sublicense, and/or
00008 # sell copies of the Software, and to permit persons to whom
00009 # the Software is furnished to do so, subject to the following
00010 # conditions:
00011 # 
00012 # The above copyright notice and this permission notice shall be
00013 # included in all copies or substantial portions of the Software.
00014 # 
00015 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
00016 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
00017 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00018 # AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00019 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00020 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00021 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
00022 # OR OTHER DEALINGS IN THE SOFTWARE.
00023 # 
00024 # NOTE: The above applies solely to Python source code provided 
00025 # herein, and it DOES NOT COVER the Zero Debugger Engine and plug-ins.
00026 #
00027 from base import Base
00028 import gobject
00029 import gtk
00030 
00031 
00032 class Threads(Base):
00033         """
00034         Threads View, displays the debuggee threads
00035         """
00036         def __init__(self, tree):
00037                 Base.__init__(self)
00038                 self.__selected = False
00039                 self.__debugger = None
00040                 self.__model = gtk.ListStore(
00041                         gobject.TYPE_PYOBJECT,
00042                         gobject.TYPE_STRING,
00043                         gobject.TYPE_STRING,
00044                 )
00045                 if tree:
00046                         self.__view = tree
00047                         tree.set_model(self.__model)
00048                         renderer = gtk.CellRendererText()
00049                         tree.append_column(gtk.TreeViewColumn("PID", renderer, text=1))
00050                         tree.append_column(gtk.TreeViewColumn("Thread ID", renderer, text=2))
00051                         tree.get_column(0).set_resizable(True)
00052 
00053                         tree.connect("cursor-changed", self.on_thread_selected)
00054 
00055 
00056         def update(self, event):
00057                 if self.__selected:
00058                         self.__selected = False
00059                 else:
00060                         thread = event.thread()
00061 
00062                         if thread is None:
00063                                 self.clear()
00064                         else:
00065                                 self.__debugger = thread.debugger()
00066                                 process = thread.process()
00067                                 if process:
00068                                         model = self.__model
00069                                         model.clear()
00070                                         for t in process.threads():
00071                                                 #print '-----',t.lwpid(),'-----'
00072                                                 iter = model.append()
00073                                                 model.set_value(iter, 1, t.lwpid())
00074                                                 model.set_value(iter, 2, t.id())
00075 
00076 
00077         def clear(self):
00078                 self.__model.clear()
00079 
00080 
00081         def on_thread_selected(self, view):
00082                 if not self.__selected:
00083                         self.__selected = True
00084                         (model, iter) = view.get_selection().get_selected()
00085                         if iter:
00086                                 pid = long(model.get_value(iter, 1))
00087                                 tid = long(model.get_value(iter, 2))
00088                                 self.__debugger.select_thread(pid, tid)
00089