3878: Private option and filter on Exporter; adds proxy order, browse of proxy data, referenced proxy, update of all exports (except csv)
svn: r15502
This commit is contained in:
parent
ba2d5d503d
commit
a9ac340110
@ -280,7 +280,7 @@ class ExportAssistant(gtk.Assistant, ManagedWindow.ManagedWindow) :
|
||||
vbox.foreach(vbox.remove)
|
||||
# add new content
|
||||
if config_box_class:
|
||||
self.option_box_instance = config_box_class(self.person)
|
||||
self.option_box_instance = config_box_class(self.person, self.dbstate, self.uistate)
|
||||
box = self.option_box_instance.get_option_box()
|
||||
vbox.add(box)
|
||||
else:
|
||||
|
@ -28,6 +28,7 @@
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gtk
|
||||
import pango
|
||||
from gen.ggettext import gettext as _
|
||||
import gobject
|
||||
|
||||
@ -37,9 +38,56 @@ import gobject
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import config
|
||||
|
||||
from gen.display.name import displayer as name_displayer
|
||||
from Filters import GenericFilter, Rules
|
||||
from gui.utils import ProgressMeter
|
||||
|
||||
def get_proxy_value(proxy_name):
|
||||
return [value for (name, value) in
|
||||
config.get('export.proxy-order') if name == proxy_name][0]
|
||||
|
||||
def set_proxy_value(proxy_name, proxy_value):
|
||||
[name_value for name_value in
|
||||
config.get('export.proxy-order') if name_value[0] == proxy_name][0][1] = int(proxy_value)
|
||||
|
||||
def get_proxy_names():
|
||||
return [name for (name, value) in config.get('export.proxy-order')]
|
||||
|
||||
def swap_proxy_order(row1, row2):
|
||||
po = config.get('export.proxy-order')
|
||||
po[row1], po[row2] = po[row2], po[row1]
|
||||
|
||||
class Progress(object):
|
||||
"""
|
||||
Mirros the same interface that the ExportAssistant uses in the
|
||||
selection, but this is for the preview selection.
|
||||
"""
|
||||
def __init__(self):
|
||||
self.pm = ProgressMeter(_("Selecting Preview Data"), _('Selecting...'))
|
||||
self.progress_cnt = 0
|
||||
self.title = _("Selecting...")
|
||||
while gtk.events_pending():
|
||||
gtk.main_iteration()
|
||||
|
||||
def reset(self, title):
|
||||
self.pm.set_header(title)
|
||||
self.title = title
|
||||
while gtk.events_pending():
|
||||
gtk.main_iteration()
|
||||
|
||||
def set_total(self, count):
|
||||
self.pm.set_pass(self.title, total=count+1)
|
||||
while gtk.events_pending():
|
||||
gtk.main_iteration()
|
||||
|
||||
def update(self, count):
|
||||
self.pm.step()
|
||||
while gtk.events_pending():
|
||||
gtk.main_iteration()
|
||||
|
||||
def close(self):
|
||||
self.pm.step()
|
||||
self.pm.close()
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -52,60 +100,84 @@ class WriterOptionBox(object):
|
||||
the options.
|
||||
|
||||
"""
|
||||
def __init__(self, person):
|
||||
def __init__(self, person, dbstate, uistate):
|
||||
self.person = person
|
||||
self.dbstate = dbstate
|
||||
self.uistate = uistate
|
||||
self.preview_dbase = None
|
||||
self.preview_button = None
|
||||
self.preview_proxy_button = {}
|
||||
self.proxy_options_showing = False
|
||||
self.proxy_dbase = {}
|
||||
self.private = 0
|
||||
self.restrict = 0
|
||||
self.unlinked = 0
|
||||
self.restrict_num = 0
|
||||
self.reference_num = 0
|
||||
self.cfilter = None
|
||||
self.nfilter = None
|
||||
self.restrict_check = None
|
||||
self.restrict_option = None
|
||||
self.private_check = None
|
||||
self.unlinked_check = None
|
||||
self.filter_obj = None
|
||||
self.filter_note = None
|
||||
self.reference_filter = None
|
||||
self.initialized_show_options = False
|
||||
# The following are special properties. Create them to force the
|
||||
# export wizard to not ask for a file, and to override the
|
||||
# confirmation message:
|
||||
#self.no_fileselect = True
|
||||
#self.confirm_text = "You made it, kid!"
|
||||
|
||||
def mark_dirty(self, widget):
|
||||
self.preview_dbase = None
|
||||
if self.preview_button:
|
||||
self.preview_button.set_sensitive(1)
|
||||
for proxy_name in self.preview_proxy_button:
|
||||
if proxy_name != "unfiltered":
|
||||
self.preview_proxy_button[proxy_name].set_sensitive(0)
|
||||
self.parse_options()
|
||||
|
||||
def get_option_box(self):
|
||||
"""Build up a gtk.Table that contains the standard options."""
|
||||
table = gtk.Table(5, 2)
|
||||
widget = gtk.VBox()
|
||||
|
||||
self.filter_obj = gtk.ComboBox()
|
||||
label = gtk.Label(_('_Person Filter'))
|
||||
label.set_use_underline(True)
|
||||
label.set_mnemonic_widget(self.filter_obj)
|
||||
|
||||
# Objects for choosing a Note filter
|
||||
self.filter_note = gtk.ComboBox()
|
||||
label_note = gtk.Label(_('_Note Filter'))
|
||||
label_note.set_use_underline(True)
|
||||
label_note.set_mnemonic_widget(self.filter_note)
|
||||
full_database_row = gtk.HBox()
|
||||
full_database_row.pack_start(gtk.Label("Unfiltered Family Tree:"), False)
|
||||
button = gtk.Button("%d People" % len(self.dbstate.db.get_person_handles()))
|
||||
button.set_tooltip_text(_("Click to see preview of unfiltered data"))
|
||||
button.set_size_request(100, -1)
|
||||
button.connect("clicked", self.show_preview_data)
|
||||
button.proxy_name = "unfiltered"
|
||||
self.preview_proxy_button["unfiltered"] = button
|
||||
self.spacer = gtk.HBox()
|
||||
full_database_row.pack_end(self.spacer, False)
|
||||
full_database_row.pack_end(button, False)
|
||||
|
||||
widget.pack_start(full_database_row, False)
|
||||
|
||||
self.private_check = gtk.CheckButton(
|
||||
_('_Do not include records marked private'))
|
||||
self.restrict_check = gtk.CheckButton(
|
||||
_('_Restrict data on living people'))
|
||||
self.unlinked_check = gtk.CheckButton(
|
||||
_('_Do not include unlinked records'))
|
||||
self.private_check.connect("clicked", self.mark_dirty)
|
||||
self.private_check.set_active(get_proxy_value("privacy"))
|
||||
|
||||
self.private_check.set_active(config.get('export.no-private'))
|
||||
self.restrict_check.set_active(config.get('export.restrict-living'))
|
||||
self.unlinked_check.set_active(config.get('export.no-unlinked'))
|
||||
|
||||
table.set_border_width(12)
|
||||
table.set_row_spacings(6)
|
||||
table.set_col_spacings(6)
|
||||
table.attach(label, 0, 1, 0, 1, xoptions=0, yoptions=0)
|
||||
table.attach(self.filter_obj, 1, 2, 0, 1, yoptions=0)
|
||||
table.attach(label_note, 0, 1, 1, 2, xoptions =0, yoptions=0)
|
||||
table.attach(self.filter_note, 1, 2, 1, 2, yoptions=0)
|
||||
table.attach(self.private_check, 1, 2, 2, 3, yoptions=0)
|
||||
table.attach(self.restrict_check, 1, 2, 3, 4, yoptions=0)
|
||||
table.attach(self.unlinked_check, 1, 2, 4, 5, yoptions=0)
|
||||
self.proxy_widget = {}
|
||||
self.vbox_n = []
|
||||
self.up_n = []
|
||||
self.down_n = []
|
||||
row = 0
|
||||
for proxy_name in get_proxy_names():
|
||||
frame = self.build_frame(proxy_name, row)
|
||||
widget.pack_start(frame, False)
|
||||
row += 1
|
||||
|
||||
hbox = gtk.HBox()
|
||||
self.advanced_button = gtk.Button(_("Change order"))
|
||||
self.advanced_button.set_size_request(150, -1)
|
||||
self.proxy_options_showing = False
|
||||
self.advanced_button.connect("clicked", self.show_options)
|
||||
hbox.pack_end(self.advanced_button, False)
|
||||
self.preview_button = gtk.Button(_("Calculate Previews"))
|
||||
self.preview_button.connect("clicked", self.preview)
|
||||
hbox.pack_end(self.preview_button, False)
|
||||
widget.pack_end(hbox, False)
|
||||
|
||||
# Populate the Person Filter
|
||||
entire_db = GenericFilter()
|
||||
@ -123,11 +195,42 @@ class WriterOptionBox(object):
|
||||
model.append(row=[item.get_name(), item])
|
||||
|
||||
cell = gtk.CellRendererText()
|
||||
cell.set_property('ellipsize', pango.ELLIPSIZE_END)
|
||||
self.filter_obj.pack_start(cell, True)
|
||||
self.filter_obj.add_attribute(cell, 'text', 0)
|
||||
self.filter_obj.set_model(model)
|
||||
self.filter_obj.set_active(0)
|
||||
|
||||
self.filter_obj.set_active(get_proxy_value("person"))
|
||||
|
||||
model = gtk.ListStore(gobject.TYPE_STRING, int)
|
||||
row = 0
|
||||
for item in [
|
||||
_('Include living people'),
|
||||
_('Restrict given names on living people'),
|
||||
_('Remove living people')]:
|
||||
model.append(row=[item, row])
|
||||
row += 1
|
||||
cell = gtk.CellRendererText()
|
||||
cell.set_property('ellipsize', pango.ELLIPSIZE_END)
|
||||
self.restrict_option.pack_start(cell, True)
|
||||
self.restrict_option.add_attribute(cell, 'text', 0)
|
||||
self.restrict_option.set_model(model)
|
||||
self.restrict_option.set_active(get_proxy_value("living"))
|
||||
|
||||
model = gtk.ListStore(gobject.TYPE_STRING, int)
|
||||
row = 0
|
||||
for item in [
|
||||
_('Include all objects'),
|
||||
_('Include only items connected to selected people'),
|
||||
_('Include items that are not orphans')]:
|
||||
model.append(row=[item, row])
|
||||
row += 1
|
||||
cell = gtk.CellRendererText()
|
||||
cell.set_property('ellipsize', pango.ELLIPSIZE_END)
|
||||
self.reference_filter.pack_start(cell, True)
|
||||
self.reference_filter.add_attribute(cell, 'text', 0)
|
||||
self.reference_filter.set_model(model)
|
||||
self.reference_filter.set_active(get_proxy_value("reference"))
|
||||
|
||||
# Populate the Notes Filter
|
||||
notes_filters = [entire_db]
|
||||
|
||||
@ -136,13 +239,204 @@ class WriterOptionBox(object):
|
||||
for item in notes_filters:
|
||||
notes_model.append(row=[item.get_name(), item])
|
||||
notes_cell = gtk.CellRendererText()
|
||||
notes_cell.set_property('ellipsize', pango.ELLIPSIZE_END)
|
||||
self.filter_note.pack_start(notes_cell, True)
|
||||
self.filter_note.add_attribute(notes_cell, 'text', 0)
|
||||
self.filter_note.set_model(notes_model)
|
||||
self.filter_note.set_active(0)
|
||||
self.filter_note.set_active(get_proxy_value("note"))
|
||||
|
||||
table.show()
|
||||
return table
|
||||
self.filter_note.connect("changed", self.mark_dirty)
|
||||
self.filter_obj.connect("changed", self.mark_dirty)
|
||||
self.restrict_option.connect("changed", self.mark_dirty)
|
||||
self.reference_filter.connect("changed", self.mark_dirty)
|
||||
return widget
|
||||
|
||||
def show_preview_data(self, widget):
|
||||
from DbState import DbState
|
||||
from QuickReports import run_quick_report_by_name
|
||||
if widget.proxy_name == "unfiltered":
|
||||
dbstate = self.dbstate
|
||||
else:
|
||||
dbstate = DbState()
|
||||
dbstate.db = self.proxy_dbase[widget.proxy_name]
|
||||
dbstate.open = True
|
||||
run_quick_report_by_name(dbstate,
|
||||
self.uistate,
|
||||
'filterbyname',
|
||||
'all')
|
||||
|
||||
def preview(self, widget):
|
||||
"""
|
||||
Calculate previews to see the selected data.
|
||||
"""
|
||||
self.parse_options()
|
||||
pm = Progress()
|
||||
self.preview_dbase = self.get_filtered_database(self.dbstate.db, pm, preview=True)
|
||||
pm.close()
|
||||
self.preview_button.set_sensitive(0)
|
||||
|
||||
def build_frame(self, proxy_name, row):
|
||||
"""
|
||||
Build a frame for a proxy option. proxy_name is a string.
|
||||
"""
|
||||
# Make a box and put the option in it:
|
||||
button = gtk.Button("%d People" % 0)
|
||||
button.set_size_request(100, -1)
|
||||
button.connect("clicked", self.show_preview_data)
|
||||
button.proxy_name = proxy_name
|
||||
if proxy_name == "person":
|
||||
# Frame Person:
|
||||
self.filter_obj = gtk.ComboBox()
|
||||
label = gtk.Label(_('_Person Filter') + ": ")
|
||||
label.set_alignment(0, 0.5)
|
||||
label.set_size_request(150, -1)
|
||||
label.set_use_underline(True)
|
||||
label.set_mnemonic_widget(self.filter_obj)
|
||||
box = gtk.HBox()
|
||||
box.pack_start(label, False)
|
||||
box.pack_start(self.filter_obj)
|
||||
button.set_tooltip_text(_("Click to see preview after person filter"))
|
||||
elif proxy_name == "note":
|
||||
# Frame Note:
|
||||
# Objects for choosing a Note filter:
|
||||
self.filter_note = gtk.ComboBox()
|
||||
label_note = gtk.Label(_('_Note Filter') + ": ")
|
||||
label_note.set_alignment(0, 0.5)
|
||||
label_note.set_size_request(150, -1)
|
||||
label_note.set_use_underline(True)
|
||||
label_note.set_mnemonic_widget(self.filter_note)
|
||||
box = gtk.HBox()
|
||||
box.pack_start(label_note, False)
|
||||
box.pack_start(self.filter_note)
|
||||
button.set_tooltip_text(_("Click to see preview after note filter"))
|
||||
elif proxy_name == "privacy":
|
||||
# Frame 3:
|
||||
label = gtk.Label(_("Privacy Filter") + ":")
|
||||
label.set_alignment(0, 0.5)
|
||||
label.set_size_request(150, -1)
|
||||
box = gtk.HBox()
|
||||
box.pack_start(label, False)
|
||||
box.add(self.private_check)
|
||||
button.set_tooltip_text(_("Click to see preview after privacy filter"))
|
||||
elif proxy_name == "living":
|
||||
# Frame 4:
|
||||
label = gtk.Label(_("Living Filter") + ":")
|
||||
label.set_alignment(0, 0.5)
|
||||
label.set_size_request(150, -1)
|
||||
box = gtk.HBox()
|
||||
box.pack_start(label, False)
|
||||
self.restrict_option = gtk.ComboBox()
|
||||
box.add(self.restrict_option)
|
||||
button.set_tooltip_text(_("Click to see preview after living filter"))
|
||||
elif proxy_name == "reference":
|
||||
# Frame 5:
|
||||
self.reference_filter = gtk.ComboBox()
|
||||
label = gtk.Label(_('Reference Filter') + ": ")
|
||||
label.set_alignment(0, 0.5)
|
||||
label.set_size_request(150, -1)
|
||||
box = gtk.HBox()
|
||||
box.pack_start(label, False)
|
||||
box.pack_start(self.reference_filter)
|
||||
button.set_tooltip_text(_("Click to see preview after reference filter"))
|
||||
else:
|
||||
raise AttributeError("Unknown proxy '%s'" % proxy_name)
|
||||
|
||||
frame = gtk.Frame()
|
||||
hbox = gtk.HBox()
|
||||
frame.add(hbox)
|
||||
vbox = gtk.HBox()
|
||||
self.vbox_n.append(vbox)
|
||||
up = gtk.Button()
|
||||
up.connect("clicked", self.swap)
|
||||
if row == 0:
|
||||
up.set_sensitive(0) # can't go up
|
||||
image = gtk.Image()
|
||||
image.set_from_stock(gtk.STOCK_GO_UP,
|
||||
gtk.ICON_SIZE_MENU)
|
||||
up.set_image(image)
|
||||
up.row = row - 1
|
||||
self.up_n.append(up)
|
||||
down = gtk.Button()
|
||||
down.connect("clicked", self.swap)
|
||||
image = gtk.Image()
|
||||
image.set_from_stock(gtk.STOCK_GO_DOWN,
|
||||
gtk.ICON_SIZE_MENU)
|
||||
down.set_image(image)
|
||||
down.row = row
|
||||
if row == 4:
|
||||
down.set_sensitive(0) # can't go down
|
||||
self.down_n.append(down)
|
||||
self.preview_proxy_button[proxy_name] = button
|
||||
self.preview_proxy_button[proxy_name].set_sensitive(0)
|
||||
box.pack_end(button, False)
|
||||
hbox.pack_start(box)
|
||||
hbox.pack_end(vbox, False)
|
||||
self.proxy_widget[proxy_name] = box
|
||||
return frame
|
||||
|
||||
def show_options(self, widget=None):
|
||||
"""
|
||||
Show or hide the option arrows. Needs to add them if first
|
||||
time due to the fact that Gramps tends to use show_all rather
|
||||
than show.
|
||||
"""
|
||||
if self.proxy_options_showing:
|
||||
self.advanced_button.set_label(_("Change order"))
|
||||
self.spacer_up.hide()
|
||||
self.spacer_down.hide()
|
||||
for n in range(5):
|
||||
self.up_n[n].hide()
|
||||
self.down_n[n].hide()
|
||||
else:
|
||||
self.advanced_button.set_label(_("Hide order"))
|
||||
if not self.initialized_show_options:
|
||||
self.initialized_show_options = True
|
||||
# This is necessary because someone used show_all up top
|
||||
# Now, we can't add something that we want hidden
|
||||
for n in range(5):
|
||||
self.vbox_n[n].pack_start(self.up_n[n])
|
||||
self.vbox_n[n].pack_end(self.down_n[n])
|
||||
# some spacer buttons:
|
||||
up = gtk.Button()
|
||||
up.set_sensitive(0)
|
||||
image = gtk.Image()
|
||||
image.set_from_stock(gtk.STOCK_GO_UP,
|
||||
gtk.ICON_SIZE_MENU)
|
||||
up.set_image(image)
|
||||
self.spacer.pack_start(up, False)
|
||||
down = gtk.Button()
|
||||
down.set_sensitive(0)
|
||||
image = gtk.Image()
|
||||
image.set_from_stock(gtk.STOCK_GO_DOWN,
|
||||
gtk.ICON_SIZE_MENU)
|
||||
down.set_image(image)
|
||||
self.spacer.pack_end(down, False)
|
||||
self.spacer_up = up
|
||||
self.spacer_down = down
|
||||
self.spacer_up.show()
|
||||
self.spacer_down.show()
|
||||
for n in range(5):
|
||||
self.up_n[n].show()
|
||||
self.down_n[n].show()
|
||||
|
||||
self.proxy_options_showing = not self.proxy_options_showing
|
||||
|
||||
def swap(self, widget):
|
||||
"""
|
||||
Swap the order of two proxies.
|
||||
"""
|
||||
row1 = widget.row
|
||||
row2 = widget.row + 1
|
||||
proxy1 = config.get('export.proxy-order')[row1][0]
|
||||
proxy2 = config.get('export.proxy-order')[row2][0]
|
||||
widget1 = self.proxy_widget[proxy1]
|
||||
widget2 = self.proxy_widget[proxy2]
|
||||
parent1 = widget1.get_parent()
|
||||
parent2 = widget2.get_parent()
|
||||
widget1.reparent(parent2)
|
||||
widget2.reparent(parent1)
|
||||
swap_proxy_order(row1, row2)
|
||||
self.mark_dirty(widget)
|
||||
|
||||
def __define_person_filters(self):
|
||||
"""Add person filters if the active person is defined."""
|
||||
@ -178,24 +472,145 @@ class WriterOptionBox(object):
|
||||
restrict = restrict information on living peoplel
|
||||
cfitler = return the GenericFilter selected
|
||||
nfilter = return the NoteFilter selected
|
||||
unlinked = restrict unlinked records
|
||||
reference = restrict referenced/orphaned records
|
||||
|
||||
"""
|
||||
self.restrict = self.restrict_check.get_active()
|
||||
self.private = self.private_check.get_active()
|
||||
self.unlinked = self.unlinked_check.get_active()
|
||||
if self.private_check:
|
||||
self.private = self.private_check.get_active()
|
||||
set_proxy_value("privacy", self.private)
|
||||
|
||||
config.set('export.no-private', self.private)
|
||||
config.set('export.restrict-living', self.restrict)
|
||||
config.set('export.no-unlinked', self.unlinked)
|
||||
config.save()
|
||||
if self.filter_obj:
|
||||
model = self.filter_obj.get_model()
|
||||
node = self.filter_obj.get_active_iter()
|
||||
self.cfilter = model[node][1]
|
||||
set_proxy_value("person", self.filter_obj.get_active())
|
||||
|
||||
model = self.filter_obj.get_model()
|
||||
node = self.filter_obj.get_active_iter()
|
||||
self.cfilter = model[node][1]
|
||||
if self.restrict_option:
|
||||
model = self.restrict_option.get_model()
|
||||
node = self.restrict_option.get_active_iter()
|
||||
self.restrict_num = model[node][1]
|
||||
set_proxy_value("living", self.restrict_option.get_active())
|
||||
|
||||
model = self.filter_note.get_model()
|
||||
node = self.filter_note.get_active_iter()
|
||||
self.nfilter = model[node][1]
|
||||
if self.filter_note:
|
||||
model = self.filter_note.get_model()
|
||||
node = self.filter_note.get_active_iter()
|
||||
self.nfilter = model[node][1]
|
||||
set_proxy_value("note", self.filter_note.get_active())
|
||||
|
||||
if self.reference_filter:
|
||||
model = self.reference_filter.get_model()
|
||||
node = self.reference_filter.get_active_iter()
|
||||
self.reference_num = model[node][1]
|
||||
set_proxy_value("reference", self.reference_filter.get_active())
|
||||
|
||||
def get_filtered_database(self, dbase, progress=None, preview=False):
|
||||
"""
|
||||
dbase - the database
|
||||
progress - instance that has:
|
||||
.reset() method
|
||||
.set_total() method
|
||||
.update() method
|
||||
.progress_cnt integer representing N of total done
|
||||
"""
|
||||
# Increment the progress count for each filter type chosen
|
||||
if self.private and progress:
|
||||
progress.progress_cnt += 1
|
||||
|
||||
if self.restrict_num > 0 and progress:
|
||||
progress.progress_cnt += 1
|
||||
|
||||
if not self.cfilter.is_empty() and progress:
|
||||
progress.progress_cnt += 1
|
||||
|
||||
if not self.nfilter.is_empty() and progress:
|
||||
progress.progress_cnt += 1
|
||||
|
||||
if self.reference_num > 0 and progress:
|
||||
progress.progress_cnt += 1
|
||||
|
||||
if progress:
|
||||
progress.set_total(progress.progress_cnt)
|
||||
progress.progress_cnt = 0
|
||||
|
||||
if self.preview_dbase:
|
||||
if progress:
|
||||
progress.progress_cnt += 5
|
||||
return self.preview_dbase
|
||||
|
||||
self.proxy_dbase.clear()
|
||||
for proxy_name in get_proxy_names():
|
||||
dbase = self.apply_proxy(proxy_name, dbase, progress)
|
||||
if preview:
|
||||
self.proxy_dbase[proxy_name] = dbase
|
||||
self.preview_proxy_button[proxy_name].set_sensitive(1)
|
||||
self.preview_proxy_button[proxy_name].set_label(_("%d People" % len(dbase.get_person_handles())))
|
||||
return dbase
|
||||
|
||||
def apply_proxy(self, proxy_name, dbase, progress=None):
|
||||
"""
|
||||
Apply the named proxy to the dbase, and return.
|
||||
proxy_name is one of
|
||||
["person", "note", "privacy", "living", "reference"]
|
||||
"""
|
||||
# If the private flag is set, apply the PrivateProxyDb
|
||||
import gen.proxy
|
||||
if proxy_name == "privacy":
|
||||
if self.private:
|
||||
if progress:
|
||||
progress.reset(_("Filtering private data"))
|
||||
progress.progress_cnt += 1
|
||||
progress.update(progress.progress_cnt)
|
||||
dbase = gen.proxy.PrivateProxyDb(dbase)
|
||||
|
||||
# If the restrict flag is set, apply the LivingProxyDb
|
||||
elif proxy_name == "living":
|
||||
if self.restrict_num > 0:
|
||||
if progress:
|
||||
progress.reset(_("Filtering living persons"))
|
||||
progress.progress_cnt += 1
|
||||
progress.update(progress.progress_cnt)
|
||||
mode = [None, # include living
|
||||
gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY,
|
||||
gen.proxy.LivingProxyDb.MODE_EXCLUDE_ALL,
|
||||
][self.restrict_num]
|
||||
dbase = gen.proxy.LivingProxyDb(
|
||||
dbase,
|
||||
mode) #
|
||||
|
||||
# If the filter returned by cfilter is not empty, apply the
|
||||
# FilterProxyDb (Person Filter)
|
||||
elif proxy_name == "person":
|
||||
if not self.cfilter.is_empty():
|
||||
if progress:
|
||||
progress.reset(_("Applying selected person filter"))
|
||||
progress.progress_cnt += 1
|
||||
progress.update(progress.progress_cnt)
|
||||
dbase = gen.proxy.FilterProxyDb(
|
||||
dbase, self.cfilter)
|
||||
|
||||
# Apply the Note Filter
|
||||
elif proxy_name == "note":
|
||||
if not self.nfilter.is_empty():
|
||||
if progress:
|
||||
progress.reset(_("Applying selected note filter"))
|
||||
progress.progress_cnt += 1
|
||||
progress.update(progress.progress_cnt)
|
||||
dbase = gen.proxy.FilterProxyDb(
|
||||
dbase, note_filter=self.nfilter)
|
||||
|
||||
# Apply the ReferencedBySelection
|
||||
elif proxy_name == "reference":
|
||||
if progress:
|
||||
progress.reset(_("Filtering referenced records"))
|
||||
progress.progress_cnt += 1
|
||||
progress.update(progress.progress_cnt)
|
||||
if self.reference_num == 0:
|
||||
pass
|
||||
elif self.reference_num == 1:
|
||||
dbase = gen.proxy.ReferencedBySelectionProxyDb(dbase)
|
||||
elif self.reference_num == 2:
|
||||
dbase = gen.proxy.ReferencedProxyDb(dbase)
|
||||
else:
|
||||
raise AttributeError("no such proxy '%s'" % proxy_name)
|
||||
|
||||
return dbase
|
||||
|
@ -144,9 +144,13 @@ register('behavior.surname-guessing', 0)
|
||||
register('behavior.use-tips', False)
|
||||
register('behavior.welcome', 100)
|
||||
|
||||
register('export.no-private', True)
|
||||
register('export.no-unlinked', True)
|
||||
register('export.restrict-living', True)
|
||||
register('export.proxy-order', [
|
||||
["privacy", 0],
|
||||
["living", 0],
|
||||
["person", 0],
|
||||
["note", 0],
|
||||
["reference", 0],
|
||||
])
|
||||
|
||||
register('geoview.latitude', "0.0")
|
||||
register('geoview.lock', False)
|
||||
|
@ -156,7 +156,7 @@ class CSVWriterOptionBox(object):
|
||||
the options.
|
||||
|
||||
"""
|
||||
def __init__(self,person):
|
||||
def __init__(self, person, dbstate, uistate):
|
||||
self.person = person
|
||||
self.include_individuals = 1
|
||||
self.include_marriages = 1
|
||||
|
@ -47,6 +47,7 @@ log = logging.getLogger(".WriteFtree")
|
||||
#-------------------------------------------------------------------------
|
||||
import Utils
|
||||
from Filters import GenericFilter, Rules, build_filter_model
|
||||
from ExportOptions import WriterOptionBox
|
||||
import Errors
|
||||
from glade import Glade
|
||||
|
||||
@ -56,66 +57,9 @@ from glade import Glade
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def writeData(database, filename, msg_callback, option_box=None, callback=None):
|
||||
writer = FtreeWriter(database, msg_callback, filename, option_box, callback)
|
||||
writer = FtreeWriter(database, filename, msg_callback, option_box, callback)
|
||||
return writer.export_data()
|
||||
|
||||
class FtreeWriterOptionBox(object):
|
||||
"""
|
||||
Create a VBox with the option widgets and define methods to retrieve
|
||||
the options.
|
||||
"""
|
||||
def __init__(self, person):
|
||||
self.person = person
|
||||
self.restrict = True
|
||||
|
||||
def get_option_box(self):
|
||||
self.top = Glade()
|
||||
|
||||
self.filters = self.top.get_object("filter")
|
||||
|
||||
all = GenericFilter()
|
||||
all.set_name(_("Entire Database"))
|
||||
all.add_rule(Rules.Person.Everyone([]))
|
||||
|
||||
the_filters = [all]
|
||||
|
||||
if self.person:
|
||||
des = GenericFilter()
|
||||
des.set_name(_("Descendants of %s") %
|
||||
self.person.get_primary_name().get_name())
|
||||
des.add_rule(Rules.Person.IsDescendantOf(
|
||||
[self.person.get_gramps_id(),1]))
|
||||
|
||||
ans = GenericFilter()
|
||||
ans.set_name(_("Ancestors of %s")
|
||||
% self.person.get_primary_name().get_name())
|
||||
ans.add_rule(Rules.Person.IsAncestorOf(
|
||||
[self.person.get_gramps_id(),1]))
|
||||
|
||||
com = GenericFilter()
|
||||
com.set_name(_("People with common ancestor with %s") %
|
||||
self.person.get_primary_name().get_name())
|
||||
com.add_rule(Rules.Person.HasCommonAncestorWith(
|
||||
[self.person.get_gramps_id()]))
|
||||
|
||||
the_filters += [des, ans, com]
|
||||
|
||||
from Filters import CustomFilters
|
||||
the_filters.extend(CustomFilters.get_filters('Person'))
|
||||
self.filter_menu = build_filter_model(the_filters)
|
||||
self.filters.set_model(self.filter_menu)
|
||||
self.filters.set_active(0)
|
||||
|
||||
the_box = self.top.get_object("vbox1")
|
||||
the_parent = self.top.get_object('dialog-vbox1')
|
||||
the_parent.remove(the_box)
|
||||
self.top.toplevel.destroy()
|
||||
return the_box
|
||||
|
||||
def parse_options(self):
|
||||
self.restrict = self.top.get_object("restrict").get_active()
|
||||
self.cfilter = self.filter_menu[self.filters.get_active()][1]
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# FtreeWriter
|
||||
@ -123,40 +67,23 @@ class FtreeWriterOptionBox(object):
|
||||
#-------------------------------------------------------------------------
|
||||
class FtreeWriter(object):
|
||||
|
||||
def __init__(self, database, msg_callback, filename="", option_box=None,
|
||||
def __init__(self, database, filename, msg_callback, option_box=None,
|
||||
callback = None):
|
||||
self.db = database
|
||||
self.option_box = option_box
|
||||
self.filename = filename
|
||||
self.callback = callback
|
||||
self.msg_callback = msg_callback
|
||||
self.option_box = option_box
|
||||
self.callback = callback
|
||||
if callable(self.callback): # callback is really callable
|
||||
self.update = self.update_real
|
||||
else:
|
||||
self.update = self.update_empty
|
||||
|
||||
self.plist = {}
|
||||
|
||||
if not option_box:
|
||||
self.cl_setup()
|
||||
else:
|
||||
if option_box:
|
||||
self.option_box.parse_options()
|
||||
self.db = option_box.get_filtered_database(self.db)
|
||||
|
||||
self.restrict = self.option_box.restrict
|
||||
if self.option_box.cfilter is None:
|
||||
self.plist.update((p,1)
|
||||
for p in self.db.iter_person_handles())
|
||||
|
||||
else:
|
||||
try:
|
||||
self.plist.update((p,1)
|
||||
for p in self.option_box.cfilter.apply(
|
||||
self.db, self.db.iter_person_handles()))
|
||||
|
||||
except Errors.FilterError, msg:
|
||||
(m1, m2) = msg.messages()
|
||||
self.msg_callback(m1, m2)
|
||||
return
|
||||
self.plist = [x for x in self.db.iter_person_handles()]
|
||||
|
||||
def update_empty(self):
|
||||
pass
|
||||
@ -168,11 +95,6 @@ class FtreeWriter(object):
|
||||
self.callback(newval)
|
||||
self.oldval = newval
|
||||
|
||||
def cl_setup(self):
|
||||
self.restrict = True
|
||||
self.plist.update((p,1)
|
||||
for p in self.db.iter_person_handles())
|
||||
|
||||
def export_data(self):
|
||||
name_map = {}
|
||||
id_map = {}
|
||||
@ -237,18 +159,18 @@ class FtreeWriter(object):
|
||||
else:
|
||||
death = None
|
||||
|
||||
if self.restrict:
|
||||
alive = Utils.probably_alive(p, self.db)
|
||||
else:
|
||||
alive = 0
|
||||
#if self.restrict:
|
||||
# alive = Utils.probably_alive(p, self.db)
|
||||
#else:
|
||||
# alive = 0
|
||||
|
||||
if birth and not alive:
|
||||
if death and not alive :
|
||||
if birth:
|
||||
if death:
|
||||
dates = "%s-%s" % (fdate(birth), fdate(death))
|
||||
else:
|
||||
dates = fdate(birth)
|
||||
else:
|
||||
if death and not alive:
|
||||
if death:
|
||||
dates = fdate(death)
|
||||
else:
|
||||
dates = ""
|
||||
|
@ -46,7 +46,6 @@ import Errors
|
||||
from ExportOptions import WriterOptionBox
|
||||
from gen.updatecallback import UpdateCallback
|
||||
from Utils import media_path_full, get_unicode_path
|
||||
import gen.proxy
|
||||
from PlaceUtils import conv_lat_lon
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
@ -234,66 +233,7 @@ class GedcomWriter(UpdateCallback):
|
||||
"""
|
||||
if option_box:
|
||||
option_box.parse_options()
|
||||
|
||||
# Increment the progress count for each filter type chosen
|
||||
if option_box.private:
|
||||
self.progress_cnt += 1
|
||||
|
||||
if option_box.restrict:
|
||||
self.progress_cnt += 1
|
||||
|
||||
if not option_box.cfilter.is_empty():
|
||||
self.progress_cnt += 1
|
||||
|
||||
if not option_box.nfilter.is_empty():
|
||||
self.progress_cnt += 1
|
||||
|
||||
if option_box.unlinked:
|
||||
self.progress_cnt += 1
|
||||
|
||||
self.set_total(self.progress_cnt)
|
||||
self.progress_cnt = 0
|
||||
|
||||
# If the private flag is set, apply the PrivateProxyDb
|
||||
if option_box.private:
|
||||
self.reset(_("Filtering private data"))
|
||||
self.progress_cnt += 1
|
||||
self.update(self.progress_cnt)
|
||||
self.dbase = gen.proxy.PrivateProxyDb(self.dbase)
|
||||
|
||||
# If the restrict flag is set, apply the LivingProxyDb
|
||||
if option_box.restrict:
|
||||
self.reset(_("Filtering living persons"))
|
||||
self.progress_cnt += 1
|
||||
self.update(self.progress_cnt)
|
||||
self.dbase = gen.proxy.LivingProxyDb(
|
||||
self.dbase,
|
||||
gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
|
||||
|
||||
# If the filter returned by cfilter is not empty, apply the
|
||||
# FilterProxyDb (Person Filter)
|
||||
if not option_box.cfilter.is_empty():
|
||||
self.reset(_("Applying selected person filter"))
|
||||
self.progress_cnt += 1
|
||||
self.update(self.progress_cnt)
|
||||
self.dbase = gen.proxy.FilterProxyDb(
|
||||
self.dbase, option_box.cfilter)
|
||||
|
||||
# Apply the Note Filter
|
||||
if not option_box.nfilter.is_empty():
|
||||
self.reset(_("Applying selected note filter"))
|
||||
self.progress_cnt += 1
|
||||
self.update(self.progress_cnt)
|
||||
self.dbase = gen.proxy.FilterProxyDb(
|
||||
self.dbase, note_filter=option_box.nfilter)
|
||||
|
||||
# Apply the ReferencedProxyDb to remove any objects not referenced
|
||||
# after any of the other proxies have been applied
|
||||
if option_box.unlinked:
|
||||
self.reset(_("Filtering unlinked records"))
|
||||
self.progress_cnt += 1
|
||||
self.update(self.progress_cnt)
|
||||
self.dbase = gen.proxy.ReferencedProxyDb(self.dbase)
|
||||
self.dbase = option_box.get_filtered_database(self.dbase, self)
|
||||
|
||||
def write_gedcom_file(self, filename):
|
||||
"""
|
||||
|
@ -48,153 +48,32 @@ log = logging.getLogger(".WriteGeneWeb")
|
||||
#-------------------------------------------------------------------------
|
||||
import gen.lib
|
||||
from Filters import GenericFilter, Rules, build_filter_model
|
||||
from ExportOptions import WriterOptionBox
|
||||
#import const
|
||||
import Utils
|
||||
from glade import Glade
|
||||
import config
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GeneWebWriterOptionBox class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class GeneWebWriterOptionBox(object):
|
||||
"""
|
||||
Create a VBox with the option widgets and define methods to retrieve
|
||||
the options.
|
||||
|
||||
"""
|
||||
def __init__(self, person):
|
||||
self.person = person
|
||||
|
||||
def get_option_box(self):
|
||||
self.restrict = 1
|
||||
|
||||
self.topDialog = Glade()
|
||||
self.topDialog.connect_signals({
|
||||
"on_restrict_toggled": self.on_restrict_toggled
|
||||
})
|
||||
|
||||
self.filters = self.topDialog.get_object("filter")
|
||||
self.copy = 0
|
||||
|
||||
all = GenericFilter()
|
||||
all.set_name(_("Entire Database"))
|
||||
all.add_rule(Rules.Person.Everyone([]))
|
||||
|
||||
the_filters = [all]
|
||||
|
||||
if self.person:
|
||||
des = GenericFilter()
|
||||
des.set_name(_("Descendants of %s") %
|
||||
self.person.get_primary_name().get_name())
|
||||
des.add_rule(Rules.Person.IsDescendantOf(
|
||||
[self.person.get_gramps_id(),1]))
|
||||
|
||||
ans = GenericFilter()
|
||||
ans.set_name(_("Ancestors of %s") %
|
||||
self.person.get_primary_name().get_name())
|
||||
ans.add_rule(Rules.Person.IsAncestorOf(
|
||||
[self.person.get_gramps_id(),1]))
|
||||
|
||||
com = GenericFilter()
|
||||
com.set_name(_("People with common ancestor with %s") %
|
||||
self.person.get_primary_name().get_name())
|
||||
com.add_rule(Rules.Person.HasCommonAncestorWith(
|
||||
[self.person.get_gramps_id()]))
|
||||
|
||||
the_filters += [des, ans, com]
|
||||
|
||||
from Filters import CustomFilters
|
||||
the_filters.extend(CustomFilters.get_filters('Person'))
|
||||
self.filter_menu = build_filter_model(the_filters)
|
||||
self.filters.set_model(self.filter_menu)
|
||||
self.filters.set_active(0)
|
||||
|
||||
the_box = self.topDialog.get_object('vbox1')
|
||||
the_parent = self.topDialog.get_object('dialog-vbox1')
|
||||
the_parent.remove(the_box)
|
||||
self.topDialog.toplevel.destroy()
|
||||
return the_box
|
||||
|
||||
def on_restrict_toggled(self, restrict):
|
||||
active = restrict.get_active ()
|
||||
for x in [self.topDialog.get_object("living"),
|
||||
self.topDialog.get_object("notes")]:
|
||||
x.set_sensitive(active)
|
||||
|
||||
def parse_options(self):
|
||||
self.restrict = self.topDialog.get_object("restrict").get_active()
|
||||
self.living = (self.restrict and
|
||||
self.topDialog.get_object("living").get_active())
|
||||
self.exclnotes = (self.restrict and
|
||||
self.topDialog.get_object("notes").get_active())
|
||||
self.cfilter = self.filter_menu[self.filters.get_active()][1]
|
||||
|
||||
self.images = self.topDialog.get_object ("images").get_active ()
|
||||
if self.images:
|
||||
images_path = self.topDialog.get_object ("images_path")
|
||||
self.images_path = unicode(images_path.get_text ())
|
||||
else:
|
||||
self.images_path = ""
|
||||
|
||||
class GeneWebWriter(object):
|
||||
def __init__(self, database, msg_callback, filename="", option_box=None,
|
||||
def __init__(self, database, filename, msg_callback, option_box=None,
|
||||
callback=None):
|
||||
self.db = database
|
||||
self.option_box = option_box
|
||||
self.filename = filename
|
||||
self.callback = callback
|
||||
self.msg_callback = msg_callback
|
||||
self.option_box = option_box
|
||||
self.callback = callback
|
||||
if callable(self.callback): # callback is really callable
|
||||
self.update = self.update_real
|
||||
else:
|
||||
self.update = self.update_empty
|
||||
|
||||
self.plist = {}
|
||||
self.flist = {}
|
||||
|
||||
self.persons_details_done = []
|
||||
self.persons_notes_done = []
|
||||
self.person_ids = {}
|
||||
|
||||
if not option_box:
|
||||
self.restrict = 0
|
||||
self.copy = 0
|
||||
self.images = 0
|
||||
else:
|
||||
if option_box:
|
||||
self.option_box.parse_options()
|
||||
|
||||
self.restrict = self.option_box.restrict
|
||||
self.living = self.option_box.living
|
||||
self.exclnotes = self.option_box.exclnotes
|
||||
self.copy = self.option_box.copy
|
||||
self.images = self.option_box.images
|
||||
self.images_path = self.option_box.images_path
|
||||
|
||||
if not option_box.cfilter.is_empty():
|
||||
self.db = gen.proxy.FilterProxyDb(self.db, option_box.cfilter)
|
||||
|
||||
self.plist.update([p, 1] for p in self.db.iter_person_handles())
|
||||
|
||||
self.flist = {}
|
||||
for key in self.plist:
|
||||
p = self.db.get_person_from_handle(key)
|
||||
for family_handle in p.get_family_handle_list():
|
||||
self.flist[family_handle] = 1
|
||||
|
||||
# remove families that dont contain father AND mother
|
||||
# because GeneWeb requires both to be present
|
||||
templist = self.flist
|
||||
self.flist = {}
|
||||
for family_handle in templist:
|
||||
family = self.db.get_family_from_handle(family_handle)
|
||||
if family:
|
||||
father_handle = family.get_father_handle()
|
||||
mother_handle = family.get_mother_handle()
|
||||
if father_handle and mother_handle:
|
||||
self.flist[family_handle] = 1
|
||||
|
||||
self.db = option_box.get_filtered_database(self.db)
|
||||
|
||||
def update_empty(self):
|
||||
pass
|
||||
@ -222,6 +101,7 @@ class GeneWebWriter(object):
|
||||
self.msg_callback(_("Could not create %s") % self.filename)
|
||||
return False
|
||||
|
||||
self.flist = [x for x in self.db.iter_family_handles()]
|
||||
if len(self.flist) < 1:
|
||||
self.msg_callback(_("No families matched by selected filter"))
|
||||
return False
|
||||
@ -258,7 +138,7 @@ class GeneWebWriter(object):
|
||||
self.write_sources( family.get_source_references())
|
||||
self.write_children( family, father)
|
||||
self.write_notes( family, father, mother)
|
||||
if not (self.restrict and self.exclnotes):
|
||||
if True: # FIXME: not (self.restrict and self.exclnotes):
|
||||
notelist = family.get_note_list()
|
||||
note = ""
|
||||
for notehandle in notelist:
|
||||
@ -274,7 +154,7 @@ class GeneWebWriter(object):
|
||||
def write_witness(self, family):
|
||||
# FIXME: witnesses are not in events anymore
|
||||
return
|
||||
|
||||
|
||||
if self.restrict:
|
||||
return
|
||||
event_ref_list = family.get_event_ref_list()
|
||||
@ -301,8 +181,9 @@ class GeneWebWriter(object):
|
||||
)
|
||||
|
||||
def write_sources(self,reflist):
|
||||
if self.restrict and self.exclnotes:
|
||||
return
|
||||
# FIXME
|
||||
#if self.restrict and self.exclnotes:
|
||||
# return
|
||||
|
||||
if reflist:
|
||||
for sr in reflist:
|
||||
@ -336,8 +217,9 @@ class GeneWebWriter(object):
|
||||
self.writeln("end")
|
||||
|
||||
def write_notes(self,family, father, mother):
|
||||
if self.restrict and self.exclnotes:
|
||||
return
|
||||
# FIXME:
|
||||
#if self.restrict and self.exclnotes:
|
||||
# return
|
||||
|
||||
self.write_note_of_person(father)
|
||||
self.write_note_of_person(mother)
|
||||
@ -379,8 +261,9 @@ class GeneWebWriter(object):
|
||||
self.writeln("end notes")
|
||||
|
||||
def get_full_person_info(self, person):
|
||||
if self.restrict:
|
||||
return "0 "
|
||||
# FIXME:
|
||||
#if self.restrict:
|
||||
# return "0 "
|
||||
|
||||
retval = ""
|
||||
|
||||
@ -451,27 +334,27 @@ class GeneWebWriter(object):
|
||||
return str.replace(' ','_')
|
||||
|
||||
def get_ref_name(self,person):
|
||||
missing_surname = config.get("preferences.no-surname-text")
|
||||
#missing_surname = config.get("preferences.no-surname-text")
|
||||
surname = self.rem_spaces( person.get_primary_name().get_surname())
|
||||
firstname = config.get('preferences.private-given-text')
|
||||
if not (Utils.probably_alive(person,self.db) and \
|
||||
self.restrict and self.living):
|
||||
firstname = self.rem_spaces( person.get_primary_name().get_first_name())
|
||||
#firstname = config.get('preferences.private-given-text')
|
||||
#if not (Utils.probably_alive(person,self.db) and \
|
||||
# self.restrict and self.living):
|
||||
firstname = self.rem_spaces( person.get_primary_name().get_first_name())
|
||||
if person.get_handle() not in self.person_ids:
|
||||
self.person_ids[person.get_handle()] = len(self.person_ids)
|
||||
return "%s %s.%d" % (surname or missing_surname, firstname,
|
||||
return "%s %s.%d" % (surname, firstname,
|
||||
self.person_ids[person.get_handle()])
|
||||
|
||||
def get_child_ref_name(self,person,father_lastname):
|
||||
missing_first_name = config.get("preferences.no-given-text")
|
||||
#missing_first_name = config.get("preferences.no-given-text")
|
||||
surname = self.rem_spaces( person.get_primary_name().get_surname())
|
||||
firstname = config.get('preferences.private-given-text')
|
||||
if not (Utils.probably_alive(person,self.db) and \
|
||||
self.restrict and self.living):
|
||||
firstname = self.rem_spaces( person.get_primary_name().get_first_name())
|
||||
#firstname = config.get('preferences.private-given-text')
|
||||
#if not (Utils.probably_alive(person,self.db) and \
|
||||
# self.restrict and self.living):
|
||||
firstname = self.rem_spaces( person.get_primary_name().get_first_name())
|
||||
if person.get_handle() not in self.person_ids:
|
||||
self.person_ids[person.get_handle()] = len(self.person_ids)
|
||||
ret = "%s.%d" % (firstname or missing_first_name, self.person_ids[person.get_handle()])
|
||||
ret = "%s.%d" % (firstname, self.person_ids[person.get_handle()])
|
||||
if surname != father_lastname: ret += " " + surname
|
||||
return ret
|
||||
|
||||
@ -611,5 +494,5 @@ class GeneWebWriter(object):
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def exportData(database, filename, msg_callback, option_box=None, callback=None):
|
||||
gw = GeneWebWriter(database, msg_callback, filename, option_box, callback)
|
||||
gw = GeneWebWriter(database, filename, msg_callback, option_box, callback)
|
||||
return gw.export_data()
|
||||
|
@ -84,27 +84,7 @@ def writeData(database, filename, msg_callback, option_box=None, callback=None):
|
||||
|
||||
if option_box:
|
||||
option_box.parse_options()
|
||||
|
||||
if option_box.private:
|
||||
database = gen.proxy.PrivateProxyDb(database)
|
||||
|
||||
if option_box.restrict:
|
||||
database = gen.proxy.LivingProxyDb(
|
||||
database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
|
||||
|
||||
# Apply the Person Filter
|
||||
if not option_box.cfilter.is_empty():
|
||||
database = gen.proxy.FilterProxyDb(database, option_box.cfilter)
|
||||
|
||||
# Apply the Note Filter
|
||||
if not option_box.nfilter.is_empty():
|
||||
database = gen.proxy.FilterProxyDb(
|
||||
database, note_filter=option_box.nfilter)
|
||||
|
||||
# Apply the ReferencedProxyDb to remove any objects not referenced
|
||||
# after any of the other proxies have been applied
|
||||
if option_box.unlinked:
|
||||
database = gen.proxy.ReferencedProxyDb(database)
|
||||
database = option_box.get_filtered_database(database)
|
||||
|
||||
writer = PackageWriter(database, filename, msg_callback, callback)
|
||||
return writer.export()
|
||||
|
@ -47,83 +47,21 @@ log = logging.getLogger(".ExportVCal")
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ExportOptions import WriterOptionBox
|
||||
from Filters import GenericFilter, Rules, build_filter_model
|
||||
import Utils
|
||||
from gen.lib import Date, EventType
|
||||
import Errors
|
||||
from glade import Glade
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# CalendarWriterOptionBox class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class CalendarWriterOptionBox(object):
|
||||
"""
|
||||
Create a VBox with the option widgets and define methods to retrieve
|
||||
the options.
|
||||
|
||||
"""
|
||||
def __init__(self, person):
|
||||
self.person = person
|
||||
|
||||
self.topDialog = Glade()
|
||||
self.copy = 0
|
||||
|
||||
def get_option_box(self):
|
||||
self.filters = self.topDialog.get_object("filter")
|
||||
|
||||
everyone_filter = GenericFilter()
|
||||
everyone_filter.set_name(_("Entire Database"))
|
||||
everyone_filter.add_rule(Rules.Person.Everyone([]))
|
||||
|
||||
the_filters = [everyone_filter]
|
||||
|
||||
if self.person:
|
||||
des = GenericFilter()
|
||||
des.set_name(_("Descendants of %s") %
|
||||
self.person.get_primary_name().get_name())
|
||||
des.add_rule(Rules.Person.IsDescendantOf(
|
||||
[self.person.get_gramps_id(),1]))
|
||||
|
||||
ans = GenericFilter()
|
||||
ans.set_name(_("Ancestors of %s") %
|
||||
self.person.get_primary_name().get_name())
|
||||
ans.add_rule(Rules.Person.IsAncestorOf(
|
||||
[self.person.get_gramps_id(),1]))
|
||||
|
||||
com = GenericFilter()
|
||||
com.set_name(_("People with common ancestor with %s") %
|
||||
self.person.get_primary_name().get_name())
|
||||
com.add_rule(Rules.Person.HasCommonAncestorWith(
|
||||
[self.person.get_gramps_id()]))
|
||||
|
||||
the_filters += [des, ans, com]
|
||||
|
||||
from Filters import CustomFilters
|
||||
the_filters.extend(CustomFilters.get_filters('Person'))
|
||||
self.filter_menu = build_filter_model(the_filters)
|
||||
self.filters.set_model(self.filter_menu)
|
||||
self.filters.set_active(0)
|
||||
|
||||
the_box = self.topDialog.get_object('vbox1')
|
||||
the_parent = self.topDialog.get_object('dialog-vbox1')
|
||||
the_parent.remove(the_box)
|
||||
self.topDialog.toplevel.destroy()
|
||||
return the_box
|
||||
|
||||
def parse_options(self):
|
||||
self.cfilter = self.filter_menu[self.filters.get_active()][1]
|
||||
|
||||
class CalendarWriter(object):
|
||||
def __init__(self, database, msg_callback, cl=0, filename="", option_box=None,
|
||||
def __init__(self, database, filename, msg_callback, option_box=None,
|
||||
callback=None):
|
||||
self.db = database
|
||||
self.option_box = option_box
|
||||
self.cl = cl
|
||||
self.filename = filename
|
||||
self.callback = callback
|
||||
self.msg_callback = msg_callback
|
||||
self.option_box = option_box
|
||||
self.callback = callback
|
||||
if callable(self.callback): # callback is really callable
|
||||
self.update = self.update_real
|
||||
else:
|
||||
@ -139,29 +77,9 @@ class CalendarWriter(object):
|
||||
self.persons_notes_done = []
|
||||
self.person_ids = {}
|
||||
|
||||
if not option_box:
|
||||
self.cl_setup()
|
||||
else:
|
||||
if option_box:
|
||||
self.option_box.parse_options()
|
||||
|
||||
if self.option_box.cfilter is None:
|
||||
self.plist.udpate([p, 1]
|
||||
for p in self.db.iter_person_handles())
|
||||
else:
|
||||
try:
|
||||
self.plist.update([p, 1]
|
||||
for p in self.option_box.cfilter.apply(
|
||||
self.db, self.db.iter_person_handles()))
|
||||
except Errors.FilterError, msg:
|
||||
(m1, m2) = msg.messages()
|
||||
self.msg_callback(m1, m2)
|
||||
return
|
||||
|
||||
self.flist = {}
|
||||
for key in self.plist:
|
||||
p = self.db.get_person_from_handle(key)
|
||||
for family_handle in p.get_family_handle_list():
|
||||
self.flist[family_handle] = 1
|
||||
self.db = option_box.get_filtered_database(self.db)
|
||||
|
||||
def update_empty(self):
|
||||
pass
|
||||
@ -173,17 +91,6 @@ class CalendarWriter(object):
|
||||
self.callback(newval)
|
||||
self.oldval = newval
|
||||
|
||||
def cl_setup(self):
|
||||
for p in self.db.iter_person_handles():
|
||||
self.plist[p] = 1
|
||||
|
||||
self.flist = {}
|
||||
|
||||
for key in self.plist:
|
||||
p = self.db.get_person_from_handle(key)
|
||||
for family_handle in p.get_family_handle_list():
|
||||
self.flist[family_handle] = 1
|
||||
|
||||
def writeln(self, text):
|
||||
#self.g.write('%s\n' % (text.encode('iso-8859-1')))
|
||||
self.g.write('%s\n' % (text.encode(sys.getfilesystemencoding())))
|
||||
@ -205,12 +112,13 @@ class CalendarWriter(object):
|
||||
self.writeln("PRODID:-//GNU//Gramps//EN")
|
||||
self.writeln("VERSION:1.0")
|
||||
|
||||
self.total = len(self.plist) + len(self.flist)
|
||||
for key in self.plist:
|
||||
self.total = (len([x for x in self.db.iter_person_handles()]) +
|
||||
len([x for x in self.db.iter_family_handles()]))
|
||||
for key in self.db.iter_person_handles():
|
||||
self.write_person(key)
|
||||
self.update()
|
||||
|
||||
for key in self.flist:
|
||||
for key in self.db.iter_family_handles():
|
||||
self.write_family(key)
|
||||
self.update()
|
||||
|
||||
@ -339,6 +247,6 @@ class CalendarWriter(object):
|
||||
#
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def exportData(database, filename, option_box=None, callback=None):
|
||||
def exportData(database, filename, msg_callback, option_box=None, callback=None):
|
||||
cw = CalendarWriter(database, 0, filename, option_box, callback)
|
||||
return cw.export_data(filename)
|
||||
|
@ -46,107 +46,27 @@ log = logging.getLogger(".ExportVCard")
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from ExportOptions import WriterOptionBox
|
||||
from Filters import GenericFilter, Rules, build_filter_model
|
||||
from gen.lib import Date
|
||||
import Errors
|
||||
from glade import Glade
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# CardWriterOptionBox class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class CardWriterOptionBox(object):
|
||||
"""
|
||||
Create a VBox with the option widgets and define methods to retrieve
|
||||
the options.
|
||||
|
||||
"""
|
||||
def __init__(self, person):
|
||||
self.person = person
|
||||
|
||||
def get_option_box(self):
|
||||
|
||||
self.topDialog = Glade()
|
||||
|
||||
self.filters = self.topDialog.get_object("filter")
|
||||
self.copy = 0
|
||||
|
||||
all = GenericFilter()
|
||||
all.set_name(_("Entire Database"))
|
||||
all.add_rule(Rules.Person.Everyone([]))
|
||||
|
||||
the_filters = [all]
|
||||
|
||||
if self.person:
|
||||
des = GenericFilter()
|
||||
des.set_name(_("Descendants of %s") %
|
||||
self.person.get_primary_name().get_name())
|
||||
des.add_rule(Rules.Person.IsDescendantOf(
|
||||
[self.person.get_gramps_id(),1]))
|
||||
|
||||
ans = GenericFilter()
|
||||
ans.set_name(_("Ancestors of %s") %
|
||||
self.person.get_primary_name().get_name())
|
||||
ans.add_rule(Rules.Person.IsAncestorOf(
|
||||
[self.person.get_gramps_id(),1]))
|
||||
|
||||
com = GenericFilter()
|
||||
com.set_name(_("People with common ancestor with %s") %
|
||||
self.person.get_primary_name().get_name())
|
||||
com.add_rule(Rules.Person.HasCommonAncestorWith(
|
||||
[self.person.get_gramps_id()]))
|
||||
|
||||
the_filters += [des, ans, com]
|
||||
|
||||
from Filters import CustomFilters
|
||||
the_filters.extend(CustomFilters.get_filters('Person'))
|
||||
self.filter_menu = build_filter_model(the_filters)
|
||||
self.filters.set_model(self.filter_menu)
|
||||
self.filters.set_active(0)
|
||||
|
||||
the_box = self.topDialog.get_object('vbox1')
|
||||
the_parent = self.topDialog.get_object('dialog-vbox1')
|
||||
the_parent.remove(the_box)
|
||||
self.topDialog.toplevel.destroy()
|
||||
return the_box
|
||||
|
||||
def parse_options(self):
|
||||
self.cfilter = self.filter_menu[self.filters.get_active()][1]
|
||||
|
||||
class CardWriter(object):
|
||||
def __init__(self, database, msg_callback, cl=0, filename="", option_box=None,
|
||||
callback=None):
|
||||
def __init__(self, database, filename, msg_callback, option_box=None, callback=None):
|
||||
self.db = database
|
||||
self.option_box = option_box
|
||||
self.cl = cl
|
||||
self.filename = filename
|
||||
self.callback = callback
|
||||
self.msg_callback = msg_callback
|
||||
self.option_box = option_box
|
||||
self.callback = callback
|
||||
if callable(self.callback): # callback is really callable
|
||||
self.update = self.update_real
|
||||
else:
|
||||
self.update = self.update_empty
|
||||
|
||||
self.plist = {}
|
||||
|
||||
if not option_box:
|
||||
self.cl_setup()
|
||||
else:
|
||||
if option_box:
|
||||
self.option_box.parse_options()
|
||||
|
||||
if self.option_box.cfilter is None:
|
||||
for p in self.db.iter_person_handles():
|
||||
self.plist[p] = 1
|
||||
else:
|
||||
try:
|
||||
for p in self.option_box.cfilter.apply(self.db,
|
||||
self.db.iter_person_handles()):
|
||||
self.plist[p] = 1
|
||||
except Errors.FilterError, msg:
|
||||
(m1, m2) = msg.messages()
|
||||
self.msg_callback(m1, m2)
|
||||
return
|
||||
self.db = option_box.get_filtered_database(self.db)
|
||||
|
||||
def update_empty(self):
|
||||
pass
|
||||
@ -158,9 +78,6 @@ class CardWriter(object):
|
||||
self.callback(newval)
|
||||
self.oldval = newval
|
||||
|
||||
def cl_setup(self):
|
||||
self.plist.update([p, 1] for p in self.db.iter_person_handles())
|
||||
|
||||
def writeln(self, text):
|
||||
#self.g.write('%s\n' % (text.encode('iso-8859-1')))
|
||||
self.g.write('%s\n' % (text.encode(sys.getfilesystemencoding())))
|
||||
@ -180,8 +97,8 @@ class CardWriter(object):
|
||||
|
||||
self.count = 0
|
||||
self.oldval = 0
|
||||
self.total = len(self.plist)
|
||||
for key in self.plist:
|
||||
self.total = len([x for x in self.db.iter_person_handles()])
|
||||
for key in self.db.iter_person_handles():
|
||||
self.write_person(key)
|
||||
self.update()
|
||||
|
||||
@ -252,6 +169,6 @@ class CardWriter(object):
|
||||
#
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
def exportData(database, filename, option_box=None, callback=None):
|
||||
cw = CardWriter(database, 0, filename, option_box, callback)
|
||||
def exportData(database, filename, msg_callback, option_box=None, callback=None):
|
||||
cw = CardWriter(database, filename, msg_callback, option_box, callback)
|
||||
return cw.export_data(filename)
|
||||
|
@ -1163,27 +1163,7 @@ def export_data(database, filename, msg_callback, option_box=None, callback=None
|
||||
|
||||
if option_box:
|
||||
option_box.parse_options()
|
||||
|
||||
if option_box.private:
|
||||
database = gen.proxy.PrivateProxyDb(database)
|
||||
|
||||
if option_box.restrict:
|
||||
database = gen.proxy.LivingProxyDb(
|
||||
database, gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
|
||||
|
||||
# Apply the Person Filter
|
||||
if not option_box.cfilter.is_empty():
|
||||
database = gen.proxy.FilterProxyDb(database, option_box.cfilter)
|
||||
|
||||
# Apply the Note Filter
|
||||
if not option_box.nfilter.is_empty():
|
||||
database = gen.proxy.FilterProxyDb(
|
||||
database, note_filter=option_box.nfilter)
|
||||
|
||||
# Apply the ReferencedProxyDb to remove any objects not referenced
|
||||
# after any of the other proxies have been applied
|
||||
if option_box.unlinked:
|
||||
database = gen.proxy.ReferencedProxyDb(database)
|
||||
database = option_box.get_filtered_database(database)
|
||||
|
||||
g = XmlWriter(database, msg_callback, callback, 0, compress)
|
||||
return g.write(filename)
|
||||
|
@ -58,7 +58,7 @@ plg.status = STABLE
|
||||
plg.fname = 'ExportFtree.py'
|
||||
plg.ptype = EXPORT
|
||||
plg.export_function = 'writeData'
|
||||
plg.export_options = 'FtreeWriterOptionBox'
|
||||
plg.export_options = 'WriterOptionBox'
|
||||
plg.export_options_title = ('Web Family Tree export options')
|
||||
plg.extension = "wft"
|
||||
|
||||
@ -101,7 +101,7 @@ plg.status = STABLE
|
||||
plg.fname = 'ExportGeneWeb.py'
|
||||
plg.ptype = EXPORT
|
||||
plg.export_function = 'exportData'
|
||||
plg.export_options = 'GeneWebWriterOptionBox'
|
||||
plg.export_options = 'WriterOptionBox'
|
||||
plg.export_options_title = ('GeneWeb export options')
|
||||
plg.extension = "gw"
|
||||
|
||||
@ -167,7 +167,7 @@ plg.status = STABLE
|
||||
plg.fname = 'ExportVCalendar.py'
|
||||
plg.ptype = EXPORT
|
||||
plg.export_function = 'exportData'
|
||||
plg.export_options = 'CalendarWriterOptionBox'
|
||||
plg.export_options = 'WriterOptionBox'
|
||||
plg.export_options_title = ('vCalendar export options')
|
||||
plg.extension = "vcs"
|
||||
|
||||
@ -188,6 +188,6 @@ plg.status = STABLE
|
||||
plg.fname = 'ExportVCard.py'
|
||||
plg.ptype = EXPORT
|
||||
plg.export_function = 'exportData'
|
||||
plg.export_options = 'CardWriterOptionBox'
|
||||
plg.export_options = 'WriterOptionBox'
|
||||
plg.export_options_title = ('vCard export options')
|
||||
plg.extension = "vcf"
|
||||
|
Loading…
Reference in New Issue
Block a user