From 7ae2cd07a5e6ff099bc0ca386f6bfd2c9449df1a Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Sat, 2 Aug 2003 02:22:34 +0000 Subject: [PATCH] * src/plugins/WriteFtree.py: add filter and data restriction support * src/plugins/writeftree.glade: interface description for Web Family Tree export filter svn: r1949 --- gramps2/src/plugins/WriteFtree.py | 91 +++++++-- gramps2/src/plugins/writeftree.glade | 267 +++++++++++++++++++++++++++ 2 files changed, 341 insertions(+), 17 deletions(-) create mode 100644 gramps2/src/plugins/writeftree.glade diff --git a/gramps2/src/plugins/WriteFtree.py b/gramps2/src/plugins/WriteFtree.py index de918be06..42801253a 100644 --- a/gramps2/src/plugins/WriteFtree.py +++ b/gramps2/src/plugins/WriteFtree.py @@ -45,11 +45,15 @@ import gtk.glade import WriteXML import TarFile import Utils +import GenericFilter +import Errors + from QuestionDialog import MissingMediaDialog from intl import gettext as _ _title_string = _("Export to Web Family Tree") + #------------------------------------------------------------------------- # # writeData @@ -57,7 +61,7 @@ _title_string = _("Export to Web Family Tree") #------------------------------------------------------------------------- def writeData(database,person): try: - FtreeWriter(database) + FtreeWriter(database,person) except: import DisplayTrace DisplayTrace.DisplayTrace() @@ -69,42 +73,90 @@ def writeData(database,person): #------------------------------------------------------------------------- class FtreeWriter: - def __init__(self,database): + def __init__(self,database,person): self.db = database base = os.path.dirname(__file__) - glade_file = "%s/%s" % (base,"pkgexport.glade") + glade_file = "%s/%s" % (base,"writeftree.glade") dic = { - "destroy_passed_object" : Utils.destroy_passed_object, - "on_ok_clicked" : self.on_ok_clicked + "destroy_passed_object" : self.close, + "on_ok_clicked" : self.on_ok_clicked, } - - self.top = gtk.glade.XML(glade_file,"packageExport") - Utils.set_titles(self.top.get_widget('packageExport'), + self.plist = {} + self.top = gtk.glade.XML(glade_file,"top") + + Utils.set_titles(self.top.get_widget('top'), self.top.get_widget('title'), _title_string) self.top.signal_autoconnect(dic) - self.top.get_widget("packageExport").show() + + self.topwin = self.top.get_widget("top") + self.restrict = self.top.get_widget("restrict") + self.filter = self.top.get_widget("filter") + + all = GenericFilter.GenericFilter() + all.set_name(_("Entire Database")) + all.add_rule(GenericFilter.Everyone([])) + + des = GenericFilter.GenericFilter() + des.set_name(_("Descendants of %s") % person.getPrimaryName().getName()) + des.add_rule(GenericFilter.IsDescendantOf([person.getId()])) + + ans = GenericFilter.GenericFilter() + ans.set_name(_("Ancestors of %s") % person.getPrimaryName().getName()) + ans.add_rule(GenericFilter.IsAncestorOf([person.getId()])) + + com = GenericFilter.GenericFilter() + com.set_name(_("People with common ancestor with %s") % + person.getPrimaryName().getName()) + com.add_rule(GenericFilter.HasCommonAncestorWith([person.getId()])) + + self.filter_menu = GenericFilter.build_filter_menu([all,des,ans,com]) + self.filter.set_menu(self.filter_menu) + + self.topwin.show() + + def close(self,obj): + self.topwin.destroy() def on_ok_clicked(self,obj): name = self.top.get_widget("filename").get_text() - Utils.destroy_passed_object(obj) + restrict = self.top.get_widget('restrict').get_active() + pfilter = self.filter_menu.get_active().get_data("filter") + + Utils.destroy_passed_object(self.topwin) try: - self.export(name) + self.export(name, pfilter, restrict) except: import DisplayTrace DisplayTrace.DisplayTrace() - def export(self, filename): + def export(self, filename, cfilter, restrict ): + + if cfilter == None: + for p in self.db.getPersonKeys(): + self.plist[p] = 1 + else: + try: + for p in cfilter.apply(self.db, self.db.getPersonMap().values()): + self.plist[p.getId()] = 1 + except Errors.FilterError, msg: + (m1,m2) = msg.messages() + ErrorDialog(m1,m2) + return + + self.flist = {} + for key in self.plist.keys(): + p = self.db.getPerson(key) name_map = {} id_map = {} id_name = {} - for key in self.db.getPersonKeys(): + for key in self.plist: pn = self.db.getPerson(key).getPrimaryName() fn = "" sn = pn.getSurname() @@ -130,7 +182,7 @@ class FtreeWriter: f = open(filename,"w") - for key in self.db.getPersonKeys(): + for key in self.plist: p = self.db.getPerson(key) name = id_name[key] father = "" @@ -151,13 +203,18 @@ class FtreeWriter: birth = p.getBirth().getDateObj() death = p.getDeath().getDateObj() - if birth.isValid(): - if death.isValid(): + if restrict: + alive = p.probablyAlive() + else: + alive = 0 + + if birth.isValid() and not alive: + if death.isValid() and not alive : dates = "%s-%s" % (fdate(birth),fdate(death)) else: dates = fdate(birth) else: - if death.isValid(): + if death.isValid() and not alive: dates = fdate(death) else: dates = "" diff --git a/gramps2/src/plugins/writeftree.glade b/gramps2/src/plugins/writeftree.glade new file mode 100644 index 000000000..e5a3b1749 --- /dev/null +++ b/gramps2/src/plugins/writeftree.glade @@ -0,0 +1,267 @@ + + + + + + + + True + + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + True + 480 + True + False + False + + + + True + False + 8 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + 0 + + + + + + + True + True + True + gtk-cancel + True + GTK_RELIEF_NORMAL + 0 + + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + False + 0 + + + + True + + False + False + GTK_JUSTIFY_CENTER + False + False + 0.5 + 0.5 + 0 + 6 + + + 0 + False + False + + + + + + 12 + True + 5 + 3 + False + 6 + 12 + + + + True + ftree_export + 10 + Export GEDCOM + False + True + + + + True + True + True + True + 0 + + True + * + False + + + + + 1 + 3 + 1 + 2 + + + + + + + True + <b>Filename</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 3 + 0 + 1 + fill + + + + + + + True + <b>Options</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 0 + 3 + 2 + 3 + fill + + + + + + + True + True + _Restrict data on living people + True + GTK_RELIEF_NORMAL + True + False + True + + + 1 + 3 + 4 + 5 + fill + + + + + + + True + _Filter: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + filter + + + + + + 1 + 2 + 3 + 4 + fill + + + + + + + True + True + -1 + + + + True + + + + + 2 + 3 + 3 + 4 + + + + + + 0 + True + True + + + + + 0 + True + True + + + + + + +