Merge pull request #329 from prculley/exportgedcom

Improve progress indications for Gedcom export
This commit is contained in:
Sam Manzi 2017-01-25 16:07:11 +11:00 committed by GitHub
commit 4c010a94e4
4 changed files with 51 additions and 35 deletions

View File

@ -72,10 +72,17 @@ class UpdateCallback:
Reset the count to zero. Reset the count to zero.
""" """
self.count = 0 self.count = 0
self.oldval = 0 self.oldval = -1
self.oldtime = 0 self.oldtime = 0
self.text = text self.text = text
def set_text(self, text):
"""
Set the text.
"""
self.text = text
self.oldval = -1
def set_total(self, total): def set_total(self, total):
""" """
Set the total. Set the total.
@ -96,7 +103,7 @@ class UpdateCallback:
Called when the count is updated. Called when the count is updated.
""" """
self.count += 1 self.count += 1
if not count: if count is None:
count = self.count count = self.count
newval = int(100 * count/self.total) newval = int(100 * count/self.total)
newtime = time.time() newtime = time.time()

View File

@ -274,7 +274,8 @@ class ExportAssistant(ManagedWindow, Gtk.Assistant):
# add new content # add new content
if config_box_class: if config_box_class:
self.option_box_instance = config_box_class( self.option_box_instance = config_box_class(
self.person, self.dbstate, self.uistate, track=self.track) self.person, self.dbstate, self.uistate, track=self.track,
window=self.window)
box = self.option_box_instance.get_option_box() box = self.option_box_instance.get_option_box()
vbox.add(box) vbox.add(box)
else: else:
@ -639,6 +640,9 @@ class ExportAssistant(ManagedWindow, Gtk.Assistant):
self.progressbar.set_fraction(min(value/100.0, 1.0)) self.progressbar.set_fraction(min(value/100.0, 1.0))
if text: if text:
self.progressbar.set_text("%s: %d%%" % (text, value)) self.progressbar.set_text("%s: %d%%" % (text, value))
self.confirm.set_label(
_("Please wait while your data is selected and exported") +
"\n" + text)
else: else:
self.progressbar.set_text("%d%%" % value) self.progressbar.set_text("%d%%" % value)
while Gtk.events_pending(): while Gtk.events_pending():

View File

