From 5f7c6c1c8a4017b22e1de0b9b7adcd500b7acf88 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 28 Feb 2008 06:20:44 +0000 Subject: [PATCH] 2008-02-28 Douglas S. Blank * src/plugins/DefaultGramplets.py: new Pedigree Gramplet * src/DataViews/GrampletView.py: added help button on undocked windows svn: r10134 --- ChangeLog | 4 ++ src/DataViews/GrampletView.py | 27 ++++++++++- src/plugins/DefaultGramplets.py | 80 +++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index dde5215a2..98ae101d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-02-28 Douglas S. Blank + * src/plugins/DefaultGramplets.py: new Pedigree Gramplet + * src/DataViews/GrampletView.py: added help button on undocked windows + 2008-02-27 Raphael Ackermann * src/Editors/_EditNote.py: empty_object() add extratype to object 0001476: Opening the new note dialog/editor and cancelling shouldn't ask diff --git a/src/DataViews/GrampletView.py b/src/DataViews/GrampletView.py index f10718389..b8c715496 100644 --- a/src/DataViews/GrampletView.py +++ b/src/DataViews/GrampletView.py @@ -47,7 +47,20 @@ import ManagedWindow import ConfigParser import Utils from QuickReports import run_quick_report_by_name +import GrampsDisplay +#------------------------------------------------------------------------- +# +# Constants +# +#------------------------------------------------------------------------- +WIKI_HELP_PAGE = 'Gramps_3.0_Wiki_Manual_-_Gramplets' + +#------------------------------------------------------------------------- +# +# Globals +# +#------------------------------------------------------------------------- AVAILABLE_GRAMPLETS = {} GRAMPLET_FILENAME = os.path.join(const.HOME_DIR,"gramplets.ini") NL = "\n" @@ -136,11 +149,20 @@ class GrampletWindow(ManagedWindow.ManagedWindow): gtk.DIALOG_DESTROY_WITH_PARENT, (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)), None, self.title) + self.window.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP) self.window.set_size_request(gramplet.detached_width, gramplet.detached_height) - self.window.connect('response', self.close) + self.window.connect('response', self.handle_response) self.gramplet.mainframe.reparent(self.window.vbox) self.window.show() + + def handle_response(self, object, response): + if response == gtk.RESPONSE_CLOSE: + self.close() + else: + # translated name: + GrampsDisplay.help('gramplet', WIKI_HELP_PAGE, + self.gramplet.tname.replace(" ", "_")) def build_menu_names(self, obj): return (self.title, 'Gramplet') @@ -406,6 +428,7 @@ class GuiGramplet: self.title = title ########## Set defaults self.name = kwargs.get("name", "Unnamed Gramplet") + self.tname = kwargs.get("tname", "Unnamed Gramplet") self.expand = logical_true(kwargs.get("expand", False)) self.height = int(kwargs.get("height", 200)) self.column = int(kwargs.get("column", -1)) @@ -516,7 +539,7 @@ class GuiGramplet: self.textview.scroll_to_mark(end, 0.0, True, 0, 0) elif scroll_to == "start": # beginning of this append self.textview.scroll_to_mark(start, 0.0, True, 0, 0) - elif scroll_to == "begin": # beginning of this append + elif scroll_to == "begin": # beginning of the buffer begin_iter = self.buffer.get_start_iter() begin = self.buffer.create_mark(None, begin_iter, True) self.textview.scroll_to_mark(begin, 0.0, True, 0, 0) diff --git a/src/plugins/DefaultGramplets.py b/src/plugins/DefaultGramplets.py index d08156c87..5cfdeba6c 100644 --- a/src/plugins/DefaultGramplets.py +++ b/src/plugins/DefaultGramplets.py @@ -442,6 +442,78 @@ class RelativesGramplet(Gramplet): self.append_text(_("Unknown")) self.append_text("\n") +class PedigreeGramplet(Gramplet): + def init(self): + self.set_text(_("No Family Tree loaded.")) + self.tooltip = _("Click name to make person active\n") + \ + _("Right-click name to edit person") + self.max_generations = 100 + + def db_changed(self): + """ + If person or family changes, the relatives of active person might have + changed + """ + self.dbstate.db.connect('person-add', self.update) + self.dbstate.db.connect('person-delete', self.update) + self.dbstate.db.connect('family-add', self.update) + self.dbstate.db.connect('family-delete', self.update) + + def active_changed(self, handle): + self.update() + + def get_boxes(self, generation): + retval = "" + for i in range(generation+1): + if self._boxes[i]: + retval += " |" + else: + retval += " " + return retval + "--" + + def process_person(self, handle, generation, what): + if generation > self.max_generations: + return + person = self.dbstate.db.get_person_from_handle(handle) + family_list = person.get_parent_family_handle_list() + if what == "f": + if len(family_list) > 0: + family = self.dbstate.db.get_family_from_handle(family_list[0]) + father = family.get_father_handle() + if father: + self.process_person(father, generation + 1, "f") + self._boxes[generation] = 1 + self.process_person(father, generation + 1, "s") + self.process_person(father, generation + 1, "m") + if what == "s": + self.append_text(self.get_boxes(generation)) + self.link(name_displayer.display_name(person.get_primary_name()), + 'Person', person.handle) + self.append_text("\n") + if what == "m": + if len(family_list) > 0: + family = self.dbstate.db.get_family_from_handle(family_list[0]) + mother = family.get_mother_handle() + if mother: + self.process_person(mother, generation + 1, "f") + self.process_person(mother, generation + 1, "s") + self._boxes[generation] = 0 + self.process_person(mother, generation + 1, "m") + + def main(self): # return false finishes + """ + Generator which will be run in the background. + """ + self._boxes = [0] * self.max_generations + self.set_text("") + active_person = self.dbstate.get_active_person() + if not active_person: + return False + self.process_person(active_person.handle, 1, "f") + self.process_person(active_person.handle, 1, "s") + self.process_person(active_person.handle, 1, "m") + self.append_text("", scroll_to="begin") + class StatsGramplet(Gramplet): def init(self): self.set_text(_("No Family Tree loaded.")) @@ -903,3 +975,11 @@ register(type="gramplet", detached_width = 250, detached_height = 300, ) + +register(type="gramplet", + name="Pedigree Gramplet", + tname=_("Pedigree Gramplet"), + height=300, + content = PedigreeGramplet, + title=_("Pedigree"), + )