tweak DumpGenderStats tool (enable GUI to be closed, neaten CLI output)

This commit is contained in:
Paul Franklin 2017-01-16 09:22:01 -08:00
parent 659329c879
commit ec9d6e8fa7

View File

@ -24,12 +24,23 @@
Tools/Debug/Dump Gender Statistics Tools/Debug/Dump Gender Statistics
""" """
#-------------------------------------------------------------------------
#
# GTK/Gnome modules
#
#-------------------------------------------------------------------------
from gi.repository import Gtk
#-------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext _ = glocale.translation.gettext
from gi.repository import Gtk
from gramps.gui.listmodel import ListModel, INTEGER from gramps.gui.listmodel import ListModel, INTEGER
from gramps.gui.managedwindow import ManagedWindow from gramps.gui.managedwindow import ManagedWindow
from gramps.gui.plug import tool from gramps.gui.plug import tool
_GENDER = [ _('female'), _('male'), _('unknown') ] _GENDER = [ _('female'), _('male'), _('unknown') ]
@ -45,9 +56,6 @@ class DumpGenderStats(tool.Tool, ManagedWindow):
uistate = user.uistate uistate = user.uistate
self.label = _("Gender Statistics tool") self.label = _("Gender Statistics tool")
tool.Tool.__init__(self, dbstate, options_class, name) tool.Tool.__init__(self, dbstate, options_class, name)
if uistate:
ManagedWindow.__init__(self,uistate,[],
self.__class__)
stats_list = [] stats_list = []
for name, value in dbstate.db.genderStats.stats.items(): for name, value in dbstate.db.genderStats.stats.items():
@ -58,33 +66,51 @@ class DumpGenderStats(tool.Tool, ManagedWindow):
) )
if uistate: if uistate:
titles = [ ManagedWindow.__init__(self, uistate, [], self.__class__)
(_('Name'),0,100),
(_('Male'),1,70,INTEGER), titles = [(_('Name'), 0, 100),
(_('Female'),2,70,INTEGER), (_('Male'), 1, 70, INTEGER),
(_('Unknown'),3,70,INTEGER), (_('Female'), 2, 70, INTEGER),
(_('Guess'),4,70) (_('Unknown'), 3, 90, INTEGER),
] (_('Guess'), 4, 70)]
treeview = Gtk.TreeView() treeview = Gtk.TreeView()
model = ListModel(treeview, titles) model = ListModel(treeview, titles)
for entry in sorted(stats_list): for entry in sorted(stats_list):
model.add(entry, entry[0]) model.add(entry, entry[0])
window = Gtk.Window() # TODO there needs to be a way to "close" it
s = Gtk.ScrolledWindow() s = Gtk.ScrolledWindow()
s.add(treeview) s.add(treeview)
window.add(s) dialog = Gtk.Dialog()
window.show_all() dialog.add_button(_('_Close'), Gtk.ResponseType.CLOSE)
self.set_window(window, None, self.label) dialog.connect('response', self._response)
self.setup_configs('interface.dumpgenderstats', 400, 300) dialog.vbox.pack_start(s, expand=True, fill=True, padding=0)
self.set_window(dialog, None, self.label)
self.setup_configs('interface.dumpgenderstats', 420, 300)
self.show() self.show()
else: else:
print('\t%s'*5 % ('Name','Male','Female','Unknown','Guess')) if len(_('Name')) < 16:
print('%s%s%s' % (_('Name'),
" " * (16 - len(_('Name'))),
_('Male')),
'\t%s'*3 % (_('Female'), _('Unknown'), _('Guess')))
else:
print(_('Name'), '\t%s'*4 % (_('Male'), _('Female'),
_('Unknown'), _('Guess')))
print() print()
for entry in stats_list: for entry in sorted(stats_list):
print('\t%s'*5 % entry) if len(entry[0]) < 16:
print('%s%s%s' % (entry[0],
" " * (16 - len(entry[0])),
entry[1]),
'\t%s'*3 % (entry[2:]))
else:
print(entry[0], '\t%s'*4 % (entry[1:]))
def _response(self, obj, response_id):
if response_id == Gtk.ResponseType.CLOSE:
self.close()
def build_menu_names(self, obj): def build_menu_names(self, obj):
return (self.label,None) return (self.label,None)