diff --git a/gramps/cli/test/user_test.py b/gramps/cli/test/user_test.py index 6157c176e..a02a751bc 100644 --- a/gramps/cli/test/user_test.py +++ b/gramps/cli/test/user_test.py @@ -32,9 +32,9 @@ import sys try: if sys.version_info < (3,3): - from mock import Mock, patch + from mock import Mock, NonCallableMock else: - from unittest.mock import Mock, patch + from unittest.mock import Mock, NonCallableMock MOCKING = True @@ -151,40 +151,5 @@ class TestUser_quiet(unittest.TestCase): assert len(self.user._fileout.method_calls ) == 0, list(self.user._fileout.method_calls) -@unittest.skipUnless(MOCKING, "Requires unittest.mock to run") -class TestUser_progress(unittest.TestCase): - _progress_begin_step_end = \ - TestUser_quiet.test_progress_can_begin_step_end.__func__ - - def setUp(self): - self.user = user.User() - self.user._fileout = Mock(spec=sys.stderr) - - def test_can_step_using_with(self): - # Collect baseline output from the old-style interface (begin/step/end) - self._progress_begin_step_end() - self.expected_output = list(self.user._fileout.method_calls) - self.user._fileout.reset_mock() - self.assertTrue( - len(self.user._fileout.method_calls) == 0, - list(self.user._fileout.method_calls)) - - with self.user.progress("Foo", "Bar", 0) as step: - for i in range(10): - step() - - # Output using `with' differs from one with `progress_...' - self.assertEqual(self.expected_output, - list(self.user._fileout.method_calls)) - - def test_ends_progress_upon_exception_in_with(self): - with patch('gramps.cli.user.User.end_progress') as MockEP: - try: - with self.user.progress("Foo", "Bar", 0) as step: - raise Exception() - except Exception: - pass - self.assertTrue(MockEP.called) - if __name__ == "__main__": unittest.main() diff --git a/gramps/gen/user.py b/gramps/gen/user.py index 70b18b764..cb6975bb1 100644 --- a/gramps/gen/user.py +++ b/gramps/gen/user.py @@ -21,7 +21,6 @@ # import sys -from contextlib import contextmanager """ The User class provides basic interaction with the user. @@ -41,8 +40,6 @@ class User(): def begin_progress(self, title, message, steps): """ Start showing a progress indicator to the user. - - Don't use this method directly, use progress instead. @param title: the title of the progress meter @type title: str @@ -59,8 +56,6 @@ class User(): def step_progress(self): """ Advance the progress meter. - - Don't use this method directly, use progress instead. """ pass @@ -85,33 +80,8 @@ class User(): def end_progress(self): """ Stop showing the progress indicator to the user. - - Don't use this method directly, use progress instead. """ pass - - # Context-manager wrapper of the begin/step/end_progress above - @contextmanager - def progress(self, *args, **kwargs): - """ - Preferred form of context reporting. - - Parameters: same as for begin_progress. - - Usage example (see gramps/cli/test/user_test.py): - with self.user.progress("Foo", "Bar", 0) as step: - for i in range(10): - step() - - Ensures end_progress will be called even if an exception was thrown. - """ - self.begin_progress(*args, **kwargs) - try: - yield self.step_progress - except: - raise - finally: - self.end_progress() def prompt(self, title, message, accept_label, reject_label): """ diff --git a/gramps/plugins/drawreport/ancestortree.py b/gramps/plugins/drawreport/ancestortree.py index cd0e287a8..d7b185291 100644 --- a/gramps/plugins/drawreport/ancestortree.py +++ b/gramps/plugins/drawreport/ancestortree.py @@ -707,59 +707,61 @@ class AncestorTree(Report): self.canvas.report_opts.box_pgap *= self.connect.get_val('box_Yscale') self.canvas.report_opts.box_mgap *= self.connect.get_val('box_Yscale') - with self._user.progress(_('Ancestor Tree'), - _('Making the Tree...'), 4) as step: + self._user.begin_progress(_('Ancestor Tree'), + _('Making the Tree...'), 4) - #make the tree onto the canvas - inlc_marr = self.connect.get_val("inc_marr") - self.max_generations = self.connect.get_val('maxgen') - fillout = self.connect.get_val('fill_out') - tree = MakeAncestorTree(database, self.canvas, self.max_generations, - inlc_marr, fillout) - tree.start(self.connect.get_val('pid')) - tree = None + #make the tree onto the canvas + inlc_marr = self.connect.get_val("inc_marr") + self.max_generations = self.connect.get_val('maxgen') + fillout = self.connect.get_val('fill_out') + tree = MakeAncestorTree(database, self.canvas, self.max_generations, + inlc_marr, fillout) + tree.start(self.connect.get_val('pid')) + tree = None - step() + self._user.step_progress() - #Title - title = self.connect.title_class(self.doc) - center = self.database.get_person_from_gramps_id( - self.connect.get_val('pid') - ) - title.calc_title(center) - self.canvas.add_title(title) + #Title + title = self.connect.title_class(self.doc) + center = self.database.get_person_from_gramps_id( + self.connect.get_val('pid') + ) + title.calc_title(center) + self.canvas.add_title(title) - #make the report as big as it wants to be. - compress = self.connect.get_val('compress_tree') - report = MakeReport(database, self.doc, self.canvas, font_normal, - inlc_marr, compress) - report.start() - self.max_generations = report.get_generations() #already know - report = None + #make the report as big as it wants to be. + compress = self.connect.get_val('compress_tree') + report = MakeReport(database, self.doc, self.canvas, font_normal, + inlc_marr, compress) + report.start() + self.max_generations = report.get_generations() #already know + report = None - step() + self._user.step_progress() - #Note? - if self.connect.get_val("inc_note"): - note_box = NoteBox(self.doc, "AC2-note-box", - self.connect.get_val("note_place")) - subst = SubstKeywords(self.database, None, None) - note_box.text = subst.replace_and_clean( - self.connect.get_val('note_disp')) - self.canvas.add_note(note_box) + #Note? + if self.connect.get_val("inc_note"): + note_box = NoteBox(self.doc, "AC2-note-box", + self.connect.get_val("note_place")) + subst = SubstKeywords(self.database, None, None) + note_box.text = subst.replace_and_clean( + self.connect.get_val('note_disp')) + self.canvas.add_note(note_box) - #Now we have the report in its full size. - #Do we want to scale the report? - one_page = self.connect.get_val("resize_page") - scale_report = self.connect.get_val("scale_tree") + #Now we have the report in its full size. + #Do we want to scale the report? + one_page = self.connect.get_val("resize_page") + scale_report = self.connect.get_val("scale_tree") - scale = self.canvas.scale_report(one_page, - scale_report != 0, scale_report == 2) - - step() + scale = self.canvas.scale_report(one_page, + scale_report != 0, scale_report == 2) + + self._user.step_progress() - if scale != 1 or self.connect.get_val('shadowscale') != 1.0: - self.scale_styles(scale) + if scale != 1 or self.connect.get_val('shadowscale') != 1.0: + self.scale_styles(scale) + + self._user.end_progress() def write_report(self): @@ -794,26 +796,29 @@ class AncestorTree(Report): #lets finally make some pages!!! ##################### pages = self.canvas.page_count(incblank) - with self._user.progress( _('Ancestor Tree'), - _('Printing the Tree...'), pages) as step: + self._user.begin_progress( _('Ancestor Tree'), + _('Printing the Tree...'), pages) - for page in self.canvas.page_iter_gen(incblank): + for page in self.canvas.page_iter_gen(incblank): - self.doc.start_page() + self.doc.start_page() + + #do we need to print a border? + if inc_border: + page.draw_border('AC2-line') + + #Do we need to print the page number? + if prnnum: + page_num_box.display(page) + + #Print the individual people and lines + page.display() + + self._user.step_progress() + self.doc.end_page() + + self._user.end_progress() - #do we need to print a border? - if inc_border: - page.draw_border('AC2-line') - - #Do we need to print the page number? - if prnnum: - page_num_box.display(page) - - #Print the individual people and lines - page.display() - - step() - self.doc.end_page() def scale_styles(self, scale): """ diff --git a/gramps/plugins/drawreport/calendarreport.py b/gramps/plugins/drawreport/calendarreport.py index 53ddabd9c..3b0f486f9 100644 --- a/gramps/plugins/drawreport/calendarreport.py +++ b/gramps/plugins/drawreport/calendarreport.py @@ -165,11 +165,12 @@ class Calendar(Report): # get data from database: self.collect_data() # generate the report: - with self._user.progress( _('Calendar Report'), - _('Formatting months...'), 12) as step: - for month in range(1, 13): - step() - self.print_page(month) + self._user.begin_progress( _('Calendar Report'), + _('Formatting months...'), 12) + for month in range(1, 13): + self._user.step_progress() + self.print_page(month) + self._user.end_progress() def print_page(self, month): """ @@ -267,131 +268,134 @@ class Calendar(Report): """ db = self.database people = db.iter_person_handles() - with self._user.progress(_('Calendar Report'), + self._user.begin_progress(_('Calendar Report'), _('Applying Filter...'), - db.get_number_of_people()) as step: - people = self.filter.apply(self.database, people, step) + db.get_number_of_people()) + people = self.filter.apply(self.database, people, + self._user.step_progress) + self._user.end_progress() - with self._user.progress(_('Calendar Report'), - _('Reading database...'), len(people)) as step: - for person_handle in people: - step() - person = db.get_person_from_handle(person_handle) - mark = ReportUtils.get_person_mark(db, person) - birth_ref = person.get_birth_ref() - birth_date = None - if birth_ref: - birth_event = db.get_event_from_handle(birth_ref.ref) - birth_date = birth_event.get_date_object() + self._user.begin_progress(_('Calendar Report'), + _('Reading database...'), len(people)) + for person_handle in people: + self._user.step_progress() + person = db.get_person_from_handle(person_handle) + mark = ReportUtils.get_person_mark(db, person) + birth_ref = person.get_birth_ref() + birth_date = None + if birth_ref: + birth_event = db.get_event_from_handle(birth_ref.ref) + birth_date = birth_event.get_date_object() - if (self.birthdays and birth_date is not None and birth_date.is_valid()): - year = birth_date.get_year() - month = birth_date.get_month() - day = birth_date.get_day() + if (self.birthdays and birth_date is not None and birth_date.is_valid()): + year = birth_date.get_year() + month = birth_date.get_month() + day = birth_date.get_day() - prob_alive_date = Date(self.year, month, day) + prob_alive_date = Date(self.year, month, day) - nyears = self.year - year - # add some things to handle maiden name: - father_lastname = None # husband, actually - if self.maiden_name in ['spouse_first', 'spouse_last']: # get husband's last name: - if person.get_gender() == Person.FEMALE: - family_list = person.get_family_handle_list() - if family_list: - if self.maiden_name == 'spouse_first': - fhandle = family_list[0] - else: - fhandle = family_list[-1] - fam = db.get_family_from_handle(fhandle) - father_handle = fam.get_father_handle() - mother_handle = fam.get_mother_handle() - if mother_handle == person_handle: - if father_handle: - father = db.get_person_from_handle(father_handle) - if father: - father_lastname = father.get_primary_name().get_surname() - short_name = self.get_name(person, father_lastname) - alive = probably_alive(person, db, prob_alive_date) + nyears = self.year - year + # add some things to handle maiden name: + father_lastname = None # husband, actually + if self.maiden_name in ['spouse_first', 'spouse_last']: # get husband's last name: + if person.get_gender() == Person.FEMALE: + family_list = person.get_family_handle_list() + if family_list: + if self.maiden_name == 'spouse_first': + fhandle = family_list[0] + else: + fhandle = family_list[-1] + fam = db.get_family_from_handle(fhandle) + father_handle = fam.get_father_handle() + mother_handle = fam.get_mother_handle() + if mother_handle == person_handle: + if father_handle: + father = db.get_person_from_handle(father_handle) + if father: + father_lastname = father.get_primary_name().get_surname() + short_name = self.get_name(person, father_lastname) + alive = probably_alive(person, db, prob_alive_date) - if not self.alive or alive: - if nyears == 0: - text = _('%(person)s, birth%(relation)s') % { - 'person' : short_name, - 'relation' : ""} - else: - text = (glocale.translation.ngettext('%(person)s, %(age)d%(relation)s', - '%(person)s, %(age)d%(relation)s', nyears) - % {'person' : short_name, - 'age' : nyears, - 'relation' : ""}) - self.add_day_item(text, month, day, marks=[mark]) - if self.anniversaries: - family_list = person.get_family_handle_list() - for fhandle in family_list: - fam = db.get_family_from_handle(fhandle) - father_handle = fam.get_father_handle() - mother_handle = fam.get_mother_handle() - if father_handle == person.get_handle(): - spouse_handle = mother_handle - else: - continue # with next person if the father is not "person" - # this will keep from duplicating the anniversary - if spouse_handle: - spouse = db.get_person_from_handle(spouse_handle) - if spouse: - s_m = ReportUtils.get_person_mark(db, spouse) - spouse_name = self.get_name(spouse) - short_name = self.get_name(person) - # TEMP: this will handle ordered events - # GRAMPS 3.0 will have a new mechanism for start/stop events - are_married = None + if not self.alive or alive: + if nyears == 0: + text = _('%(person)s, birth%(relation)s') % { + 'person' : short_name, + 'relation' : ""} + else: + text = (glocale.translation.ngettext('%(person)s, %(age)d%(relation)s', + '%(person)s, %(age)d%(relation)s', nyears) + % {'person' : short_name, + 'age' : nyears, + 'relation' : ""}) + self.add_day_item(text, month, day, marks=[mark]) + if self.anniversaries: + family_list = person.get_family_handle_list() + for fhandle in family_list: + fam = db.get_family_from_handle(fhandle) + father_handle = fam.get_father_handle() + mother_handle = fam.get_mother_handle() + if father_handle == person.get_handle(): + spouse_handle = mother_handle + else: + continue # with next person if the father is not "person" + # this will keep from duplicating the anniversary + if spouse_handle: + spouse = db.get_person_from_handle(spouse_handle) + if spouse: + s_m = ReportUtils.get_person_mark(db, spouse) + spouse_name = self.get_name(spouse) + short_name = self.get_name(person) + # TEMP: this will handle ordered events + # GRAMPS 3.0 will have a new mechanism for start/stop events + are_married = None + for event_ref in fam.get_event_ref_list(): + event = db.get_event_from_handle(event_ref.ref) + et = EventType + rt = EventRoleType + if event.type in [et.MARRIAGE, + et.MARR_ALT] and \ + (event_ref.get_role() == rt.FAMILY or + event_ref.get_role() == rt.PRIMARY ): + are_married = event + elif event.type in [et.DIVORCE, + et.ANNULMENT, + et.DIV_FILING] and \ + (event_ref.get_role() == rt.FAMILY or + event_ref.get_role() == rt.PRIMARY ): + are_married = None + if are_married is not None: for event_ref in fam.get_event_ref_list(): event = db.get_event_from_handle(event_ref.ref) - et = EventType - rt = EventRoleType - if event.type in [et.MARRIAGE, - et.MARR_ALT] and \ - (event_ref.get_role() == rt.FAMILY or - event_ref.get_role() == rt.PRIMARY ): - are_married = event - elif event.type in [et.DIVORCE, - et.ANNULMENT, - et.DIV_FILING] and \ - (event_ref.get_role() == rt.FAMILY or - event_ref.get_role() == rt.PRIMARY ): - are_married = None - if are_married is not None: - for event_ref in fam.get_event_ref_list(): - event = db.get_event_from_handle(event_ref.ref) - event_obj = event.get_date_object() + event_obj = event.get_date_object() - if event_obj.is_valid(): - year = event_obj.get_year() - month = event_obj.get_month() - day = event_obj.get_day() + if event_obj.is_valid(): + year = event_obj.get_year() + month = event_obj.get_month() + day = event_obj.get_day() - prob_alive_date = Date(self.year, month, day) - - nyears = self.year - year - if nyears == 0: - text = _('%(spouse)s and\n %(person)s, wedding') % { - 'spouse' : spouse_name, - 'person' : short_name, - } - else: - text = (glocale.translation.ngettext("%(spouse)s and\n %(person)s, %(nyears)d", - "%(spouse)s and\n %(person)s, %(nyears)d", nyears) - % {'spouse' : spouse_name, - 'person' : short_name, - 'nyears' : nyears}) + prob_alive_date = Date(self.year, month, day) + + nyears = self.year - year + if nyears == 0: + text = _('%(spouse)s and\n %(person)s, wedding') % { + 'spouse' : spouse_name, + 'person' : short_name, + } + else: + text = (glocale.translation.ngettext("%(spouse)s and\n %(person)s, %(nyears)d", + "%(spouse)s and\n %(person)s, %(nyears)d", nyears) + % {'spouse' : spouse_name, + 'person' : short_name, + 'nyears' : nyears}) - alive1 = probably_alive(person, self.database, - prob_alive_date) - alive2 = probably_alive(spouse, self.database, - prob_alive_date) - if ((self.alive and alive1 and alive2) or not self.alive): - self.add_day_item(text, month, day, - marks=[mark,s_m]) + alive1 = probably_alive(person, self.database, + prob_alive_date) + alive2 = probably_alive(spouse, self.database, + prob_alive_date) + if ((self.alive and alive1 and alive2) or not self.alive): + self.add_day_item(text, month, day, + marks=[mark,s_m]) + self._user.end_progress() #------------------------------------------------------------------------ # diff --git a/gramps/plugins/drawreport/timeline.py b/gramps/plugins/drawreport/timeline.py index 2bde2d035..0c3c5b250 100644 --- a/gramps/plugins/drawreport/timeline.py +++ b/gramps/plugins/drawreport/timeline.py @@ -123,12 +123,13 @@ class TimeLine(Report): def write_report(self): # Apply the filter - with self._user.progress(_('Timeline'), + self._user.begin_progress(_('Timeline'), _('Applying filter...'), - self.database.get_number_of_people()) as step: - self.plist = self.filter.apply(self.database, - self.database.iter_person_handles(), - step) + self.database.get_number_of_people()) + self.plist = self.filter.apply(self.database, + self.database.iter_person_handles(), + self._user.step_progress) + self._user.end_progress() # Find the range of dates to include (low, high) = self.find_year_range() @@ -149,8 +150,9 @@ class TimeLine(Report): self.header = 2.0 # Sort the people as requested - with self._user.progress(_('Timeline'), _('Sorting dates...'), 0) as step: - self.plist.sort(key=self.sort_func) + self._user.begin_progress(_('Timeline'), _('Sorting dates...'), 0) + self.plist.sort(key=self.sort_func) + self._user.end_progress() self.doc.start_page() self.build_grid(low, high, start, stop, True) @@ -160,65 +162,66 @@ class TimeLine(Report): length = len(self.plist) - with self._user.progress(_('Timeline'), - _('Calculating timeline...'), length) as step: + self._user.begin_progress(_('Timeline'), + _('Calculating timeline...'), length) - for p_id in self.plist: - p = self.database.get_person_from_handle(p_id) - birth = get_birth_or_fallback(self.database, p) - if birth: - b = birth.get_date_object().to_calendar(self.calendar).get_year() - else: - b = None + for p_id in self.plist: + p = self.database.get_person_from_handle(p_id) + birth = get_birth_or_fallback(self.database, p) + if birth: + b = birth.get_date_object().to_calendar(self.calendar).get_year() + else: + b = None - death = get_death_or_fallback(self.database, p) - if death: - d = death.get_date_object().to_calendar(self.calendar).get_year() - else: - d = None + death = get_death_or_fallback(self.database, p) + if death: + d = death.get_date_object().to_calendar(self.calendar).get_year() + else: + d = None - n = self._name_display.display(p) - mark = ReportUtils.get_person_mark(self.database, p) - self.doc.draw_text('TLG-text', n, incr+pad, - self.header + (incr+pad)*index, mark) - - y1 = self.header + (pad+incr)*index - y2 = self.header + ((pad+incr)*index)+incr - y3 = (y1+y2)/2.0 - w = 0.05 - - if b: - start_offset = ((float(b-low)/float(high-low)) * (size)) - x1 = start+start_offset - path = [(x1,y1),(x1+w,y3),(x1,y2),(x1-w,y3)] - self.doc.draw_path('TLG-line',path) + n = self._name_display.display(p) + mark = ReportUtils.get_person_mark(self.database, p) + self.doc.draw_text('TLG-text', n, incr+pad, + self.header + (incr+pad)*index, mark) + + y1 = self.header + (pad+incr)*index + y2 = self.header + ((pad+incr)*index)+incr + y3 = (y1+y2)/2.0 + w = 0.05 + + if b: + start_offset = ((float(b-low)/float(high-low)) * (size)) + x1 = start+start_offset + path = [(x1,y1),(x1+w,y3),(x1,y2),(x1-w,y3)] + self.doc.draw_path('TLG-line',path) - if d: - start_offset = ((float(d-low)/float(high-low)) * (size)) - x1 = start+start_offset - path = [(x1,y1),(x1+w,y3),(x1,y2),(x1-w,y3)] - self.doc.draw_path('TLG-solid',path) + if d: + start_offset = ((float(d-low)/float(high-low)) * (size)) + x1 = start+start_offset + path = [(x1,y1),(x1+w,y3),(x1,y2),(x1-w,y3)] + self.doc.draw_path('TLG-solid',path) - if b and d: - start_offset = ((float(b-low)/float(high-low)) * size) + w - stop_offset = ((float(d-low)/float(high-low)) * size) - w + if b and d: + start_offset = ((float(b-low)/float(high-low)) * size) + w + stop_offset = ((float(d-low)/float(high-low)) * size) - w - x1 = start+start_offset - x2 = start+stop_offset - self.doc.draw_line('open',x1,y3,x2,y3) + x1 = start+start_offset + x2 = start+stop_offset + self.doc.draw_line('open',x1,y3,x2,y3) - if (y2 + incr) >= self.doc.get_usable_height(): - if current != length: - self.doc.end_page() - self.doc.start_page() - self.build_grid(low, high,start,stop) - index = 1 - x1,x2,y1,y2 = (0,0,0,0) - else: - index += 1; - current += 1 - step() - self.doc.end_page() + if (y2 + incr) >= self.doc.get_usable_height(): + if current != length: + self.doc.end_page() + self.doc.start_page() + self.build_grid(low, high,start,stop) + index = 1 + x1,x2,y1,y2 = (0,0,0,0) + else: + index += 1; + current += 1 + self._user.step_progress() + self.doc.end_page() + self._user.end_progress() def build_grid(self, year_low, year_high, start_pos, stop_pos, toc=False): """ @@ -340,39 +343,40 @@ class TimeLine(Report): high = year return (low, high) - with self._user.progress(_('Timeline'), + self._user.begin_progress(_('Timeline'), _('Finding date range...'), - len(self.plist)) as step: + len(self.plist)) - for p_id in self.plist: - p = self.database.get_person_from_handle(p_id) - birth = get_birth_or_fallback(self.database, p) - if birth: - b = birth.get_date_object().to_calendar(self.calendar).get_year() - (low, high) = min_max_year(low, high, b) + for p_id in self.plist: + p = self.database.get_person_from_handle(p_id) + birth = get_birth_or_fallback(self.database, p) + if birth: + b = birth.get_date_object().to_calendar(self.calendar).get_year() + (low, high) = min_max_year(low, high, b) - death = get_death_or_fallback(self.database, p) - if death: - d = death.get_date_object().to_calendar(self.calendar).get_year() - (low, high) = min_max_year(low, high, d) - step() + death = get_death_or_fallback(self.database, p) + if death: + d = death.get_date_object().to_calendar(self.calendar).get_year() + (low, high) = min_max_year(low, high, d) + self._user.step_progress() - # round the dates to the nearest decade - if low is not None: - low = int((low/10))*10 - else: - low = high - - if high is not None: - high = int(((high+9)/10))*10 - else: - high = low - - # Make sure the difference is a multiple of 50 so all year ranges land - # on a decade. - if low is not None and high is not None: - low -= 50 - ((high-low) % 50) + # round the dates to the nearest decade + if low is not None: + low = int((low/10))*10 + else: + low = high + if high is not None: + high = int(((high+9)/10))*10 + else: + high = low + + # Make sure the difference is a multiple of 50 so all year ranges land + # on a decade. + if low is not None and high is not None: + low -= 50 - ((high-low) % 50) + + self._user.end_progress() return (low, high) def name_size(self): diff --git a/gramps/plugins/importer/importcsv.py b/gramps/plugins/importer/importcsv.py index 9c056b596..0991a8964 100644 --- a/gramps/plugins/importer/importcsv.py +++ b/gramps/plugins/importer/importcsv.py @@ -321,29 +321,30 @@ class CSVParser(object): :param filehandle: open file handle positioned at start of the file """ + data = self.read_csv(filehandle) progress_title = _('CSV Import') - with self.user.progress(progress_title, - _('Reading data...'), 1) as step: - data = self.read_csv(filehandle) + self.user.begin_progress(progress_title, + _('Reading data...'), 1) + self.user.end_progress() + self.user.begin_progress(progress_title, + _('Importing data...'), len(data)) + tym = time.time() + self.db.disable_signals() + with DbTxn(_("CSV import"), self.db, batch=True) as self.trans: + if self.default_tag and self.default_tag.handle is None: + self.db.add_tag(self.default_tag, self.trans) + self._parse_csv_data(data) + self.db.enable_signals() + self.db.request_rebuild() + tym = time.time() - tym + msg = glocale.translation.ngettext('Import Complete: %d second', + 'Import Complete: %d seconds', tym ) % tym + LOG.debug(msg) + LOG.debug("New Families: %d" % self.fam_count) + LOG.debug("New Individuals: %d" % self.indi_count) + self.user.end_progress() - with self.user.progress(progress_title, - _('Importing data...'), len(data)) as step: - tym = time.time() - self.db.disable_signals() - with DbTxn(_("CSV import"), self.db, batch=True) as self.trans: - if self.default_tag and self.default_tag.handle is None: - self.db.add_tag(self.default_tag, self.trans) - self._parse_csv_data(data, step) - self.db.enable_signals() - self.db.request_rebuild() - tym = time.time() - tym - msg = glocale.translation.ngettext('Import Complete: %d second', - 'Import Complete: %d seconds', tym ) % tym - LOG.debug(msg) - LOG.debug("New Families: %d" % self.fam_count) - LOG.debug("New Individuals: %d" % self.indi_count) - - def _parse_csv_data(self, data, step): + def _parse_csv_data(self, data): """Parse each line of the input data and act accordingly.""" self.lineno = 0 self.index = 0 @@ -354,7 +355,7 @@ class CSVParser(object): header = None line_number = 0 for row in data: - step() + self.user.step_progress() line_number += 1 if "".join(row) == "": # no blanks are allowed inside a table header = None # clear headers, ready for next "table" diff --git a/gramps/plugins/textreport/birthdayreport.py b/gramps/plugins/textreport/birthdayreport.py index 365e28f15..1bef0f45b 100644 --- a/gramps/plugins/textreport/birthdayreport.py +++ b/gramps/plugins/textreport/birthdayreport.py @@ -216,11 +216,12 @@ class BirthdayReport(Report): self.doc.write_text(self._("Relationships shown are to %s") % self._name_display.display_name(name), mark) self.doc.end_paragraph() - with self._user.progress(_('Birthday and Anniversary Report'), - _('Formatting months...'), 12) as step: - for month in range(1, 13): - step() - self.print_page(month) + self._user.begin_progress(_('Birthday and Anniversary Report'), + _('Formatting months...'), 12) + for month in range(1, 13): + self._user.step_progress() + self.print_page(month) + self._user.end_progress() def print_page(self, month): """ Prints a month as a page """ @@ -255,139 +256,141 @@ class BirthdayReport(Report): and text. """ people = self.database.iter_person_handles() - with self._user.progress(_('Birthday and Anniversary Report'), + self._user.begin_progress(_('Birthday and Anniversary Report'), _('Applying Filter...'), - self.database.get_number_of_people()) as step: - people = self.filter.apply(self.database, people, - step) + self.database.get_number_of_people()) + people = self.filter.apply(self.database, people, + self._user.step_progress) + self._user.end_progress() rel_calc = get_relationship_calculator(reinit=True, clocale=self._locale) ngettext = self._locale.translation.ngettext - with self._user.progress(_('Birthday and Anniversary Report'), - _('Reading database...'), len(people)) as step: - for person_handle in people: - step() - person = self.database.get_person_from_handle(person_handle) - birth_ref = person.get_birth_ref() - birth_date = None - if birth_ref: - birth_event = self.database.get_event_from_handle(birth_ref.ref) - birth_date = birth_event.get_date_object() + self._user.begin_progress(_('Birthday and Anniversary Report'), + _('Reading database...'), len(people)) + for person_handle in people: + self._user.step_progress() + person = self.database.get_person_from_handle(person_handle) + birth_ref = person.get_birth_ref() + birth_date = None + if birth_ref: + birth_event = self.database.get_event_from_handle(birth_ref.ref) + birth_date = birth_event.get_date_object() - if (self.birthdays and birth_date is not None and birth_date.is_valid()): - year = birth_date.get_year() - month = birth_date.get_month() - day = birth_date.get_day() + if (self.birthdays and birth_date is not None and birth_date.is_valid()): + year = birth_date.get_year() + month = birth_date.get_month() + day = birth_date.get_day() - prob_alive_date = Date(self.year, month, day) + prob_alive_date = Date(self.year, month, day) - nyears = self.year - year - # add some things to handle maiden name: - father_lastname = None # husband, actually - if self.maiden_name in ['spouse_first', 'spouse_last']: # get husband's last name: - if person.get_gender() == Person.FEMALE: - family_list = person.get_family_handle_list() - if len(family_list) > 0: - if self.maiden_name == 'spouse_first': - fhandle = family_list[0] - else: - fhandle = family_list[-1] - fam = self.database.get_family_from_handle(fhandle) - father_handle = fam.get_father_handle() - mother_handle = fam.get_mother_handle() - if mother_handle == person_handle: - if father_handle: - father = self.database.get_person_from_handle(father_handle) - if father is not None: - primary_name = father.get_primary_name() - if primary_name: - father_lastname = Surname.get_surname(primary_name.get_primary_surname()) + nyears = self.year - year + # add some things to handle maiden name: + father_lastname = None # husband, actually + if self.maiden_name in ['spouse_first', 'spouse_last']: # get husband's last name: + if person.get_gender() == Person.FEMALE: + family_list = person.get_family_handle_list() + if len(family_list) > 0: + if self.maiden_name == 'spouse_first': + fhandle = family_list[0] + else: + fhandle = family_list[-1] + fam = self.database.get_family_from_handle(fhandle) + father_handle = fam.get_father_handle() + mother_handle = fam.get_mother_handle() + if mother_handle == person_handle: + if father_handle: + father = self.database.get_person_from_handle(father_handle) + if father is not None: + primary_name = father.get_primary_name() + if primary_name: + father_lastname = Surname.get_surname(primary_name.get_primary_surname()) - short_name = self.get_name(person, father_lastname) + short_name = self.get_name(person, father_lastname) - alive = probably_alive(person, self.database, prob_alive_date) - if ((self.alive and alive) or not self.alive): + alive = probably_alive(person, self.database, prob_alive_date) + if ((self.alive and alive) or not self.alive): - comment = "" - if self.relationships: - relation = rel_calc.get_one_relationship( - self.database, - self.center_person, - person, - olocale=self._locale) - if relation: - # FIXME this won't work for RTL languages - comment = " --- %s" % relation - if nyears == 0: - text = self._('%(person)s, birth%(relation)s') % { - 'person' : short_name, - 'relation' : comment} - else: - text = (ngettext('%(person)s, %(age)d%(relation)s', - '%(person)s, %(age)d%(relation)s', nyears) - % {'person' : short_name, - 'age' : nyears, - 'relation' : comment}) + comment = "" + if self.relationships: + relation = rel_calc.get_one_relationship( + self.database, + self.center_person, + person, + olocale=self._locale) + if relation: + # FIXME this won't work for RTL languages + comment = " --- %s" % relation + if nyears == 0: + text = self._('%(person)s, birth%(relation)s') % { + 'person' : short_name, + 'relation' : comment} + else: + text = (ngettext('%(person)s, %(age)d%(relation)s', + '%(person)s, %(age)d%(relation)s', nyears) + % {'person' : short_name, + 'age' : nyears, + 'relation' : comment}) - self.add_day_item(text, month, day, person) - if self.anniversaries: - family_list = person.get_family_handle_list() - for fhandle in family_list: - fam = self.database.get_family_from_handle(fhandle) - father_handle = fam.get_father_handle() - mother_handle = fam.get_mother_handle() - if father_handle == person.get_handle(): - spouse_handle = mother_handle - else: - continue # with next person if the father is not "person" - # this will keep from duplicating the anniversary - if spouse_handle: - spouse = self.database.get_person_from_handle(spouse_handle) - if spouse: - spouse_name = self.get_name(spouse) - short_name = self.get_name(person) - # TEMP: this will handle ordered events - # GRAMPS 3.0 will have a new mechanism for start/stop events - are_married = None + self.add_day_item(text, month, day, person) + if self.anniversaries: + family_list = person.get_family_handle_list() + for fhandle in family_list: + fam = self.database.get_family_from_handle(fhandle) + father_handle = fam.get_father_handle() + mother_handle = fam.get_mother_handle() + if father_handle == person.get_handle(): + spouse_handle = mother_handle + else: + continue # with next person if the father is not "person" + # this will keep from duplicating the anniversary + if spouse_handle: + spouse = self.database.get_person_from_handle(spouse_handle) + if spouse: + spouse_name = self.get_name(spouse) + short_name = self.get_name(person) + # TEMP: this will handle ordered events + # GRAMPS 3.0 will have a new mechanism for start/stop events + are_married = None + for event_ref in fam.get_event_ref_list(): + event = self.database.get_event_from_handle(event_ref.ref) + if event.type in [EventType.MARRIAGE, + EventType.MARR_ALT]: + are_married = event + elif event.type in [EventType.DIVORCE, + EventType.ANNULMENT, + EventType.DIV_FILING]: + are_married = None + if are_married is not None: for event_ref in fam.get_event_ref_list(): event = self.database.get_event_from_handle(event_ref.ref) - if event.type in [EventType.MARRIAGE, - EventType.MARR_ALT]: - are_married = event - elif event.type in [EventType.DIVORCE, - EventType.ANNULMENT, - EventType.DIV_FILING]: - are_married = None - if are_married is not None: - for event_ref in fam.get_event_ref_list(): - event = self.database.get_event_from_handle(event_ref.ref) - event_obj = event.get_date_object() - year = event_obj.get_year() - month = event_obj.get_month() - day = event_obj.get_day() - nyears = self.year - year + event_obj = event.get_date_object() + year = event_obj.get_year() + month = event_obj.get_month() + day = event_obj.get_day() + nyears = self.year - year - if event_obj.is_valid(): - if nyears == 0: - text = self._("%(spouse)s and\n %(person)s, wedding") % { - 'spouse' : spouse_name, - 'person' : short_name} - else: - text = (ngettext("%(spouse)s and\n %(person)s, %(nyears)d", - "%(spouse)s and\n %(person)s, %(nyears)d", nyears) - % {'spouse' : spouse_name, - 'person' : short_name, - 'nyears' : nyears}) - - prob_alive_date = Date(self.year, month, day) - alive1 = probably_alive(person, self.database, - prob_alive_date) - alive2 = probably_alive(spouse, self.database, - prob_alive_date) - if (self.alive and alive1 and alive2) or not self.alive: - self.add_day_item(text, month, day, spouse) + if event_obj.is_valid(): + if nyears == 0: + text = self._("%(spouse)s and\n %(person)s, wedding") % { + 'spouse' : spouse_name, + 'person' : short_name} + else: + text = (ngettext("%(spouse)s and\n %(person)s, %(nyears)d", + "%(spouse)s and\n %(person)s, %(nyears)d", nyears) + % {'spouse' : spouse_name, + 'person' : short_name, + 'nyears' : nyears}) + + prob_alive_date = Date(self.year, month, day) + alive1 = probably_alive(person, self.database, + prob_alive_date) + alive2 = probably_alive(spouse, self.database, + prob_alive_date) + if (self.alive and alive1 and alive2) or not self.alive: + self.add_day_item(text, month, day, spouse) + self._user.end_progress() #------------------------------------------------------------------------ # diff --git a/gramps/plugins/textreport/placereport.py b/gramps/plugins/textreport/placereport.py index 21c08a08e..9030c8b71 100644 --- a/gramps/plugins/textreport/placereport.py +++ b/gramps/plugins/textreport/placereport.py @@ -126,22 +126,23 @@ class PlaceReport(Report): """ place_nbr = 1 - with self._user.progress(_("Place Report"), + self._user.begin_progress(_("Place Report"), _("Generating report"), - len(self.place_handles)) as step: + len(self.place_handles)) + + for handle in self.place_handles: + self.__write_place(handle, place_nbr) + if self.center == "Event": + self.__write_referenced_events(handle) + elif self.center == "Person": + self.__write_referenced_persons(handle) + else: + raise AttributeError("no such center: '%s'" % self.center) + place_nbr += 1 + # increment progress bar + self._user.step_progress() - for handle in self.place_handles: - self.__write_place(handle, place_nbr) - if self.center == "Event": - self.__write_referenced_events(handle) - elif self.center == "Person": - self.__write_referenced_persons(handle) - else: - raise AttributeError("no such center: '%s'" % self.center) - place_nbr += 1 - # increment progress bar - step() - + self._user.end_progress() def __write_place(self, handle, place_nbr): """ diff --git a/gramps/plugins/webreport/narrativeweb.py b/gramps/plugins/webreport/narrativeweb.py index 83184d483..dcdf755da 100644 --- a/gramps/plugins/webreport/narrativeweb.py +++ b/gramps/plugins/webreport/narrativeweb.py @@ -3045,15 +3045,16 @@ class FamilyPages(BasePage): for item in self.report.obj_dict[Family].items(): log.debug(" %s" % str(item)) - with self.report.user.progress(_("Narrated Web Site Report"), + self.report.user.begin_progress(_("Narrated Web Site Report"), _("Creating family pages..."), - len(self.report.obj_dict[Family]) + 1) as step: - self.FamilyListPage(self.report, title, - self.report.obj_dict[Family].keys()) + len(self.report.obj_dict[Family]) + 1) + self.FamilyListPage(self.report, title, + self.report.obj_dict[Family].keys()) - for family_handle in self.report.obj_dict[Family]: - step() - self.FamilyPage(self.report, title, family_handle) + for family_handle in self.report.obj_dict[Family]: + self.report.user.step_progress() + self.FamilyPage(self.report, title, family_handle) + self.report.user.end_progress() def FamilyListPage(self, report, title, fam_list): self.dbase_ = report.database @@ -3321,16 +3322,17 @@ class PlacePages(BasePage): log.debug("obj_dict[Place]") for item in self.report.obj_dict[Place].items(): log.debug(" %s" % str(item)) - with self.report.user.progress(_("Narrated Web Site Report"), + self.report.user.begin_progress(_("Narrated Web Site Report"), _("Creating place pages"), - len(self.report.obj_dict[Place]) + 1) as step: + len(self.report.obj_dict[Place]) + 1) - self.PlaceListPage(self.report, title, - self.report.obj_dict[Place].keys()) + self.PlaceListPage(self.report, title, + self.report.obj_dict[Place].keys()) - for place_handle in self.report.obj_dict[Place]: - step() - self.PlacePage(self.report, title, place_handle) + for place_handle in self.report.obj_dict[Place]: + self.report.user.step_progress() + self.PlacePage(self.report, title, place_handle) + self.report.user.end_progress() pass def PlaceListPage(self, report, title, place_handles): @@ -3604,15 +3606,16 @@ class EventPages(BasePage): for event_handle in event_handle_list: event = self.report.database.get_event_from_handle(event_handle) event_types.append(str(event.get_type())) - with self.report.user.progress(_("Narrated Web Site Report"), + self.report.user.begin_progress(_("Narrated Web Site Report"), _("Creating event pages"), - len(event_handle_list) + 1) as step: - self.EventListPage(self.report, title, event_types, event_handle_list) + len(event_handle_list) + 1) + self.EventListPage(self.report, title, event_types, event_handle_list) - for event_handle in event_handle_list: - step() - self.EventPage(self.report, title, event_handle) + for event_handle in event_handle_list: + self.report.user.step_progress() + self.EventPage(self.report, title, event_handle) + self.report.user.end_progress() def EventListPage(self, report, title, event_types, event_handle_list): """ @@ -4148,16 +4151,17 @@ class SourcePages(BasePage): log.debug("obj_dict[Source]") for item in self.report.obj_dict[Source].items(): log.debug(" %s" % str(item)) - with self.report.user.progress(_("Narrated Web Site Report"), + self.report.user.begin_progress(_("Narrated Web Site Report"), _("Creating source pages"), - len(self.report.obj_dict[Source]) + 1) as step: - self.SourceListPage(self.report, title, - self.report.obj_dict[Source].keys()) + len(self.report.obj_dict[Source]) + 1) + self.SourceListPage(self.report, title, + self.report.obj_dict[Source].keys()) - for source_handle in self.report.obj_dict[Source]: - step() - self.SourcePage(self.report, title, source_handle) + for source_handle in self.report.obj_dict[Source]: + self.report.user.step_progress() + self.SourcePage(self.report, title, source_handle) + self.report.user.end_progress() def SourceListPage(self, report, title, source_handles): """ @@ -4362,24 +4366,25 @@ class MediaPages(BasePage): log.debug("obj_dict[Media]") for item in self.report.obj_dict[MediaObject].items(): log.debug(" %s" % str(item)) - with self.report.user.progress(_("Narrated Web Site Report"), + self.report.user.begin_progress(_("Narrated Web Site Report"), _("Creating media pages"), - len(self.report.obj_dict[MediaObject]) + 1) as step: - - sorted_media_handles = sorted(self.report.obj_dict[MediaObject].keys(), - key=lambda x: SORT_KEY(self.report.database.get_object_from_handle(x).desc)) - self.MediaListPage(self.report, title, sorted_media_handles) + len(self.report.obj_dict[MediaObject]) + 1) + + sorted_media_handles = sorted(self.report.obj_dict[MediaObject].keys(), + key=lambda x: SORT_KEY(self.report.database.get_object_from_handle(x).desc)) + self.MediaListPage(self.report, title, sorted_media_handles) - prev = None - total = len(sorted_media_handles) - index = 1 - for handle in sorted_media_handles: - gc.collect() # Reduce memory usage when there are many images. - next = None if index == total else sorted_media_handles[index] - step() - self.MediaPage(self.report, title, handle, (prev, next, index, total)) - prev = handle - index += 1 + prev = None + total = len(sorted_media_handles) + index = 1 + for handle in sorted_media_handles: + gc.collect() # Reduce memory usage when there are many images. + next = None if index == total else sorted_media_handles[index] + self.report.user.step_progress() + self.MediaPage(self.report, title, handle, (prev, next, index, total)) + prev = handle + index += 1 + self.report.user.end_progress() def MediaListPage(self, report, title, sorted_media_handles): """ @@ -5160,15 +5165,16 @@ class PersonPages(BasePage): log.debug("obj_dict[Person]") for item in self.report.obj_dict[Person].items(): log.debug(" %s" % str(item)) - with self.report.user.progress(_("Narrated Web Site Report"), + self.report.user.begin_progress(_("Narrated Web Site Report"), _('Creating individual pages'), - len(self.report.obj_dict[Person]) + 1) as step: - self.IndividualListPage(self.report, title, - self.report.obj_dict[Person].keys()) - for person_handle in self.report.obj_dict[Person]: - step() - person = self.report.database.get_person_from_handle(person_handle) - self.IndividualPage(self.report, title, person) + len(self.report.obj_dict[Person]) + 1) + self.IndividualListPage(self.report, title, + self.report.obj_dict[Person].keys()) + for person_handle in self.report.obj_dict[Person]: + self.report.user.step_progress() + person = self.report.database.get_person_from_handle(person_handle) + self.IndividualPage(self.report, title, person) + self.report.user.end_progress() ################################################# # @@ -6522,26 +6528,27 @@ class RepositoryPages(BasePage): log.debug(" %s" % str(item)) # set progress bar pass for Repositories - with self.report.user.progress(_("Narrated Web Site Report"), + self.report.user.begin_progress(_("Narrated Web Site Report"), _('Creating repository pages'), - len(self.report.obj_dict[Repository]) + 1) as step: - # Sort the repositories - repos_dict = {} - for repository_handle in self.report.obj_dict[Repository]: - repository = self.report.database.get_repository_from_handle(repository_handle) - key = repository.get_name() + str(repository.get_gramps_id()) - repos_dict[key] = (repository, repository_handle) - - keys = sorted(repos_dict, key = SORT_KEY) + len(self.report.obj_dict[Repository]) + 1) + # Sort the repositories + repos_dict = {} + for repository_handle in self.report.obj_dict[Repository]: + repository = self.report.database.get_repository_from_handle(repository_handle) + key = repository.get_name() + str(repository.get_gramps_id()) + repos_dict[key] = (repository, repository_handle) + + keys = sorted(repos_dict, key = SORT_KEY) - # RepositoryListPage Class - self.RepositoryListPage(self.report, title, repos_dict, keys) + # RepositoryListPage Class + self.RepositoryListPage(self.report, title, repos_dict, keys) - for index, key in enumerate(keys): - (repo, handle) = repos_dict[key] + for index, key in enumerate(keys): + (repo, handle) = repos_dict[key] - step() - self.RepositoryPage(self.report, title, repo, handle) + self.report.user.step_progress() + self.RepositoryPage(self.report, title, repo, handle) + self.report.user.end_progress() def RepositoryListPage(self, report, title, repos_dict, keys): self.dbase_ = report.database @@ -7138,22 +7145,24 @@ class NavWebReport(Report): self.obj_dict[obj_class] = defaultdict(set) ind_list = self.database.iter_person_handles() - with self.user.progress(_("Narrated Web Site Report"), + self.user.begin_progress(_("Narrated Web Site Report"), _('Applying Person Filter...'), - self.database.get_number_of_people()) as step: - ind_list = self.filter.apply(self.database, ind_list, - step) + self.database.get_number_of_people()) + ind_list = self.filter.apply(self.database, ind_list, + self.user.step_progress) + self.user.end_progress() - with self.user.progress(_("Narrated Web Site Report"), + self.user.begin_progress(_("Narrated Web Site Report"), _('Constructing list of other objects...'), - sum(1 for _ in ind_list)) as step: - for handle in ind_list: - # FIXME work around bug that self.database.iter under python 3 - # returns (binary) data rather than text - if not isinstance(handle, UNITYPE): - handle = handle.decode('utf-8') - step() - self._add_person(handle, "", "") + sum(1 for _ in ind_list)) + for handle in ind_list: + # FIXME work around bug that self.database.iter under python 3 + # returns (binary) data rather than text + if not isinstance(handle, UNITYPE): + handle = handle.decode('utf-8') + self.user.step_progress() + self._add_person(handle, "", "") + self.user.end_progress() log.debug("final object dictionary \n" + "".join(("%s: %s\n" % item) for item in self.obj_dict.items())) @@ -7562,18 +7571,19 @@ class NavWebReport(Report): def build_gendex(self, ind_list): if self.inc_gendex: - with self.user.progress(_("Narrated Web Site Report"), - _('Creating GENDEX file'), len(ind_list)) as step: - fp_gendex, gendex_io = self.create_file("gendex", ext=".txt") - for person_handle in ind_list: - step() - person = self.database.get_person_from_handle(person_handle) + self.user.begin_progress(_("Narrated Web Site Report"), + _('Creating GENDEX file'), len(ind_list)) + fp_gendex, gendex_io = self.create_file("gendex", ext=".txt") + for person_handle in ind_list: + self.user.step_progress() + person = self.database.get_person_from_handle(person_handle) + self.write_gendex(fp_gendex, person) + if self.archive: + self.write_gendex(gendex_io, person) + else: self.write_gendex(fp_gendex, person) - if self.archive: - self.write_gendex(gendex_io, person) - else: - self.write_gendex(fp_gendex, person) - self.close_file(fp_gendex, gendex_io) + self.close_file(fp_gendex, gendex_io) + self.user.end_progress() def write_gendex(self, fp, person): """ @@ -7606,27 +7616,29 @@ class NavWebReport(Report): """ local_list = sort_people(self.database, ind_list) - with self.user.progress(_("Narrated Web Site Report"), - _("Creating surname pages"), len(local_list)) as step: + self.user.begin_progress(_("Narrated Web Site Report"), + _("Creating surname pages"), len(local_list)) - SurnameListPage(self, self.title, ind_list, SurnameListPage.ORDER_BY_NAME, - self.surname_fname) + SurnameListPage(self, self.title, ind_list, SurnameListPage.ORDER_BY_NAME, + self.surname_fname) - SurnameListPage(self, self.title, ind_list, SurnameListPage.ORDER_BY_COUNT, - "surnames_count") + SurnameListPage(self, self.title, ind_list, SurnameListPage.ORDER_BY_COUNT, + "surnames_count") - for (surname, handle_list) in local_list: - SurnamePage(self, self.title, surname, handle_list) - step() + for (surname, handle_list) in local_list: + SurnamePage(self, self.title, surname, handle_list) + self.user.step_progress() + self.user.end_progress() def thumbnail_preview_page(self): """ creates the thumbnail preview page """ - with self.user.progress(_("Narrated Web Site Report"), + self.user.begin_progress(_("Narrated Web Site Report"), _("Creating thumbnail preview page..."), - len(self.obj_dict[MediaObject])) as step: - ThumbnailPreviewPage(self, self.title, step) + len(self.obj_dict[MediaObject])) + ThumbnailPreviewPage(self, self.title, self.user.step_progress) + self.user.end_progress() def addressbook_pages(self, ind_list): """ @@ -7664,12 +7676,13 @@ class NavWebReport(Report): # begin Address Book pages addr_size = len(url_addr_res) - with self.user.progress(_("Narrated Web Site Report"), + self.user.begin_progress(_("Narrated Web Site Report"), _("Creating address book pages ..."), - addr_size) as step: - for (sort_name, person_handle, add, res, url) in url_addr_res: - AddressBookPage(self, self.title, person_handle, add, res, url) - step() + addr_size) + for (sort_name, person_handle, add, res, url) in url_addr_res: + AddressBookPage(self, self.title, person_handle, add, res, url) + self.user.step_progress() + self.user.end_progress() def base_pages(self): """ diff --git a/gramps/plugins/webreport/webcal.py b/gramps/plugins/webreport/webcal.py index 1a72caa96..f40506613 100644 --- a/gramps/plugins/webreport/webcal.py +++ b/gramps/plugins/webreport/webcal.py @@ -296,20 +296,21 @@ class WebCalReport(Report): def __get_holidays(self, year): # _('translation') - with self._user.progress(_("Web Calendar Report"), + self._user.begin_progress(_("Web Calendar Report"), (_('Calculating Holidays for year %04d') % year), - 365) as step: + 365) - """ Get the holidays for the specified country and year """ - holiday_table = libholiday.HolidayTable() - country = holiday_table.get_countries()[self.country] - holiday_table.load_holidays(year, country) - for month in range(1, 13): - for day in range(1, 32): - holiday_names = holiday_table.get_holidays(month, day) - for holiday_name in holiday_names: - self.add_day_item(holiday_name, year, month, day, 'Holiday') - step() + """ Get the holidays for the specified country and year """ + holiday_table = libholiday.HolidayTable() + country = holiday_table.get_countries()[self.country] + holiday_table.load_holidays(year, country) + for month in range(1, 13): + for day in range(1, 32): + holiday_names = holiday_table.get_holidays(month, day) + for holiday_name in holiday_names: + self.add_day_item(holiday_name, year, month, day, 'Holiday') + self._user.step_progress() + self._user.end_progress() def copy_calendar_files(self): """ @@ -838,58 +839,59 @@ class WebCalReport(Report): nr_up = 1 # Number of directory levels up to get to self.html_dir / root - with self._user.progress(_("Web Calendar Report"), - _('Formatting months ...'), 12) as step: + self._user.begin_progress(_("Web Calendar Report"), + _('Formatting months ...'), 12) - for month in range(1, 13): - cal_fname = _dd.long_months[month] - of = self.create_file(cal_fname, str(year)) + for month in range(1, 13): + cal_fname = _dd.long_months[month] + of = self.create_file(cal_fname, str(year)) - # Add xml, doctype, meta and stylesheets - # body has already been added to webcal already once - webcal, body = self.write_header(nr_up, self.title_text) + # Add xml, doctype, meta and stylesheets + # body has already been added to webcal already once + webcal, body = self.write_header(nr_up, self.title_text) - # create Year Navigation menu - if (self.multiyear and ((self.end_year - self.start_year) > 0)): - body += self.year_navigation(nr_up, str(year)) + # create Year Navigation menu + if (self.multiyear and ((self.end_year - self.start_year) > 0)): + body += self.year_navigation(nr_up, str(year)) - # Create Month Navigation Menu - # identify currentsection for proper highlighting - currentsection = _dd.long_months[month] - body += self.month_navigation(nr_up, year, currentsection, True) + # Create Month Navigation Menu + # identify currentsection for proper highlighting + currentsection = _dd.long_months[month] + body += self.month_navigation(nr_up, year, currentsection, True) - # build the calendar - content = Html("div", class_="content", id = "WebCal") - body += content - monthly_calendar = self.calendar_build("wc", year, month) - content += monthly_calendar + # build the calendar + content = Html("div", class_="content", id = "WebCal") + body += content + monthly_calendar = self.calendar_build("wc", year, month) + content += monthly_calendar - # create note section for webcalendar() - # One has to be minused because the array starts at zero, but January =1 - note = self.month_notes[month-1].strip() - if note: - note = self.database.get_note_from_gramps_id(note) - note = self.get_note_format(note) + # create note section for webcalendar() + # One has to be minused because the array starts at zero, but January =1 + note = self.month_notes[month-1].strip() + if note: + note = self.database.get_note_from_gramps_id(note) + note = self.get_note_format(note) - # table foot section - cal_foot = Html("tfoot") - monthly_calendar += cal_foot + # table foot section + cal_foot = Html("tfoot") + monthly_calendar += cal_foot - trow = Html("tr") + ( - Html("td", note, colspan=7, inline = True) - ) - cal_foot += trow + trow = Html("tr") + ( + Html("td", note, colspan=7, inline = True) + ) + cal_foot += trow - # create blank line for stylesheets - # create footer division section - footer = self.write_footer(nr_up) - body += (fullclear, footer) + # create blank line for stylesheets + # create footer division section + footer = self.write_footer(nr_up) + body += (fullclear, footer) - # send calendar page to web output - # and close the file - self.XHTMLWriter(webcal, of) + # send calendar page to web output + # and close the file + self.XHTMLWriter(webcal, of) - step() + self._user.step_progress() + self._user.end_progress() def year_glance(self, year): """ @@ -900,54 +902,55 @@ class WebCalReport(Report): nr_up = 1 # Number of directory levels up to get to root # generate progress pass for "Year At A Glance" - with self._user.progress(_("Web Calendar Report"), - _('Creating Year At A Glance calendar'), 12) as step: + self._user.begin_progress(_("Web Calendar Report"), + _('Creating Year At A Glance calendar'), 12) - of = self.create_file('fullyearlinked', str(year)) + of = self.create_file('fullyearlinked', str(year)) - # page title - title = _("%(year)d, At A Glance") % {'year' : year} + # page title + title = _("%(year)d, At A Glance") % {'year' : year} - # Create page header - # body has already been added to yearglance already once - yearglance, body = self.write_header(nr_up, title, "fullyearlinked", False) + # Create page header + # body has already been added to yearglance already once + yearglance, body = self.write_header(nr_up, title, "fullyearlinked", False) - # create Year Navigation menu - if (self.multiyear and ((self.end_year - self.start_year) > 0)): - body += self.year_navigation(nr_up, str(year)) + # create Year Navigation menu + if (self.multiyear and ((self.end_year - self.start_year) > 0)): + body += self.year_navigation(nr_up, str(year)) - # Create Month Navigation Menu - # identify currentsection for proper highlighting - body += self.month_navigation(nr_up, year, "fullyearlinked", True) + # Create Month Navigation Menu + # identify currentsection for proper highlighting + body += self.month_navigation(nr_up, year, "fullyearlinked", True) - msg = (_('This calendar is meant to give you access ' - 'to all your data at a glance compressed into one page. Clicking ' - 'on a date will take you to a page that shows all the events for ' - 'that date, if there are any.\n')) + msg = (_('This calendar is meant to give you access ' + 'to all your data at a glance compressed into one page. Clicking ' + 'on a date will take you to a page that shows all the events for ' + 'that date, if there are any.\n')) - # page description - content = Html("div", class_ = "content", id = "YearGlance") - body += content + # page description + content = Html("div", class_ = "content", id = "YearGlance") + body += content - content += Html("p", msg, id='description') + content += Html("p", msg, id='description') - for month in range(1, 13): + for month in range(1, 13): - # build the calendar - monthly_calendar = self.calendar_build("yg", year, month) - content += monthly_calendar + # build the calendar + monthly_calendar = self.calendar_build("yg", year, month) + content += monthly_calendar - # increase progress bar - step() + # increase progress bar + self._user.step_progress() - # create blank line for stylesheets - # write footer section - footer = self.write_footer(nr_up) - body += (fullclear, footer) + # create blank line for stylesheets + # write footer section + footer = self.write_footer(nr_up) + body += (fullclear, footer) - # send calendar page to web output - # and close the file - self.XHTMLWriter(yearglance, of) + # send calendar page to web output + # and close the file + self.XHTMLWriter(yearglance, of) + self._user.end_progress() def one_day(self, event_date, fname_date, day_list): """ @@ -1080,112 +1083,114 @@ class WebCalReport(Report): db = self.database people = db.iter_person_handles() - with self._user.progress(_("Web Calendar Report"), + self._user.begin_progress(_("Web Calendar Report"), _('Applying Filter...'), - db.get_number_of_people()) as step: - people = self.filter.apply(db, people, step_progress) + db.get_number_of_people()) + people = self.filter.apply(db, people, self._user.step_progress) + self._user.end_progress() - with self._user.progress(_("Web Calendar Report"), - _("Reading database..."), len(people)) as step: - for person in map(db.get_person_from_handle, people): - step() + self._user.begin_progress(_("Web Calendar Report"), + _("Reading database..."), len(people)) + for person in map(db.get_person_from_handle, people): + self._user.step_progress() - family_list = person.get_family_handle_list() - birth_ref = person.get_birth_ref() - birth_date = Date.EMPTY - if birth_ref: - birth_event = db.get_event_from_handle(birth_ref.ref) - birth_date = birth_event.get_date_object() + family_list = person.get_family_handle_list() + birth_ref = person.get_birth_ref() + birth_date = Date.EMPTY + if birth_ref: + birth_event = db.get_event_from_handle(birth_ref.ref) + birth_date = birth_event.get_date_object() - # determine birthday information??? - if (self.birthday and birth_date is not Date.EMPTY and birth_date.is_valid()): + # determine birthday information??? + if (self.birthday and birth_date is not Date.EMPTY and birth_date.is_valid()): - year = birth_date.get_year() or this_year - month = birth_date.get_month() - day = birth_date.get_day() + year = birth_date.get_year() or this_year + month = birth_date.get_month() + day = birth_date.get_day() - # date to figure if someone is still alive - # current year of calendar, month nd day is their birth month and birth day - prob_alive_date = Date(this_year, month, day) + # date to figure if someone is still alive + # current year of calendar, month nd day is their birth month and birth day + prob_alive_date = Date(this_year, month, day) - # add some things to handle maiden name: - father_surname = None # husband, actually - if person.gender == Person.FEMALE: + # add some things to handle maiden name: + father_surname = None # husband, actually + if person.gender == Person.FEMALE: - # get husband's last name: - if self.maiden_name in ['spouse_first', 'spouse_last']: - if family_list: - if self.maiden_name == 'spouse_first': - fhandle = family_list[0] - else: - fhandle = family_list[-1] - fam = db.get_family_from_handle(fhandle) - father_handle = fam.get_father_handle() - mother_handle = fam.get_mother_handle() - if mother_handle == person.handle: - if father_handle: - father = db.get_person_from_handle(father_handle) - if father is not None: - father_surname = _get_regular_surname(person.gender, - father.get_primary_name()) - short_name = self.get_name(person, father_surname) - alive = probably_alive(person, db, prob_alive_date) - if (self.alive and alive) or not self.alive: + # get husband's last name: + if self.maiden_name in ['spouse_first', 'spouse_last']: + if family_list: + if self.maiden_name == 'spouse_first': + fhandle = family_list[0] + else: + fhandle = family_list[-1] + fam = db.get_family_from_handle(fhandle) + father_handle = fam.get_father_handle() + mother_handle = fam.get_mother_handle() + if mother_handle == person.handle: + if father_handle: + father = db.get_person_from_handle(father_handle) + if father is not None: + father_surname = _get_regular_surname(person.gender, + father.get_primary_name()) + short_name = self.get_name(person, father_surname) + alive = probably_alive(person, db, prob_alive_date) + if (self.alive and alive) or not self.alive: - # add link to NarrativeWeb - if self.link_to_narweb: - text = str(Html("a", short_name, - href = self.build_url_fname_html(person.handle, "ppl", - prefix = self.narweb_prefix))) - else: - text = short_name - self.add_day_item(text, year, month, day, 'Birthday') + # add link to NarrativeWeb + if self.link_to_narweb: + text = str(Html("a", short_name, + href = self.build_url_fname_html(person.handle, "ppl", + prefix = self.narweb_prefix))) + else: + text = short_name + self.add_day_item(text, year, month, day, 'Birthday') - # add anniversary if requested - if self.anniv: - for fhandle in family_list: - fam = db.get_family_from_handle(fhandle) - father_handle = fam.get_father_handle() - mother_handle = fam.get_mother_handle() - if father_handle == person.handle: - spouse_handle = mother_handle - else: - continue # with next person if this was the marriage event - if spouse_handle: - spouse = db.get_person_from_handle(spouse_handle) - if spouse: - spouse_name = self.get_name(spouse) - short_name = self.get_name(person) + # add anniversary if requested + if self.anniv: + for fhandle in family_list: + fam = db.get_family_from_handle(fhandle) + father_handle = fam.get_father_handle() + mother_handle = fam.get_mother_handle() + if father_handle == person.handle: + spouse_handle = mother_handle + else: + continue # with next person if this was the marriage event + if spouse_handle: + spouse = db.get_person_from_handle(spouse_handle) + if spouse: + spouse_name = self.get_name(spouse) + short_name = self.get_name(person) - # will return a marriage event or False if not married any longer - marriage_event = get_marriage_event(db, fam) - if marriage_event: - event_date = marriage_event.get_date_object() - if event_date is not Date.EMPTY and event_date.is_valid(): - year = event_date.get_year() - month = event_date.get_month() - day = event_date.get_day() + # will return a marriage event or False if not married any longer + marriage_event = get_marriage_event(db, fam) + if marriage_event: + event_date = marriage_event.get_date_object() + if event_date is not Date.EMPTY and event_date.is_valid(): + year = event_date.get_year() + month = event_date.get_month() + day = event_date.get_day() - # date to figure if someone is still alive - prob_alive_date = Date(this_year, month, day) + # date to figure if someone is still alive + prob_alive_date = Date(this_year, month, day) - if self.link_to_narweb: - spouse_name = str(Html("a", spouse_name, - href = self.build_url_fname_html(spouse_handle, 'ppl', - prefix = self.narweb_prefix))) - short_name = str(Html("a", short_name, - href = self.build_url_fname_html(person.handle, 'ppl', - prefix = self.narweb_prefix))) - - alive1 = probably_alive(person, db, prob_alive_date) - alive2 = probably_alive(spouse, db, prob_alive_date) - if ((self.alive and alive1 and alive2) or not self.alive): + if self.link_to_narweb: + spouse_name = str(Html("a", spouse_name, + href = self.build_url_fname_html(spouse_handle, 'ppl', + prefix = self.narweb_prefix))) + short_name = str(Html("a", short_name, + href = self.build_url_fname_html(person.handle, 'ppl', + prefix = self.narweb_prefix))) + + alive1 = probably_alive(person, db, prob_alive_date) + alive2 = probably_alive(spouse, db, prob_alive_date) + if ((self.alive and alive1 and alive2) or not self.alive): - text = _('%(spouse)s and %(person)s') % { - 'spouse' : spouse_name, - 'person' : short_name} + text = _('%(spouse)s and %(person)s') % { + 'spouse' : spouse_name, + 'person' : short_name} - self.add_day_item(text, year, month, day, 'Anniversary') + self.add_day_item(text, year, month, day, 'Anniversary') + self._user.end_progress() def write_footer(self, nr_up): """