view/data.py

Go to the documentation of this file.
00001 #
00002 # Copyright (c) 2006 Cristian L. Vlasceanu
00003 #
00004 # Permission is hereby granted, free of charge, to any person
00005 # obtaining a copy of this software and associated documentation
00006 # files (the "Software"), to deal in the Software without
00007 # restriction, including without limitation the rights to use,
00008 # copy, modify, merge, publish, distribute, sublicense, and/or
00009 # sell copies of the Software, and to permit persons to whom
00010 # the Software is furnished to do so, subject to the following
00011 # conditions:
00012 # 
00013 # The above copyright notice and this permission notice shall be
00014 # included in all copies or substantial portions of the Software.
00015 # 
00016 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
00017 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
00018 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
00019 # AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00020 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00021 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
00023 # OR OTHER DEALINGS IN THE SOFTWARE.
00024 # 
00025 # NOTE: The above applies solely to Python source code provided 
00026 # herein, and it DOES NOT COVER the Zero Debugger Engine and plug-ins.
00027 #
00028 import gobject
00029 import gtk
00030 from base import Base
00031 import traceback
00032 
00033 
00034 def add_variable(view, model, iter, var):
00035         model.set_value(iter, 0, var)
00036         model.set_value(iter, 1, var.name())
00037         model.set_value(iter, 2, var.type().name())
00038         try:
00039                 model.set_value(iter, 3, unicode(var.value(), "utf-8"))
00040         except:
00041                 #traceback.print_exc()
00042                 pass
00043         if var.has_children():
00044                 #insert a place-holder
00045                 model.insert_before(iter, None)
00046         if var.is_expanded():
00047                 view.expand_row(model.get_path(iter), False)
00048                 
00049 
00050 class Data(Base):
00051         """
00052         Displays program data, which may be local and/or global 
00053         variables, data members, expression evaluation results, etc.
00054         """
00055         
00056         def __init__(self, tree):
00057                 Base.__init__(self)
00058                 self.__model = gtk.TreeStore(
00059                         gobject.TYPE_PYOBJECT, 
00060                         gobject.TYPE_STRING,
00061                         gobject.TYPE_STRING,
00062                         gobject.TYPE_STRING 
00063                 )
00064                 if tree:
00065                         self.__view = tree
00066                         tree.set_model(self.__model)
00067                         renderer = gtk.CellRendererText()
00068                         tree.append_column(gtk.TreeViewColumn("Name", renderer, text=1))
00069                         tree.append_column(gtk.TreeViewColumn("Type", renderer, text=2))
00070                         tree.append_column(gtk.TreeViewColumn("Value", renderer, text=3))
00071                         tree.get_column(0).set_resizable(True)
00072                         tree.get_column(1).set_resizable(True)
00073                         tree.connect("row-collapsed", self.on_row_collapsed)
00074                         tree.connect("row-expanded", self.on_row_expanded)
00075 
00076 
00077         def clear(self):
00078                 self.__model.clear()
00079 
00080         
00081         def show(self, vars):
00082                 self.clear()
00083                 for v in vars:
00084                         model = self.__model
00085                         iter = model.insert_before(None, None)
00086                         add_variable(self.__view, model, iter, v)
00087                 
00088 
00089         def on_row_collapsed(self, treeview, iter, path):
00090                 var = self.__model.get_value(iter, 0)
00091                 var.set_expanded(False)
00092 
00093 
00094         def on_row_expanded(self, treeview, iter, path):
00095                 model = self.__model
00096                 var = model.get_value(iter, 0)
00097                 var.set_expanded(True)
00098                 child = model.iter_nth_child(iter, 0)
00099                 if model.get_value(child, 0):
00100                         pass
00101                 else:
00102                         #has place-holder, replace with actual children
00103                         for v in var.children():
00104                                 i = model.insert_before(iter, None)
00105                                 add_variable(self.__view, model, i, v)
00106                         model.remove(child)
00107 
00108