Convert uncollected objects tool into a gramplet

svn: r23243
This commit is contained in:
Nick Hall 2013-10-03 16:02:48 +00:00
parent 6aaccd4ca0
commit ac35859e27
4 changed files with 54 additions and 225 deletions

View File

@ -1180,3 +1180,16 @@ register(GRAMPLET,
gramplet = 'PythonEvaluation',
gramplet_title=_("Python Evaluation"),
)
register(GRAMPLET,
id="Uncollected Objects",
name=_("Uncollected Objects"),
description = _("Gramplet showing uncollected objects"),
version="1.0.0",
gramps_target_version="4.1",
status = STABLE,
fname="leak.py",
height=200,
gramplet = 'Leak',
gramplet_title=_("Uncollected Objects"),
)

View File

@ -47,48 +47,59 @@ else:
#------------------------------------------------------------------------
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import Pango
import gc
#------------------------------------------------------------------------
#
# GRAMPS modules
# Gramps modules
#
#------------------------------------------------------------------------
from gramps.gui.plug import tool
from gramps.gui.managedwindow import ManagedWindow
from gramps.gen.plug import Gramplet
from gramps.gui.dialog import InfoDialog
from gramps.gui.glade import Glade
from gramps.gui.utils import is_right_click
#-------------------------------------------------------------------------
#
# Actual tool
# Leak
#
#-------------------------------------------------------------------------
class Leak(tool.Tool, ManagedWindow):
def __init__(self,dbstate, user, options_class, name, callback=None):
uistate = user.uistate
self.title = _('Uncollected Objects Tool')
class Leak(Gramplet):
"""
Shows uncollected objects.
"""
def init(self):
self.gui.WIDGET = self.build_gui()
self.gui.get_container_widget().remove(self.gui.textview)
self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET)
tool.Tool.__init__(self,dbstate, options_class, name)
ManagedWindow.__init__(self,uistate,[],self.__class__)
flags = gc.DEBUG_UNCOLLECTABLE|gc.DEBUG_SAVEALL
if hasattr(gc, "DEBUG_OBJECTS"):
flags = flags | gc.DEBUG_OBJECTS
gc.set_debug(flags)
self.glade = Glade()
def build_gui(self):
"""
Build the GUI interface.
"""
self.top = Gtk.VBox()
self.top.set_border_width(6)
self.window = self.glade.toplevel
self.scroll = self.glade.get_object("scrolledwindow1")
self.label = Gtk.Label()
self.label.set_alignment(0, 0.5)
self.top.pack_start(self.label, False, False, 6)
self.scroll = Gtk.ScrolledWindow()
#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)
self.scroll.add_with_viewport(self.list)
#make a model
self.modeldata = []
self.model = Gtk.ListStore(int, str)
self.list.set_model(self.model)
#set the colums
#set the columns
self.renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(_('Number'), self.renderer, text=0)
column.set_resizable(True)
@ -100,25 +111,20 @@ class Leak(tool.Tool, ManagedWindow):
column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
self.list.append_column(column)
self.selection = self.list.get_selection()
self.top.pack_start(self.scroll, True, True, 6)
flags = gc.DEBUG_UNCOLLECTABLE|gc.DEBUG_SAVEALL
if hasattr(gc, "DEBUG_OBJECTS"):
flags = flags | gc.DEBUG_OBJECTS
gc.set_debug(flags)
bbox = Gtk.HButtonBox()
apply_button = Gtk.Button(_("Refresh"))
apply_button.connect('clicked', self.apply_clicked)
bbox.pack_start(apply_button, False, False, 6)
self.top.pack_start(bbox, False, False, 6)
self.set_window(self.window, self.glade.get_object('title'),
self.title)
self.top.show_all()
self.glade.connect_signals({
"on_apply_clicked" : self.apply_clicked,
"on_close_clicked" : self.close,
"on_delete_event" : self.close,
})
return self.top
def main(self):
self.display()
self.show()
def build_menu_names(self, obj):
return (self.title,None)
def _button_press(self, obj, event):
if event.type == Gdk.EventType._2BUTTON_PRESS and event.button == 1:
@ -140,7 +146,7 @@ class Leak(tool.Tool, ManagedWindow):
except ReferenceError:
pass
InfoDialog(_('Referrers of %d') % count, text,
parent=self.window)
parent=self.uistate.window)
def refers_to(self):
model, iter = self.selection.get_selected()
@ -154,7 +160,7 @@ class Leak(tool.Tool, ManagedWindow):
except ReferenceError:
pass
InfoDialog(_('%d refers to') % count, text,
parent=self.window)
parent=self.uistate.window)
def display(self):
gc.collect(2)
@ -171,20 +177,7 @@ class Leak(tool.Tool, ManagedWindow):
except ReferenceError:
pass
count += 1
self.glade.get_object('label2').set_text(_('Uncollected Objects: %s') % str(len(gc.garbage)))
self.label.set_text(_('Uncollected Objects: %s') % str(len(gc.garbage)))
def apply_clicked(self, obj):
self.display()
#------------------------------------------------------------------------
#
#
#
#------------------------------------------------------------------------
class LeakOptions(tool.ToolOptions):
"""
Defines options and provides handling interface.
"""
def __init__(self, name,person_id=None):
tool.ToolOptions.__init__(self, name,person_id)

View File

@ -1,155 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkDialog" id="leak">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="default_width">450</property>
<property name="default_height">500</property>
<property name="type_hint">dialog</property>
<signal name="delete-event" handler="on_delete_event" swapped="no"/>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button2">
<property name="label">gtk-refresh</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_apply_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button3">
<property name="label">gtk-close</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="on_close_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="title">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="n_rows">2</property>
<property name="column_spacing">6</property>
<property name="row_spacing">6</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Uncollected Objects</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
<property name="y_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHButtonBox" id="hbuttonbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="spacing">6</property>
<property name="layout_style">end</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">button2</action-widget>
<action-widget response="0">button3</action-widget>
</action-widgets>
</object>
</interface>

View File

@ -208,28 +208,6 @@ optionclass = 'MergeOptions',
tool_modes = [TOOL_MODE_GUI]
)
#------------------------------------------------------------------------
#
# Show Uncollected Objects
#
#------------------------------------------------------------------------
register(TOOL,
id = 'leak',
name = "Show Uncollected Objects",
description = "Provide a window listing all uncollected objects",
version = '1.0',
gramps_target_version = '4.1',
status = STABLE,
fname = 'leak.py',
authors = ["Donald N. Allingham"],
authors_email = ["don@gramps-project.org"],
category = TOOL_DEBUG,
toolclass = 'Leak',
optionclass = 'LeakOptions',
tool_modes = [TOOL_MODE_GUI]
)
#------------------------------------------------------------------------
#
# Media Manager