* src/plugins/WriteFtree.py: add filter and data restriction support

* src/plugins/writeftree.glade: interface description for Web Family
Tree export filter


svn: r1949
This commit is contained in:
Don Allingham 2003-08-02 02:22:34 +00:00
parent 9b3253a9bf
commit 7ae2cd07a5
2 changed files with 341 additions and 17 deletions

View File

@ -45,11 +45,15 @@ import gtk.glade
import WriteXML import WriteXML
import TarFile import TarFile
import Utils import Utils
import GenericFilter
import Errors
from QuestionDialog import MissingMediaDialog from QuestionDialog import MissingMediaDialog
from intl import gettext as _ from intl import gettext as _
_title_string = _("Export to Web Family Tree") _title_string = _("Export to Web Family Tree")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# writeData # writeData
@ -57,7 +61,7 @@ _title_string = _("Export to Web Family Tree")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def writeData(database,person): def writeData(database,person):
try: try:
FtreeWriter(database) FtreeWriter(database,person)
except: except:
import DisplayTrace import DisplayTrace
DisplayTrace.DisplayTrace() DisplayTrace.DisplayTrace()
@ -69,42 +73,90 @@ def writeData(database,person):
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class FtreeWriter: class FtreeWriter:
def __init__(self,database): def __init__(self,database,person):
self.db = database self.db = database
base = os.path.dirname(__file__) base = os.path.dirname(__file__)
glade_file = "%s/%s" % (base,"pkgexport.glade") glade_file = "%s/%s" % (base,"writeftree.glade")
dic = { dic = {
"destroy_passed_object" : Utils.destroy_passed_object, "destroy_passed_object" : self.close,
"on_ok_clicked" : self.on_ok_clicked "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'), self.top.get_widget('title'),
_title_string) _title_string)
self.top.signal_autoconnect(dic) 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): def on_ok_clicked(self,obj):
name = self.top.get_widget("filename").get_text() 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: try:
self.export(name) self.export(name, pfilter, restrict)
except: except:
import DisplayTrace import DisplayTrace
DisplayTrace.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 = {} name_map = {}
id_map = {} id_map = {}
id_name = {} id_name = {}
for key in self.db.getPersonKeys(): for key in self.plist:
pn = self.db.getPerson(key).getPrimaryName() pn = self.db.getPerson(key).getPrimaryName()
fn = "" fn = ""
sn = pn.getSurname() sn = pn.getSurname()
@ -130,7 +182,7 @@ class FtreeWriter:
f = open(filename,"w") f = open(filename,"w")
for key in self.db.getPersonKeys(): for key in self.plist:
p = self.db.getPerson(key) p = self.db.getPerson(key)
name = id_name[key] name = id_name[key]
father = "" father = ""
@ -151,13 +203,18 @@ class FtreeWriter:
birth = p.getBirth().getDateObj() birth = p.getBirth().getDateObj()
death = p.getDeath().getDateObj() death = p.getDeath().getDateObj()
if birth.isValid(): if restrict:
if death.isValid(): 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)) dates = "%s-%s" % (fdate(birth),fdate(death))
else: else:
dates = fdate(birth) dates = fdate(birth)
else: else:
if death.isValid(): if death.isValid() and not alive:
dates = fdate(death) dates = fdate(death)
else: else:
dates = "" dates = ""

View File

@ -0,0 +1,267 @@
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<requires lib="gnome"/>
<widget class="GtkDialog" id="top">
<property name="visible">True</property>
<property name="title" translatable="yes"></property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">True</property>
<property name="default_width">480</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">8</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="ok">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_ok_clicked" object="gedcomExport"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="cancel">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="response_id">0</property>
<signal name="clicked" handler="destroy_passed_object" object="gedcomExport"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="title">
<property name="visible">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">6</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkTable" id="table3">
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="n_rows">5</property>
<property name="n_columns">3</property>
<property name="homogeneous">False</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<child>
<widget class="GnomeFileEntry" id="fileentry1">
<property name="visible">True</property>
<property name="history_id">ftree_export</property>
<property name="max_saved">10</property>
<property name="browse_dialog_title" translatable="yes">Export GEDCOM</property>
<property name="directory_entry">False</property>
<property name="modal">True</property>
<child internal-child="entry">
<widget class="GtkEntry" id="filename">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char" translatable="yes">*</property>
<property name="activates_default">False</property>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Filename&lt;/b&gt;</property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">3</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Options&lt;/b&gt;</property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">3</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="restrict">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Restrict data on living people</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="active">True</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">_Filter:</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="mnemonic_widget">filter</property>
<accessibility>
<atkrelation target="filter" type="label-for"/>
</accessibility>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkOptionMenu" id="filter">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="history">-1</property>
<child internal-child="menu">
<widget class="GtkMenu" id="convertwidget1">
<property name="visible">True</property>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>