From ca4856adeed456e472eecfcc137c71b4f698293f Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 3 Aug 2005 19:25:03 +0000 Subject: [PATCH] ProgressMeter additions svn: r5008 --- gramps2/ChangeLog | 6 ++++ gramps2/src/GrampsDbBase.py | 30 +++++++++++++++++ gramps2/src/Utils.py | 58 ++++++++++++++++++++++++++++++++ gramps2/src/plugins/Check.py | 65 +++++++++++++++++++++++++++++++++--- 4 files changed, 154 insertions(+), 5 deletions(-) diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index d62c33485..fb09d93dc 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,9 @@ +2005-08-03 Don Allingham + * src/GrampsDbBase.py: provide functions for indicating the number + of items in each table + * src/Check.py: Add ProgressMeter calls + * src/Utils.py: Define new ProgressMeter class + 2005-08-02 Alex Roitman * src/Bookmarks.py: Convert from CList to ListModel and TreeView; Remove Cancel and OK buttons, Add Close button; make all changes diff --git a/gramps2/src/GrampsDbBase.py b/gramps2/src/GrampsDbBase.py index 936fd5db0..4035bb08b 100644 --- a/gramps2/src/GrampsDbBase.py +++ b/gramps2/src/GrampsDbBase.py @@ -783,6 +783,36 @@ class GrampsDbBase(GrampsDBCallback.GrampsDBCallback): """ return len(self.person_map) + def get_number_of_families(self): + """ + Returns the number of families currently in the databse. + """ + return len(self.family_map) + + def get_number_of_events(self): + """ + Returns the number of events currently in the databse. + """ + return len(self.event_map) + + def get_number_of_places(self): + """ + Returns the number of places currently in the databse. + """ + return len(self.place_map) + + def get_number_of_sources(self): + """ + Returns the number of sources currently in the databse. + """ + return len(self.source_map) + + def get_number_of_media_objects(self): + """ + Returns the number of media objects currently in the databse. + """ + return len(self.media_map) + def get_person_handles(self,sort_handles=True): """ Returns a list of database handles, one handle for each Person in diff --git a/gramps2/src/Utils.py b/gramps2/src/Utils.py index 07c0db6d3..4681b2e18 100644 --- a/gramps2/src/Utils.py +++ b/gramps2/src/Utils.py @@ -810,3 +810,61 @@ def strip_context(msgid,sep='|'): if msgval == msgid and sep_idx != -1: msgval = msgid[sep_idx+1:] return msgval + +class ProgressMeter: + """ + Progress meter class for GRAMPS. + """ + def __init__(self,title,header): + """ + Specify the title and the current pass header. + """ + self.ptop = gtk.Dialog() + self.ptop.set_has_separator(False) + self.ptop.set_title(title) + self.ptop.set_border_width(12) + self.ptop.vbox.set_spacing(10) + lbl = gtk.Label('%s' % title) + lbl.set_use_markup(True) + self.lbl = gtk.Label(header) + self.lbl.set_use_markup(True) + self.ptop.vbox.add(lbl) + self.ptop.vbox.add(self.lbl) + self.ptop.vbox.set_border_width(24) + self.pbar = gtk.ProgressBar() + + self.ptop.set_size_request(350,125) + self.ptop.vbox.add(self.pbar) + self.ptop.show_all() + + def set_pass(self,header,total): + """ + Reset for another pass. Provide a new header and define number + of steps to be used. + """ + self.pbar_max = total + self.pbar_index = 0.0 + self.lbl.set_text(header) + self.pbar.set_fraction(0.0) + while gtk.events_pending(): + gtk.main_iteration() + + def step(self): + """Click the progress bar over to the next value. Be paranoid + and insure that it doesn't go over 100%.""" + self.pbar_index = self.pbar_index + 1.0 + if (self.pbar_index > self.pbar_max): + self.pbar_index = self.pbar_max + + val = self.pbar_index/self.pbar_max + + self.pbar.set_text("%d of %d (%.1f%%)" % (self.pbar_index,self.pbar_max,(val*100))) + self.pbar.set_fraction(val) + while gtk.events_pending(): + gtk.main_iteration() + + def close(self): + """ + Close the progress meter + """ + self.ptop.destroy() diff --git a/gramps2/src/plugins/Check.py b/gramps2/src/plugins/Check.py index 7a2fa7a22..e39030311 100644 --- a/gramps2/src/plugins/Check.py +++ b/gramps2/src/plugins/Check.py @@ -120,11 +120,16 @@ class CheckIntegrity: self.invalid_death_events = [] self.invalid_place_references = [] self.invalid_source_references = [] + self.progress = Utils.ProgressMeter('Checking database','') def family_errors(self): return len(self.broken_parent_links) + len(self.broken_links) + len(self.empty_family) + len(self.duplicate_links) def cleanup_duplicate_spouses(self): + + self.progress.set_pass(_('Looking for duplicate spouses'), + self.db.get_number_of_people()) + cursor = self.db.get_person_cursor() data = cursor.first() while data: @@ -140,11 +145,17 @@ class CheckIntegrity: p.set_family_handle_list(new_list) self.db.commit_person(p,self.trans) data = cursor.next() + self.progress.step() cursor.close() def check_for_broken_family_links(self): # Check persons referenced by the family objects - for family_handle in self.db.get_family_handles(): + + fhandle_list = self.db.get_family_handles() + self.progress.set_pass(_('Looking for broken family links'), + len(fhandle_list) + self.db.get_number_of_people()) + + for family_handle in fhandle_list: family = self.db.get_family_from_handle(family_handle) father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() @@ -193,7 +204,8 @@ class CheckIntegrity: family.remove_child_handle(child_handle) self.db.commit_family(family,self.trans) self.broken_links.append((child_handle,family_handle)) - + self.progress.step() + # Check persons membership in referenced families for person_handle in self.db.get_person_handles(): person = self.db.get_person_from_handle(person_handle) @@ -227,8 +239,13 @@ class CheckIntegrity: person.remove_family_handle(family_handle) self.db.commit_person(person,self.trans) self.broken_links.append((person_handle,family_handle)) + self.progress.step() def cleanup_missing_photos(self,cl=0): + + self.progress.set_pass(_('Looking for unused objects'), + len(self.db.get_media_object_handles())) + missmedia_action = 0 #------------------------------------------------------------------------- def remove_clicked(): @@ -318,9 +335,17 @@ class CheckIntegrity: leave_clicked() elif missmedia_action == 3: select_clicked() + self.progress.step() def cleanup_empty_families(self,automatic): - for family_handle in self.db.get_family_handles(): + + fhandle_list = self.db.get_family_handles() + + self.progress.set_pass(_('Looking for empty families'), + len(fhandle_list)) + for family_handle in fhandle_list: + self.progress.step() + family = self.db.get_family_from_handle(family_handle) father_handle = family.get_father_handle() mother_handle = family.get_mother_handle() @@ -352,7 +377,12 @@ class CheckIntegrity: self.db.remove_family(family_handle,self.trans) def check_parent_relationships(self): - for family_handle in self.db.get_family_handles(): + + fhandle_list = self.db.get_family_handles() + self.progress.set_pass(_('Looking for broken parent relationships'), + len(fhandle_list)) + + for family_handle in fhandle_list: family = self.db.get_family_from_handle(family_handle) mother_handle = family.get_mother_handle() father_handle = family.get_father_handle() @@ -400,7 +430,12 @@ class CheckIntegrity: self.db.commit_family(family,self.trans) def check_events(self): + self.progress.set_pass(_('Looking for event problems'), + self.db.get_number_of_people()) + for key in self.db.get_person_handles(sort_handles=False): + self.progress.step() + person = self.db.get_person_from_handle(key) birth_handle = person.get_birth_handle() if birth_handle: @@ -441,7 +476,12 @@ class CheckIntegrity: self.invalid_events.append(key) def check_place_references(self): - for key in self.db.get_event_handles(): + elist = self.db.get_event_handles() + + self.progress.set_pass(_('Looking for place reference problems'), + len(elist)) + + for key in elist: event = self.db.get_event_from_handle(key) place_handle = event.get_place_handle() if place_handle: @@ -454,10 +494,19 @@ class CheckIntegrity: def check_source_references(self): known_handles = self.db.get_source_handles() + + total = self.db.get_number_of_people() + self.db.get_number_of_families() + \ + self.db.get_number_of_events() + self.db.get_number_of_places() + \ + self.db.get_number_of_media_objects() + \ + self.db.get_number_of_sources() + + self.progress.set_pass(_('Looking for source reference problems'), + total) cursor = self.db.get_person_cursor() data = cursor.first() while data: + self.progress.step() handle,info = data person = RelLib.Person() person.unserialize(info) @@ -477,6 +526,7 @@ class CheckIntegrity: cursor = self.db.get_family_cursor() data = cursor.first() while data: + self.progress.step() handle,info = data family = RelLib.Family() family.unserialize(info) @@ -496,6 +546,7 @@ class CheckIntegrity: cursor = self.db.get_place_cursor() data = cursor.first() while data: + self.progress.step() handle,info = data place = RelLib.Place() place.unserialize(info) @@ -515,6 +566,7 @@ class CheckIntegrity: cursor = self.db.get_source_cursor() data = cursor.first() while data: + self.progress.step() handle,info = data source = RelLib.Source() source.unserialize(info) @@ -534,6 +586,7 @@ class CheckIntegrity: cursor = self.db.get_media_cursor() data = cursor.first() while data: + self.progress.step() handle,info = data obj = RelLib.MediaObject() obj.unserialize(info) @@ -553,6 +606,7 @@ class CheckIntegrity: cursor = self.db.get_event_cursor() data = cursor.first() while data: + self.progress.step() handle,info = data event = RelLib.Event() event.unserialize(info) @@ -570,6 +624,7 @@ class CheckIntegrity: cursor.close() def build_report(self,cl=0): + self.progress.close() bad_photos = len(self.bad_photo) replaced_photos = len(self.replaced_photo) removed_photos = len(self.removed_photo)