@ -62,11 +62,11 @@ class Progress:
Mirros the same interface that the ExportAssistant uses in the Mirros the same interface that the ExportAssistant uses in the
selection, but this is for the preview selection. selection, but this is for the preview selection.
""" """
def __init__(self, uistate): def __init__(self, parent):
from gi.repository import Gtk from gi.repository import Gtk
self.pm = ProgressMeter(_("Selecting Preview Data"), self.pm = ProgressMeter(_("Selecting Preview Data"),
_('Selecting...'), _('Selecting...'),
parent=uistate.window) parent=parent)
self.progress_cnt = 0 self.progress_cnt = 0
self.title = _("Selecting...") self.title = _("Selecting...")
while Gtk.events_pending(): while Gtk.events_pending():
@ -106,11 +106,12 @@ class WriterOptionBox:
the options. the options.
""" """
def __init__(self, person, dbstate, uistate, track=[]): def __init__(self, person, dbstate, uistate, track=[], window=None):
self.person = person self.person = person
self.dbstate = dbstate self.dbstate = dbstate
self.uistate = uistate self.uistate = uistate
self.track = track self.track = track
self.window = window
self.preview_dbase = None self.preview_dbase = None
self.preview_button = None self.preview_button = None
self.preview_proxy_button = {} self.preview_proxy_button = {}
@ -256,7 +257,7 @@ class WriterOptionBox:
Calculate previews to see the selected data. Calculate previews to see the selected data.
""" """
self.parse_options() self.parse_options()
pm = Progress(self.uistate) pm = Progress(self.window)
self.preview_dbase = self.get_filtered_database(self.dbstate.db, pm, preview=True) self.preview_dbase = self.get_filtered_database(self.dbstate.db, pm, preview=True)
pm.close() pm.close()
self.preview_button.set_sensitive(0) self.preview_button.set_sensitive(0)
@ -586,8 +587,8 @@ class WriterOptionBox:
if self.private: if self.private:
if progress: if progress:
progress.reset(_("Filtering private data")) progress.reset(_("Filtering private data"))
progress.progress_cnt += 1
progress.update(progress.progress_cnt) progress.update(progress.progress_cnt)
progress.progress_cnt += 1
dbase = PrivateProxyDb(dbase) dbase = PrivateProxyDb(dbase)
# If the restrict flag is set, apply the LivingProxyDb # If the restrict flag is set, apply the LivingProxyDb
@ -595,8 +596,8 @@ class WriterOptionBox:
if self.restrict_num > 0: if self.restrict_num > 0:
if progress: if progress:
progress.reset(_("Filtering living persons")) progress.reset(_("Filtering living persons"))
progress.progress_cnt += 1
progress.update(progress.progress_cnt) progress.update(progress.progress_cnt)
progress.progress_cnt += 1
mode = [None, # include living mode = [None, # include living
LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY, LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY,
LivingProxyDb.MODE_REPLACE_COMPLETE_NAME, LivingProxyDb.MODE_REPLACE_COMPLETE_NAME,
@ -612,8 +613,8 @@ class WriterOptionBox:
if self.cfilter != None and not self.cfilter.is_empty(): if self.cfilter != None and not self.cfilter.is_empty():
if progress: if progress:
progress.reset(_("Applying selected person filter")) progress.reset(_("Applying selected person filter"))
progress.progress_cnt += 1
progress.update(progress.progress_cnt) progress.update(progress.progress_cnt)
progress.progress_cnt += 1
dbase = FilterProxyDb( dbase = FilterProxyDb(
dbase, self.cfilter) dbase, self.cfilter)
@ -622,17 +623,17 @@ class WriterOptionBox:
if self.nfilter != None and not self.nfilter.is_empty(): if self.nfilter != None and not self.nfilter.is_empty():
if progress: if progress:
progress.reset(_("Applying selected note filter")) progress.reset(_("Applying selected note filter"))
progress.progress_cnt += 1
progress.update(progress.progress_cnt) progress.update(progress.progress_cnt)
progress.progress_cnt += 1
dbase = FilterProxyDb( dbase = FilterProxyDb(
dbase, note_filter=self.nfilter) dbase, note_filter=self.nfilter)
# Apply the ReferencedBySelection # Apply the ReferencedBySelection
elif proxy_name == "reference": elif proxy_name == "reference":
if progress: if self.reference_num > 0 and progress:
progress.reset(_("Filtering referenced records")) progress.reset(_("Filtering referenced records"))
progress.progress_cnt += 1
progress.update(progress.progress_cnt) progress.update(progress.progress_cnt)
progress.progress_cnt += 1
if self.reference_num == 0: if self.reference_num == 0:
pass pass
elif self.reference_num == 1: elif self.reference_num == 1:
@ -673,7 +674,7 @@ class WriterOptionBox:
from ...dialog import ErrorDialog from ...dialog import ErrorDialog
ErrorDialog(_("Cannot edit a system filter"), ErrorDialog(_("Cannot edit a system filter"),
_("Please select a different filter to edit"), _("Please select a different filter to edit"),
parent=self.uistate.window) parent=self.window)
def edit_filter_save(self, filterdb, namespace): def edit_filter_save(self, filterdb, namespace):
""" """

View File

@ -129,6 +129,7 @@ PEDIGREE_TYPES = {
ChildRefType.FOSTER: 'Foster', ChildRefType.FOSTER: 'Foster',
} }
NOTES_PER_PERSON = 104 # fudge factor to make progress meter a bit smoother
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# sort_handles_by_id # sort_handles_by_id
@ -217,15 +218,10 @@ class GedcomWriter(UpdateCallback):
def __init__(self, database, user, option_box=None): def __init__(self, database, user, option_box=None):
UpdateCallback.__init__(self, user.callback) UpdateCallback.__init__(self, user.callback)
self.total = 100
self.dbase = database self.dbase = database
self.dirname = None self.dirname = None
self.gedcom_file = None self.gedcom_file = None
self.progress_cnt = 0
# The number of different stages other than any of the optional filters
# which the write_gedcom_file method will call.
self.progress_cnt = 5
self.setup(option_box) self.setup(option_box)
def setup(self, option_box): def setup(self, option_box):
@ -245,6 +241,15 @@ class GedcomWriter(UpdateCallback):
self.dirname = os.path.dirname (filename) self.dirname = os.path.dirname (filename)
with open(filename, "w", encoding='utf-8') as self.gedcom_file: with open(filename, "w", encoding='utf-8') as self.gedcom_file:
person_len = self.dbase.get_number_of_people()
family_len = self.dbase.get_number_of_families()
source_len = self.dbase.get_number_of_sources()
repo_len = self.dbase.get_number_of_repositories()
note_len = self.dbase.get_number_of_notes() / NOTES_PER_PERSON
total_steps = (person_len + family_len + source_len + repo_len +
note_len)
self.set_total(total_steps)
self._header(filename) self._header(filename)
self._submitter() self._submitter()
self._individuals() self._individuals()
@ -391,9 +396,7 @@ class GedcomWriter(UpdateCallback):
people will be confused when the progress bar is idle. people will be confused when the progress bar is idle.
""" """
self.reset(_("Writing individuals")) self.set_text(_("Writing individuals"))
self.progress_cnt += 1
self.update(self.progress_cnt)
phandles = self.dbase.iter_person_handles() phandles = self.dbase.iter_person_handles()
sorted_list = [] sorted_list = []
@ -405,6 +408,7 @@ class GedcomWriter(UpdateCallback):
sorted_list.sort() sorted_list.sort()
for data in sorted_list: for data in sorted_list:
self.update()
self._person(self.dbase.get_person_from_handle(data[1])) self._person(self.dbase.get_person_from_handle(data[1]))
def _person(self, person): def _person(self, person):
@ -797,9 +801,7 @@ class GedcomWriter(UpdateCallback):
""" """
Write out the list of families, sorting by Gramps ID. Write out the list of families, sorting by Gramps ID.
""" """
self.reset(_("Writing families")) self.set_text(_("Writing families"))
self.progress_cnt += 1
self.update(self.progress_cnt)
# generate a list of (GRAMPS_ID, HANDLE) pairs. This list # generate a list of (GRAMPS_ID, HANDLE) pairs. This list
# can then be sorted by the sort routine, which will use the # can then be sorted by the sort routine, which will use the
# first value of the tuple as the sort key. # first value of the tuple as the sort key.
@ -809,6 +811,7 @@ class GedcomWriter(UpdateCallback):
# loop through the sorted list, pulling of the handle. This list # loop through the sorted list, pulling of the handle. This list
# has already been sorted by GRAMPS_ID # has already been sorted by GRAMPS_ID
for family_handle in [hndl[1] for hndl in sorted_list]: for family_handle in [hndl[1] for hndl in sorted_list]:
self.update()
self._family(self.dbase.get_family_from_handle(family_handle)) self._family(self.dbase.get_family_from_handle(family_handle))
def _family(self, family): def _family(self, family):
@ -963,13 +966,12 @@ class GedcomWriter(UpdateCallback):
""" """
Write out the list of sources, sorting by Gramps ID. Write out the list of sources, sorting by Gramps ID.
""" """
self.reset(_("Writing sources")) self.set_text(_("Writing sources"))
self.progress_cnt += 1
self.update(self.progress_cnt)
sorted_list = sort_handles_by_id(self.dbase.get_source_handles(), sorted_list = sort_handles_by_id(self.dbase.get_source_handles(),
self.dbase.get_source_from_handle) self.dbase.get_source_from_handle)
for (source_id, handle) in sorted_list: for (source_id, handle) in sorted_list:
self.update()
source = self.dbase.get_source_from_handle(handle) source = self.dbase.get_source_from_handle(handle)
if source is None: continue if source is None: continue
self._writeln(0, '@%s@' % source_id, 'SOUR') self._writeln(0, '@%s@' % source_id, 'SOUR')
@ -998,13 +1000,16 @@ class GedcomWriter(UpdateCallback):
""" """
Write out the list of notes, sorting by Gramps ID. Write out the list of notes, sorting by Gramps ID.
""" """
self.reset(_("Writing notes")) self.set_text(_("Writing notes"))
self.progress_cnt += 1 note_cnt = 0
self.update(self.progress_cnt)
sorted_list = sort_handles_by_id(self.dbase.get_note_handles(), sorted_list = sort_handles_by_id(self.dbase.get_note_handles(),
self.dbase.get_note_from_handle) self.dbase.get_note_from_handle)
for note_handle in [hndl[1] for hndl in sorted_list]: for note_handle in [hndl[1] for hndl in sorted_list]:
# the following makes the progress bar a bit smoother
if not note_cnt % NOTES_PER_PERSON:
self.update()
note_cnt += 1
note = self.dbase.get_note_from_handle(note_handle) note = self.dbase.get_note_from_handle(note_handle)
if note is None: continue if note is None: continue
self._note_record(note) self._note_record(note)
@ -1036,15 +1041,14 @@ class GedcomWriter(UpdateCallback):
+1 RIN <AUTOMATED_RECORD_ID> {0:1} +1 RIN <AUTOMATED_RECORD_ID> {0:1}
+1 <<CHANGE_DATE>> {0:1} +1 <<CHANGE_DATE>> {0:1}
""" """
self.reset(_("Writing repositories")) self.set_text(_("Writing repositories"))
self.progress_cnt += 1
self.update(self.progress_cnt)
sorted_list = sort_handles_by_id(self.dbase.get_repository_handles(), sorted_list = sort_handles_by_id(self.dbase.get_repository_handles(),
self.dbase.get_repository_from_handle) self.dbase.get_repository_from_handle)
# GEDCOM only allows for a single repository per source # GEDCOM only allows for a single repository per source
for (repo_id, handle) in sorted_list: for (repo_id, handle) in sorted_list:
self.update()
repo = self.dbase.get_repository_from_handle(handle) repo = self.dbase.get_repository_from_handle(handle)
if repo is None: continue if repo is None: continue
self._writeln(0, '@%s@' % repo_id, 'REPO' ) self._writeln(0, '@%s@' % repo_id, 'REPO' )