Merge pull request #329 from prculley/exportgedcom
Improve progress indications for Gedcom export
This commit is contained in:
commit
4c010a94e4
@ -72,10 +72,17 @@ class UpdateCallback:
|
||||
Reset the count to zero.
|
||||
"""
|
||||
self.count = 0
|
||||
self.oldval = 0
|
||||
self.oldval = -1
|
||||
self.oldtime = 0
|
||||
self.text = text
|
||||
|
||||
def set_text(self, text):
|
||||
"""
|
||||
Set the text.
|
||||
"""
|
||||
self.text = text
|
||||
self.oldval = -1
|
||||
|
||||
def set_total(self, total):
|
||||
"""
|
||||
Set the total.
|
||||
@ -96,7 +103,7 @@ class UpdateCallback:
|
||||
Called when the count is updated.
|
||||
"""
|
||||
self.count += 1
|
||||
if not count:
|
||||
if count is None:
|
||||
count = self.count
|
||||
newval = int(100 * count/self.total)
|
||||
newtime = time.time()
|
||||
|
@ -274,7 +274,8 @@ class ExportAssistant(ManagedWindow, Gtk.Assistant):
|
||||
# add new content
|
||||
if 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()
|
||||
vbox.add(box)
|
||||
else:
|
||||
@ -639,6 +640,9 @@ class ExportAssistant(ManagedWindow, Gtk.Assistant):
|
||||
self.progressbar.set_fraction(min(value/100.0, 1.0))
|
||||
if text:
|
||||
self.progressbar.set_text("%s: %d%%" % (text, value))
|
||||
self.confirm.set_label(
|
||||
_("Please wait while your data is selected and exported") +
|
||||
"\n" + text)
|
||||
else:
|
||||
self.progressbar.set_text("%d%%" % value)
|
||||
while Gtk.events_pending():
|
||||
|
@ -62,11 +62,11 @@ class Progress:
|
||||
Mirros the same interface that the ExportAssistant uses in the
|
||||
selection, but this is for the preview selection.
|
||||
"""
|
||||
def __init__(self, uistate):
|
||||
def __init__(self, parent):
|
||||
from gi.repository import Gtk
|
||||
self.pm = ProgressMeter(_("Selecting Preview Data"),
|
||||
_('Selecting...'),
|
||||
parent=uistate.window)
|
||||
parent=parent)
|
||||
self.progress_cnt = 0
|
||||
self.title = _("Selecting...")
|
||||
while Gtk.events_pending():
|
||||
@ -106,11 +106,12 @@ class WriterOptionBox:
|
||||
the options.
|
||||
|
||||
"""
|
||||
def __init__(self, person, dbstate, uistate, track=[]):
|
||||
def __init__(self, person, dbstate, uistate, track=[], window=None):
|
||||
self.person = person
|
||||
self.dbstate = dbstate
|
||||
self.uistate = uistate
|
||||
self.track = track
|
||||
self.window = window
|
||||
self.preview_dbase = None
|
||||
self.preview_button = None
|
||||
self.preview_proxy_button = {}
|
||||
@ -256,7 +257,7 @@ class WriterOptionBox:
|
||||
Calculate previews to see the selected data.
|
||||
"""
|
||||
self.parse_options()
|
||||
pm = Progress(self.uistate)
|
||||
pm = Progress(self.window)
|
||||
self.preview_dbase = self.get_filtered_database(self.dbstate.db, pm, preview=True)
|
||||
pm.close()
|
||||
self.preview_button.set_sensitive(0)
|
||||
@ -586,8 +587,8 @@ class WriterOptionBox:
|
||||
if self.private:
|
||||
if progress:
|
||||
progress.reset(_("Filtering private data"))
|
||||
progress.progress_cnt += 1
|
||||
progress.update(progress.progress_cnt)
|
||||
progress.progress_cnt += 1
|
||||
dbase = PrivateProxyDb(dbase)
|
||||
|
||||
# If the restrict flag is set, apply the LivingProxyDb
|
||||
@ -595,8 +596,8 @@ class WriterOptionBox:
|
||||
if self.restrict_num > 0:
|
||||
if progress:
|
||||
progress.reset(_("Filtering living persons"))
|
||||
progress.progress_cnt += 1
|
||||
progress.update(progress.progress_cnt)
|
||||
progress.progress_cnt += 1
|
||||
mode = [None, # include living
|
||||
LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY,
|
||||
LivingProxyDb.MODE_REPLACE_COMPLETE_NAME,
|
||||
@ -612,8 +613,8 @@ class WriterOptionBox:
|
||||
if self.cfilter != None and not self.cfilter.is_empty():
|
||||
if progress:
|
||||
progress.reset(_("Applying selected person filter"))
|
||||
progress.progress_cnt += 1
|
||||
progress.update(progress.progress_cnt)
|
||||
progress.progress_cnt += 1
|
||||
dbase = FilterProxyDb(
|
||||
dbase, self.cfilter)
|
||||
|
||||
@ -622,17 +623,17 @@ class WriterOptionBox:
|
||||
if self.nfilter != None and not self.nfilter.is_empty():
|
||||
if progress:
|
||||
progress.reset(_("Applying selected note filter"))
|
||||
progress.progress_cnt += 1
|
||||
progress.update(progress.progress_cnt)
|
||||
progress.progress_cnt += 1
|
||||
dbase = FilterProxyDb(
|
||||
dbase, note_filter=self.nfilter)
|
||||
|
||||
# Apply the ReferencedBySelection
|
||||
elif proxy_name == "reference":
|
||||
if progress:
|
||||
if self.reference_num > 0 and progress:
|
||||
progress.reset(_("Filtering referenced records"))
|
||||
progress.progress_cnt += 1
|
||||
progress.update(progress.progress_cnt)
|
||||
progress.progress_cnt += 1
|
||||
if self.reference_num == 0:
|
||||
pass
|
||||
elif self.reference_num == 1:
|
||||
@ -673,7 +674,7 @@ class WriterOptionBox:
|
||||
from ...dialog import ErrorDialog
|
||||
ErrorDialog(_("Cannot edit a system filter"),
|
||||
_("Please select a different filter to edit"),
|
||||
parent=self.uistate.window)
|
||||
parent=self.window)
|
||||
|
||||
def edit_filter_save(self, filterdb, namespace):
|
||||
"""
|
||||
|
@ -129,6 +129,7 @@ PEDIGREE_TYPES = {
|
||||
ChildRefType.FOSTER: 'Foster',
|
||||
}
|
||||
|
||||
NOTES_PER_PERSON = 104 # fudge factor to make progress meter a bit smoother
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# sort_handles_by_id
|
||||
@ -217,15 +218,10 @@ class GedcomWriter(UpdateCallback):
|
||||
|
||||
def __init__(self, database, user, option_box=None):
|
||||
UpdateCallback.__init__(self, user.callback)
|
||||
self.total = 100
|
||||
self.dbase = database
|
||||
self.dirname = None
|
||||
self.gedcom_file = None
|
||||
|
||||
# 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.progress_cnt = 0
|
||||
self.setup(option_box)
|
||||
|
||||
def setup(self, option_box):
|
||||
@ -245,6 +241,15 @@ class GedcomWriter(UpdateCallback):
|
||||
|
||||
self.dirname = os.path.dirname (filename)
|
||||
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._submitter()
|
||||
self._individuals()
|
||||
@ -391,9 +396,7 @@ class GedcomWriter(UpdateCallback):
|
||||
people will be confused when the progress bar is idle.
|
||||
|
||||
"""
|
||||
self.reset(_("Writing individuals"))
|
||||
self.progress_cnt += 1
|
||||
self.update(self.progress_cnt)
|
||||
self.set_text(_("Writing individuals"))
|
||||
phandles = self.dbase.iter_person_handles()
|
||||
|
||||
sorted_list = []
|
||||
@ -405,6 +408,7 @@ class GedcomWriter(UpdateCallback):
|
||||
sorted_list.sort()
|
||||
|
||||
for data in sorted_list:
|
||||
self.update()
|
||||
self._person(self.dbase.get_person_from_handle(data[1]))
|
||||
|
||||
def _person(self, person):
|
||||
@ -797,9 +801,7 @@ class GedcomWriter(UpdateCallback):
|
||||
"""
|
||||
Write out the list of families, sorting by Gramps ID.
|
||||
"""
|
||||
self.reset(_("Writing families"))
|
||||
self.progress_cnt += 1
|
||||
self.update(self.progress_cnt)
|
||||
self.set_text(_("Writing families"))
|
||||
# generate a list of (GRAMPS_ID, HANDLE) pairs. This list
|
||||
# can then be sorted by the sort routine, which will use the
|
||||
# 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
|
||||
# has already been sorted by GRAMPS_ID
|
||||
for family_handle in [hndl[1] for hndl in sorted_list]:
|
||||
self.update()
|
||||
self._family(self.dbase.get_family_from_handle(family_handle))
|
||||
|
||||
def _family(self, family):
|
||||
@ -963,13 +966,12 @@ class GedcomWriter(UpdateCallback):
|
||||
"""
|
||||
Write out the list of sources, sorting by Gramps ID.
|
||||
"""
|
||||
self.reset(_("Writing sources"))
|
||||
self.progress_cnt += 1
|
||||
self.update(self.progress_cnt)
|
||||
self.set_text(_("Writing sources"))
|
||||
sorted_list = sort_handles_by_id(self.dbase.get_source_handles(),
|
||||
self.dbase.get_source_from_handle)
|
||||
|
||||
for (source_id, handle) in sorted_list:
|
||||
self.update()
|
||||
source = self.dbase.get_source_from_handle(handle)
|
||||
if source is None: continue
|
||||
self._writeln(0, '@%s@' % source_id, 'SOUR')
|
||||
@ -998,13 +1000,16 @@ class GedcomWriter(UpdateCallback):
|
||||
"""
|
||||
Write out the list of notes, sorting by Gramps ID.
|
||||
"""
|
||||
self.reset(_("Writing notes"))
|
||||
self.progress_cnt += 1
|
||||
self.update(self.progress_cnt)
|
||||
self.set_text(_("Writing notes"))
|
||||
note_cnt = 0
|
||||
sorted_list = sort_handles_by_id(self.dbase.get_note_handles(),
|
||||
self.dbase.get_note_from_handle)
|
||||
|
||||
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)
|
||||
if note is None: continue
|
||||
self._note_record(note)
|
||||
@ -1036,15 +1041,14 @@ class GedcomWriter(UpdateCallback):
|
||||
+1 RIN <AUTOMATED_RECORD_ID> {0:1}
|
||||
+1 <<CHANGE_DATE>> {0:1}
|
||||
"""
|
||||
self.reset(_("Writing repositories"))
|
||||
self.progress_cnt += 1
|
||||
self.update(self.progress_cnt)
|
||||
self.set_text(_("Writing repositories"))
|
||||
sorted_list = sort_handles_by_id(self.dbase.get_repository_handles(),
|
||||
self.dbase.get_repository_from_handle)
|
||||
|
||||
# GEDCOM only allows for a single repository per source
|
||||
|
||||
for (repo_id, handle) in sorted_list:
|
||||
self.update()
|
||||
repo = self.dbase.get_repository_from_handle(handle)
|
||||
if repo is None: continue
|
||||
self._writeln(0, '@%s@' % repo_id, 'REPO' )
|
||||
|
Loading…
Reference in New Issue
Block a user