From 07bdb1902811a0a49e73536480d67d993041d1f0 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sun, 30 Dec 2007 03:46:39 +0000 Subject: [PATCH] 2007-12-29 Douglas S. Blank * src/DataViews/MyGrampsView.py: show matching surnames * src/plugins/OnThisDay.py: refinement * src/plugins/SameSurnames.py: changed name * src/plugins/DefaultGadgets.py: calendar calls quickreport * src/QuickReports.py: new function to call qr directly * src/Simple/_SimpleAccess.py: new func to format dates svn: r9633 --- ChangeLog | 8 ++++++++ src/DataViews/MyGrampsView.py | 7 +++++++ src/QuickReports.py | 19 +++++++++++++++++-- src/Simple/_SimpleAccess.py | 14 ++++++++++++++ src/plugins/DefaultGadgets.py | 31 +++++++++++++++++++++---------- src/plugins/OnThisDay.py | 4 +++- src/plugins/SameSurnames.py | 2 +- 7 files changed, 71 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6b806567f..f0f12b637 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-12-29 Douglas S. Blank + * src/DataViews/MyGrampsView.py: show matching surnames + * src/plugins/OnThisDay.py: refinement + * src/plugins/SameSurnames.py: changed name + * src/plugins/DefaultGadgets.py: calendar calls quickreport + * src/QuickReports.py: new function to call qr directly + * src/Simple/_SimpleAccess.py: new func to format dates + 2007-12-29 Douglas S. Blank * src/DataViews/MyGrampsView.py: fixme's are fixed * src/DataViews/EventView.py: added quick report popup diff --git a/src/DataViews/MyGrampsView.py b/src/DataViews/MyGrampsView.py index 01ed2b7b3..c4820b87d 100644 --- a/src/DataViews/MyGrampsView.py +++ b/src/DataViews/MyGrampsView.py @@ -42,6 +42,7 @@ import PageView import ManagedWindow import ConfigParser import Utils +from QuickReports import run_quick_report_by_name AVAILABLE_GADGETS = {} GADGET_FILENAME = os.path.join(const.HOME_DIR,"gadgets.ini") @@ -340,6 +341,12 @@ class Gadget(object): self.gui.dbstate.change_active_person(person) return True # handled event elif link_type == 'Surname': + 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, + 'samesurnames', + handle) return True return False # did not handle event diff --git a/src/QuickReports.py b/src/QuickReports.py index b921a4de4..d209baa3c 100644 --- a/src/QuickReports.py +++ b/src/QuickReports.py @@ -110,6 +110,21 @@ def by_menu_name(first, second): def make_quick_report_callback(lst, category, dbstate, uistate, handle): return lambda x: run_report(dbstate, uistate, category, handle, lst[0]) + +def run_quick_report_by_name(dbstate, uistate, report_name, handle): + from PluginUtils import quick_report_list + # [0] - function + # [1] - translated name + # [2] - category + # [3] - name + # [5] - status + report = None + for item in quick_report_list: + if item[3] == report_name: + report = item + break + if report: + run_report(dbstate, uistate, report[2], handle, report[0]) def run_report(dbstate, uistate, category,handle,func): from TextBufDoc import TextBufDoc @@ -131,9 +146,9 @@ def run_report(dbstate, uistate, category,handle,func): obj = dbstate.db.get_place_from_handle(handle) elif category == CATEGORY_QR_REPOSITORY : obj = dbstate.db.get_repository_from_handle(handle) - else : + else: obj = None - if obj : + if obj: d.open("") func(dbstate.db, d, obj) d.close() diff --git a/src/Simple/_SimpleAccess.py b/src/Simple/_SimpleAccess.py index 94bcd1de9..6f3975012 100644 --- a/src/Simple/_SimpleAccess.py +++ b/src/Simple/_SimpleAccess.py @@ -491,6 +491,20 @@ class SimpleAccess: else: return u'' + def date_string(self, date_obj): + """ + Returns a string representation a date_obj + + @param date_obj: Date object + @type date_obj: L{gen.lib.Date} + @return: Returns a string representation a date_obj + @rtype: unicode + """ + if date_obj: + return DateHandler.displayer.display(date_obj) + else: + return u'' + def event_date(self, event): """ Returns a string indicating the date of the event diff --git a/src/plugins/DefaultGadgets.py b/src/plugins/DefaultGadgets.py index 871259a53..fc052faa0 100644 --- a/src/plugins/DefaultGadgets.py +++ b/src/plugins/DefaultGadgets.py @@ -1,7 +1,3 @@ -from DataViews import register, Gadget -from BasicUtils import name_displayer -import DateHandler -import gen.lib import sys import os import re @@ -9,6 +5,12 @@ import time import string import urllib +import gen.lib +from DataViews import register, Gadget +from BasicUtils import name_displayer +from QuickReports import run_quick_report_by_name +import DateHandler + # # Hello World, in Gramps Gadgets # @@ -74,9 +76,10 @@ class CalendarGadget(Gadget): self.gui.calendar.clear_marks() year, month, day = self.gui.calendar.get_date() for date in self.dates: - if date[1] != 0 and date[1] == month + 1: - if date[2] > 0 and date[2] <= day: - self.gui.calendar.mark_day(date[2]) + if ((date[0] == year) and + (date[1] == month + 1) and + (date[2] > 0 and date[2] <= day)): + self.gui.calendar.mark_day(date[2]) self.gui.calendar.thaw() def main(self): @@ -98,13 +101,19 @@ class CalendarGadget(Gadget): month = birth_date.get_month() day = birth_date.get_day() #age = self.year - year - self.dates[(year, month, day)] = 1 + self.dates[(year, month, day)] = birth_event.handle cnt += 1 self.refresh() def double_click(self, obj): # bring up events on this day - pass + year, month, day = self.gui.calendar.get_date() + month += 1 + if (year, month, day) in self.dates: + run_quick_report_by_name(self.gui.dbstate, + self.gui.uistate, + 'onthisday', + self.dates[(year, month, day)]) class LogGadget(Gadget): def db_changed(self): @@ -180,12 +189,14 @@ class TopSurnamesGadget(Gadget): self.set_text("Processing...\n") people = self.dbstate.db.get_person_handles(sort_handles=False) surnames = {} + representative_handle = {} cnt = 0 for person_handle in people: person = self.dbstate.db.get_person_from_handle(person_handle) if person: surname = person.get_primary_name().get_surname().strip() surnames[surname] = surnames.get(surname, 0) + 1 + representative_handle[surname] = person_handle if cnt % 350 == 0: yield True cnt += 1 @@ -206,7 +217,7 @@ class TopSurnamesGadget(Gadget): self.set_text("") for (count, surname) in surname_sort: self.append_text(" %d. " % (line + 1)) - self.link(surname, 'Surname', surname) + self.link(surname, 'Surname', representative_handle[surname]) self.append_text(", %d%% (%d)\n" % (int((float(count)/total) * 100), count)) line += 1 diff --git a/src/plugins/OnThisDay.py b/src/plugins/OnThisDay.py index 894d50a64..849613099 100644 --- a/src/plugins/OnThisDay.py +++ b/src/plugins/OnThisDay.py @@ -39,6 +39,8 @@ def run(database, document, main_event): """ Loops through the families that the person is a child in, and display the information about the other children. + + Takes an Event handle """ # setup the simple access functions sdb = SimpleAccess(database) @@ -50,7 +52,7 @@ def run(database, document, main_event): main_date = main_event.get_date_object() # display the title - sdoc.title(_("Events of %s") % sdb.event_date(main_event)) + sdoc.title(_("Events of %s") % sdb.date_string(main_date)) sdoc.paragraph("") stab.columns(_("Date"), _("Type"), _("Place"), _("Reference")) yeartab.columns(_("Date"), _("Type"), _("Place"), _("Reference")) diff --git a/src/plugins/SameSurnames.py b/src/plugins/SameSurnames.py index bcecc702c..05b56cc14 100644 --- a/src/plugins/SameSurnames.py +++ b/src/plugins/SameSurnames.py @@ -64,7 +64,7 @@ def run(database, document, person): # #------------------------------------------------------------------------ register_quick_report( - name = 'surnames', + name = 'samesurnames', category = CATEGORY_QR_PERSON, run_func = run, translated_name = _("Same Surnames"),