Make Leak into a treeview, double click to have referrers, right click
to obtain referents of selected line svn: r12057
This commit is contained in:
parent
8541c74f4b
commit
52b0b13507
@ -40,6 +40,8 @@ from bsddb.db import DBError
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gtk import glade
|
||||
import gtk
|
||||
import pango
|
||||
import gc
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
@ -50,6 +52,7 @@ import gc
|
||||
from PluginUtils import Tool
|
||||
from gen.plug import PluginManager
|
||||
import ManagedWindow
|
||||
from QuestionDialog import InfoDialog
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -66,12 +69,35 @@ class Leak(Tool.Tool,ManagedWindow.ManagedWindow):
|
||||
glade_file = os.path.dirname(__file__) + os.sep + "leak.glade"
|
||||
self.glade = glade.XML(glade_file,"top","gramps")
|
||||
|
||||
window = self.glade.get_widget("top")
|
||||
self.eval = self.glade.get_widget("eval")
|
||||
self.ebuf = self.eval.get_buffer()
|
||||
self.window = self.glade.get_widget("top")
|
||||
self.scroll = self.glade.get_widget("scrolledwindow1")
|
||||
#add a listview to the scrollable
|
||||
self.list = gtk.TreeView()
|
||||
self.list.set_headers_visible(True)
|
||||
self.list.connect('button-press-event', self._button_press)
|
||||
self.scroll.add(self.list)
|
||||
#make a model
|
||||
self.modeldata = []
|
||||
self.model = gtk.ListStore(int, str)
|
||||
self.list.set_model(self.model)
|
||||
|
||||
#set the colums
|
||||
self.renderer = gtk.CellRendererText()
|
||||
column = gtk.TreeViewColumn(_('Number'), self.renderer, text=0)
|
||||
column.set_resizable(True)
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
self.list.append_column(column)
|
||||
column = gtk.TreeViewColumn(_('Uncollected object'), self.renderer,
|
||||
text=1)
|
||||
column.set_resizable(True)
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
|
||||
self.list.append_column(column)
|
||||
self.selection = self.list.get_selection()
|
||||
|
||||
gc.set_debug(gc.DEBUG_UNCOLLECTABLE|gc.DEBUG_OBJECTS|gc.DEBUG_SAVEALL)
|
||||
|
||||
self.set_window(window,self.glade.get_widget('title'),self.title)
|
||||
self.set_window(self.window, self.glade.get_widget('title'),
|
||||
self.title)
|
||||
|
||||
self.glade.signal_autoconnect({
|
||||
"on_apply_clicked" : self.apply_clicked,
|
||||
@ -83,23 +109,49 @@ class Leak(Tool.Tool,ManagedWindow.ManagedWindow):
|
||||
def build_menu_names(self, obj):
|
||||
return (self.title,None)
|
||||
|
||||
def _button_press(self, obj, event):
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS and event.button == 1:
|
||||
self.referenced_in()
|
||||
return True
|
||||
elif event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
||||
self.refers_to()
|
||||
return True
|
||||
|
||||
def referenced_in(self):
|
||||
model, iter = self.selection.get_selected()
|
||||
if iter is not None:
|
||||
count = model.get_value(iter, 0)
|
||||
referrers = gc.get_referrers(self.modeldata[count])
|
||||
text = ""
|
||||
for referrer in referrers:
|
||||
text += str(referrer) + '\n'
|
||||
InfoDialog(_('Referrers of %d') % count, text,
|
||||
parent=self.window)
|
||||
|
||||
def refers_to(self):
|
||||
model, iter = self.selection.get_selected()
|
||||
if iter is not None:
|
||||
count = model.get_value(iter, 0)
|
||||
referents = gc.get_referents(self.modeldata[count])
|
||||
text = ""
|
||||
for referent in referents:
|
||||
text += str(referent) + '\n'
|
||||
InfoDialog(_('%d refers to') % count, text,
|
||||
parent=self.window)
|
||||
|
||||
def display(self):
|
||||
gc.collect()
|
||||
mylist = []
|
||||
self.model.clear()
|
||||
count = 0
|
||||
if len(gc.garbage):
|
||||
for each in gc.garbage:
|
||||
try:
|
||||
mylist.append(str(each))
|
||||
self.modeldata.append(each)
|
||||
self.model.append((count, str(each)))
|
||||
except DBError:
|
||||
mylist.append('db.DB instance at %s' % id(each))
|
||||
self.ebuf.set_text(_("%d uncollected objects:\n\n" % len(mylist)))
|
||||
count = 1
|
||||
for line in mylist:
|
||||
self.ebuf.insert_at_cursor(" %d) %s\n" % (count, line))
|
||||
self.modeldata.append(each)
|
||||
self.model.append((count, 'db.DB instance at %s' % id(each)))
|
||||
count += 1
|
||||
else:
|
||||
self.ebuf.set_text(_("No uncollected objects\n")
|
||||
+ str(gc.get_debug()))
|
||||
|
||||
def apply_clicked(self, obj):
|
||||
self.display()
|
||||
|
@ -18,6 +18,8 @@
|
||||
<property name="skip_pager_hint">False</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
|
||||
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
|
||||
<property name="focus_on_map">True</property>
|
||||
<property name="urgency_hint">False</property>
|
||||
<property name="has_separator">False</property>
|
||||
<signal name="delete_event" handler="on_delete_event" last_modification_time="Fri, 25 Mar 2005 00:15:07 GMT"/>
|
||||
|
||||
@ -88,6 +90,10 @@
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
|
||||
<property name="width_chars">-1</property>
|
||||
<property name="single_line_mode">False</property>
|
||||
<property name="angle">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
@ -101,48 +107,11 @@
|
||||
<property name="border_width">6</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="n_rows">2</property>
|
||||
<property name="n_columns">2</property>
|
||||
<property name="n_columns">1</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="row_spacing">6</property>
|
||||
<property name="column_spacing">6</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="shadow_type">GTK_SHADOW_IN</property>
|
||||
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
|
||||
|
||||
<child>
|
||||
<widget class="GtkTextView" id="eval">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="editable">True</property>
|
||||
<property name="overwrite">False</property>
|
||||
<property name="accepts_tab">True</property>
|
||||
<property name="justification">GTK_JUSTIFY_LEFT</property>
|
||||
<property name="wrap_mode">GTK_WRAP_NONE</property>
|
||||
<property name="cursor_visible">True</property>
|
||||
<property name="pixels_above_lines">0</property>
|
||||
<property name="pixels_below_lines">0</property>
|
||||
<property name="pixels_inside_wrap">0</property>
|
||||
<property name="left_margin">0</property>
|
||||
<property name="right_margin">0</property>
|
||||
<property name="indent">0</property>
|
||||
<property name="text" translatable="yes"></property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label2">
|
||||
<property name="visible">True</property>
|
||||
@ -156,16 +125,43 @@
|
||||
<property name="yalign">0.5</property>
|
||||
<property name="xpad">0</property>
|
||||
<property name="ypad">0</property>
|
||||
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
|
||||
<property name="width_chars">-1</property>
|
||||
<property name="single_line_mode">False</property>
|
||||
<property name="angle">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="right_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
<property name="bottom_attach">1</property>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
|
||||
<child>
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
|
||||
<property name="shadow_type">GTK_SHADOW_IN</property>
|
||||
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
|
||||
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="right_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="x_options">expand|shrink|fill</property>
|
||||
<property name="y_options">expand|shrink|fill</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
|
Loading…
Reference in New Issue
Block a user