From 3c9ffd061e535220527a639c0a0463b5f5eb3c08 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Tue, 6 Jan 2009 05:01:17 +0000 Subject: [PATCH] New Given Name Cloud Gramplet by Pander Musubi, and new links to run Same Given Quick View svn: r11577 --- po/POTFILES.in | 1 + src/DataViews/GrampletView.py | 8 +++ src/plugins/GivenNameGramplet.py | 105 +++++++++++++++++++++++++++++++ src/plugins/Makefile.am | 1 + 4 files changed, 115 insertions(+) create mode 100644 src/plugins/GivenNameGramplet.py diff --git a/po/POTFILES.in b/po/POTFILES.in index f74fdc5c1..dae62b1d7 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -276,6 +276,7 @@ src/plugins/FamilyGroup.py src/plugins/FanChart.py src/plugins/FilterByName.py src/plugins/FindDupes.py +src/plugins/GivenNameGramplet.py src/plugins/GVFamilyLines.py src/plugins/GVHourGlass.py src/plugins/GVRelGraph.py diff --git a/src/DataViews/GrampletView.py b/src/DataViews/GrampletView.py index f31d569e9..53d876c51 100644 --- a/src/DataViews/GrampletView.py +++ b/src/DataViews/GrampletView.py @@ -451,6 +451,14 @@ class Gramplet(object): 'samesurnames', handle) return True + elif link_type == 'Given': + if event.button == 1: # left mouse + if event.type == gtk.gdk._2BUTTON_PRESS: # double + run_quick_report_by_name(self.gui.dbstate, + self.gui.uistate, + 'samegivens_misc', + handle) + return True elif link_type == 'Filter': if event.button == 1: # left mouse if event.type == gtk.gdk._2BUTTON_PRESS: # double diff --git a/src/plugins/GivenNameGramplet.py b/src/plugins/GivenNameGramplet.py new file mode 100644 index 000000000..d412f61ee --- /dev/null +++ b/src/plugins/GivenNameGramplet.py @@ -0,0 +1,105 @@ +from gettext import gettext as _ + +from DataViews import Gramplet, register +import Config + +def make_tag_size(n, counts, mins=8, maxs=20): + # return font sizes mins to maxs + diff = maxs - mins + # based on counts (biggest to smallest) + if len(counts) > 1: + position = diff - (diff * (float(counts.index(n)) / (len(counts) - 1))) + else: + position = 0 + return int(position) + mins + +class GivenNameCloudGramplet(Gramplet): + def init(self): + self.tooltip = _("Double-click given name for details") + self.top_size = 100 # will be overwritten in load + self.set_text(_("No Family Tree loaded.")) + + def db_changed(self): + self.dbstate.db.connect('person-add', self.update) + self.dbstate.db.connect('person-delete', self.update) + self.dbstate.db.connect('person-update', self.update) + + def on_load(self): + if len(self.gui.data) > 0: + self.top_size = int(self.gui.data[0]) + + def on_save(self): + self.gui.data = [self.top_size] + + def main(self): + self.set_text(_("Processing...") + "\n") + people = self.dbstate.db.get_person_handles(sort_handles=False) + givensubnames = {} + representative_handle = {} + cnt = 0 + for person_handle in people: + person = self.dbstate.db.get_person_from_handle(person_handle) + if person: + allnames = [person.get_primary_name()] + person.get_alternate_names() + allnames = set([name.get_first_name().strip() for name in allnames]) + for givenname in allnames: + for givensubname in givenname.split(): + givensubnames[givensubname] = givensubnames.get(givensubname, 0) + 1 + representative_handle[givensubname] = person_handle + if cnt % 350 == 0: + yield True + cnt += 1 + total_people = cnt + givensubname_sort = [] + total = 0 + cnt = 0 + for givensubname in givensubnames: + givensubname_sort.append( (givensubnames[givensubname], givensubname) ) + total += givensubnames[givensubname] + if cnt % 350 == 0: + yield True + cnt += 1 + total_givensubnames = cnt + givensubname_sort.sort(lambda a,b: -cmp(a,b)) + cloud_names = [] + cloud_values = [] + cnt = 0 + for (count, givensubname) in givensubname_sort: + cloud_names.append( (count, givensubname) ) + cloud_values.append( count ) + if cnt > self.top_size: + break + cnt += 1 + cloud_names.sort(lambda a,b: cmp(a[1], b[1])) + counts = list(set(cloud_values)) + counts.sort() + counts.reverse() + line = 0 + ### All done! + self.set_text("") + for (count, givensubname) in cloud_names: # givensubname_sort: + if len(givensubname) == 0: + text = Config.get(Config.NO_SURNAME_TEXT) + else: + text = givensubname + size = make_tag_size(count, counts) + self.link(text, 'Given', text, size, + "%s, %d%% (%d)" % (text, + int((float(count)/total) * 100), + count)) + self.append_text(" ") + line += 1 + if line >= self.top_size: + break + self.append_text(("\n" + _("Total unique given names") + ": %d\n") % + total_givensubnames) + self.append_text((_("Total people") + ": %d") % total_people, "begin") + +register(type="gramplet", + name= "Given Name Cloud Gramplet", + tname=_("Given Name Cloud Gramplet"), + height=300, + expand=True, + content = GivenNameCloudGramplet, + title=_("Given Name Cloud"), + ) diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 78f597afa..8f8db1fa1 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -46,6 +46,7 @@ pkgdata_PYTHON = \ FanChart.py\ FilterByName.py\ FindDupes.py\ + GivenNameGramplet.py\ GVFamilyLines.py \ GVHourGlass.py\ GVRelGraph.py\