Revert*2 "5098: refactor code to use User.progress

Revert*2 means re-apply :-)

svn: r23102
This commit is contained in:
Vassilii Khachaturov 2013-09-12 21:22:14 +00:00
parent 0b936041d3
commit 6c6ca1cd20
9 changed files with 741 additions and 778 deletions

View File

@ -137,42 +137,41 @@ def diff_dbs(db1, db2, user=None):
missing_from_old = []
missing_from_new = []
diffs = []
user.begin_progress(_('Family Tree Differences'),
_('Searching...'), 10)
for item in ['Person', 'Family', 'Source', 'Citation', 'Event', 'Media',
'Place', 'Repository', 'Note', 'Tag']:
user.step_progress()
handles1 = sorted(db1._tables[item]["handles_func"]())
handles2 = sorted(db2._tables[item]["handles_func"]())
p1 = 0
p2 = 0
while p1 < len(handles1) and p2 < len(handles2):
if handles1[p1] == handles2[p2]: # in both
item1 = db1._tables[item]["handle_func"](handles1[p1])
item2 = db2._tables[item]["handle_func"](handles2[p2])
diff = diff_items(item, item1.to_struct(), item2.to_struct())
if diff:
diffs += [(item, item1, item2)]
# else same!
p1 += 1
p2 += 1
elif handles1[p1] < handles2[p2]: # p1 is mssing in p2
with user.progress(_('Family Tree Differences'),
_('Searching...'), 10) as step:
for item in ['Person', 'Family', 'Source', 'Citation', 'Event', 'Media',
'Place', 'Repository', 'Note', 'Tag']:
step()
handles1 = sorted(db1._tables[item]["handles_func"]())
handles2 = sorted(db2._tables[item]["handles_func"]())
p1 = 0
p2 = 0
while p1 < len(handles1) and p2 < len(handles2):
if handles1[p1] == handles2[p2]: # in both
item1 = db1._tables[item]["handle_func"](handles1[p1])
item2 = db2._tables[item]["handle_func"](handles2[p2])
diff = diff_items(item, item1.to_struct(), item2.to_struct())
if diff:
diffs += [(item, item1, item2)]
# else same!
p1 += 1
p2 += 1
elif handles1[p1] < handles2[p2]: # p1 is mssing in p2
item1 = db1._tables[item]["handle_func"](handles1[p1])
missing_from_new += [(item, item1)]
p1 += 1
elif handles1[p1] > handles2[p2]: # p2 is mssing in p1
item2 = db2._tables[item]["handle_func"](handles2[p2])
missing_from_old += [(item, item2)]
p2 += 1
while p1 < len(handles1):
item1 = db1._tables[item]["handle_func"](handles1[p1])
missing_from_new += [(item, item1)]
p1 += 1
elif handles1[p1] > handles2[p2]: # p2 is mssing in p1
while p2 < len(handles2):
item2 = db2._tables[item]["handle_func"](handles2[p2])
missing_from_old += [(item, item2)]
p2 += 1
while p1 < len(handles1):
item1 = db1._tables[item]["handle_func"](handles1[p1])
missing_from_new += [(item, item1)]
p1 += 1
while p2 < len(handles2):
item2 = db2._tables[item]["handle_func"](handles2[p2])
missing_from_old += [(item, item2)]
p2 += 1
user.end_progress()
return diffs, missing_from_old, missing_from_new
def diff_db_to_file(old_db, filename, user=None):

View File

@ -707,61 +707,59 @@ 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')
self._user.begin_progress(_('Ancestor Tree'),
_('Making the Tree...'), 4)
with self._user.progress(_('Ancestor Tree'),
_('Making the Tree...'), 4) as step:
#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
self._user.step_progress()
step()
#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
self._user.step_progress()
step()
#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)
self._user.step_progress()
scale = self.canvas.scale_report(one_page,
scale_report != 0, scale_report == 2)
step()
if scale != 1 or self.connect.get_val('shadowscale') != 1.0:
self.scale_styles(scale)
self._user.end_progress()
if scale != 1 or self.connect.get_val('shadowscale') != 1.0:
self.scale_styles(scale)
def write_report(self):
@ -796,29 +794,26 @@ class AncestorTree(Report):
#lets finally make some pages!!!
#####################
pages = self.canvas.page_count(incblank)
self._user.begin_progress( _('Ancestor Tree'),
_('Printing the Tree...'), pages)
with self._user.progress( _('Ancestor Tree'),
_('Printing the Tree...'), pages) as step:
for page in self.canvas.page_iter_gen(incblank):
for page in self.canvas.page_iter_gen(incblank):
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()
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()
step()
self.doc.end_page()
def scale_styles(self, scale):
"""

View File

@ -165,12 +165,11 @@ class Calendar(Report):
# get data from database:
self.collect_data()
# generate the report:
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()
with self._user.progress( _('Calendar Report'),
_('Formatting months...'), 12) as step:
for month in range(1, 13):
step()
self.print_page(month)
def print_page(self, month):
"""
@ -268,134 +267,131 @@ class Calendar(Report):
"""
db = self.database
people = db.iter_person_handles()
self._user.begin_progress(_('Calendar Report'),
with self._user.progress(_('Calendar Report'),
_('Applying Filter...'),
db.get_number_of_people())
people = self.filter.apply(self.database, people,
self._user.step_progress)
self._user.end_progress()
db.get_number_of_people()) as step:
people = self.filter.apply(self.database, people, step)
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()
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()
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
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:
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)
event_obj = event.get_date_object()
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()
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])
self._user.end_progress()
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])
#------------------------------------------------------------------------
#

View File

@ -123,13 +123,12 @@ class TimeLine(Report):
def write_report(self):
# Apply the filter
self._user.begin_progress(_('Timeline'),
with self._user.progress(_('Timeline'),
_('Applying filter...'),
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()
self.database.get_number_of_people()) as step:
self.plist = self.filter.apply(self.database,
self.database.iter_person_handles(),
step)
# Find the range of dates to include
(low, high) = self.find_year_range()
@ -150,9 +149,8 @@ class TimeLine(Report):
self.header = 2.0
# Sort the people as requested
self._user.begin_progress(_('Timeline'), _('Sorting dates...'), 0)
self.plist.sort(key=self.sort_func)
self._user.end_progress()
with self._user.progress(_('Timeline'), _('Sorting dates...'), 0) as step:
self.plist.sort(key=self.sort_func)
self.doc.start_page()
self.build_grid(low, high, start, stop, True)
@ -162,66 +160,65 @@ class TimeLine(Report):
length = len(self.plist)
self._user.begin_progress(_('Timeline'),
_('Calculating timeline...'), length)
with self._user.progress(_('Timeline'),
_('Calculating timeline...'), length) as step:
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
self._user.step_progress()
self.doc.end_page()
self._user.end_progress()
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()
def build_grid(self, year_low, year_high, start_pos, stop_pos, toc=False):
"""
@ -343,40 +340,39 @@ class TimeLine(Report):
high = year
return (low, high)
self._user.begin_progress(_('Timeline'),
with self._user.progress(_('Timeline'),
_('Finding date range...'),
len(self.plist))
len(self.plist)) as step:
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)
self._user.step_progress()
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()
# round the dates to the nearest decade
if low is not None:
low = int((low/10))*10
else:
low = high
# 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)
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):

View File

@ -324,30 +324,29 @@ class CSVParser(object):
:param filehandle: open file handle positioned at start of the file
"""
data = self.read_csv(filehandle)
progress_title = _('CSV Import')
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,
_('Reading data...'), 1) as step:
data = self.read_csv(filehandle)
def _parse_csv_data(self, data):
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):
"""Parse each line of the input data and act accordingly."""
self.lineno = 0
self.index = 0
@ -358,7 +357,7 @@ class CSVParser(object):
header = None
line_number = 0
for row in data:
self.user.step_progress()
step()
line_number += 1
if "".join(row) == "": # no blanks are allowed inside a table
header = None # clear headers, ready for next "table"

View File

@ -216,12 +216,11 @@ class BirthdayReport(Report):
self.doc.write_text(self._("Relationships shown are to %s") %
self._name_display.display_name(name), mark)
self.doc.end_paragraph()
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()
with self._user.progress(_('Birthday and Anniversary Report'),
_('Formatting months...'), 12) as step:
for month in range(1, 13):
step()
self.print_page(month)
def print_page(self, month):
""" Prints a month as a page """
@ -256,141 +255,139 @@ class BirthdayReport(Report):
and text.
"""
people = self.database.iter_person_handles()
self._user.begin_progress(_('Birthday and Anniversary Report'),
with self._user.progress(_('Birthday and Anniversary Report'),
_('Applying Filter...'),
self.database.get_number_of_people())
people = self.filter.apply(self.database, people,
self._user.step_progress)
self._user.end_progress()
self.database.get_number_of_people()) as step:
people = self.filter.apply(self.database, people,
step)
rel_calc = get_relationship_calculator(reinit=True,
clocale=self._locale)
ngettext = self._locale.translation.ngettext
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()
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()
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
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:
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)
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.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
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()
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)
#------------------------------------------------------------------------
#

View File

@ -126,23 +126,22 @@ class PlaceReport(Report):
"""
place_nbr = 1
self._user.begin_progress(_("Place Report"),
with self._user.progress(_("Place Report"),
_("Generating report"),
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()
len(self.place_handles)) as step:
self._user.end_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()
def __write_place(self, handle, place_nbr):
"""

View File

@ -3037,16 +3037,15 @@ class FamilyPages(BasePage):
for item in self.report.obj_dict[Family].items():
log.debug(" %s" % str(item))
self.report.user.begin_progress(_("Narrated Web Site Report"),
with self.report.user.progress(_("Narrated Web Site Report"),
_("Creating family pages..."),
len(self.report.obj_dict[Family]) + 1)
self.FamilyListPage(self.report, title,
self.report.obj_dict[Family].keys())
len(self.report.obj_dict[Family]) + 1) as step:
self.FamilyListPage(self.report, title,
self.report.obj_dict[Family].keys())
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()
for family_handle in self.report.obj_dict[Family]:
step()
self.FamilyPage(self.report, title, family_handle)
def FamilyListPage(self, report, title, fam_list):
self.dbase_ = report.database
@ -3314,17 +3313,16 @@ class PlacePages(BasePage):
log.debug("obj_dict[Place]")
for item in self.report.obj_dict[Place].items():
log.debug(" %s" % str(item))
self.report.user.begin_progress(_("Narrated Web Site Report"),
with self.report.user.progress(_("Narrated Web Site Report"),
_("Creating place pages"),
len(self.report.obj_dict[Place]) + 1)
len(self.report.obj_dict[Place]) + 1) as step:
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]:
self.report.user.step_progress()
self.PlacePage(self.report, title, place_handle)
self.report.user.end_progress()
for place_handle in self.report.obj_dict[Place]:
step()
self.PlacePage(self.report, title, place_handle)
pass
def PlaceListPage(self, report, title, place_handles):
@ -3598,16 +3596,15 @@ 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()))
self.report.user.begin_progress(_("Narrated Web Site Report"),
with self.report.user.progress(_("Narrated Web Site Report"),
_("Creating event pages"),
len(event_handle_list) + 1)
self.EventListPage(self.report, title, event_types, event_handle_list)
len(event_handle_list) + 1) as step:
self.EventListPage(self.report, title, event_types, event_handle_list)
for event_handle in event_handle_list:
self.report.user.step_progress()
self.EventPage(self.report, title, event_handle)
for event_handle in event_handle_list:
step()
self.EventPage(self.report, title, event_handle)
self.report.user.end_progress()
def EventListPage(self, report, title, event_types, event_handle_list):
"""
@ -4143,17 +4140,16 @@ class SourcePages(BasePage):
log.debug("obj_dict[Source]")
for item in self.report.obj_dict[Source].items():
log.debug(" %s" % str(item))
self.report.user.begin_progress(_("Narrated Web Site Report"),
with self.report.user.progress(_("Narrated Web Site Report"),
_("Creating source pages"),
len(self.report.obj_dict[Source]) + 1)
self.SourceListPage(self.report, title,
self.report.obj_dict[Source].keys())
len(self.report.obj_dict[Source]) + 1) as step:
self.SourceListPage(self.report, title,
self.report.obj_dict[Source].keys())
for source_handle in self.report.obj_dict[Source]:
self.report.user.step_progress()
self.SourcePage(self.report, title, source_handle)
for source_handle in self.report.obj_dict[Source]:
step()
self.SourcePage(self.report, title, source_handle)
self.report.user.end_progress()
def SourceListPage(self, report, title, source_handles):
"""
@ -4358,25 +4354,24 @@ class MediaPages(BasePage):
log.debug("obj_dict[Media]")
for item in self.report.obj_dict[MediaObject].items():
log.debug(" %s" % str(item))
self.report.user.begin_progress(_("Narrated Web Site Report"),
with self.report.user.progress(_("Narrated Web Site Report"),
_("Creating media pages"),
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)
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)
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()
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
def MediaListPage(self, report, title, sorted_media_handles):
"""
@ -5157,16 +5152,15 @@ class PersonPages(BasePage):
log.debug("obj_dict[Person]")
for item in self.report.obj_dict[Person].items():
log.debug(" %s" % str(item))
self.report.user.begin_progress(_("Narrated Web Site Report"),
with self.report.user.progress(_("Narrated Web Site Report"),
_('Creating individual pages'),
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()
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)
#################################################
#
@ -6520,27 +6514,26 @@ class RepositoryPages(BasePage):
log.debug(" %s" % str(item))
# set progress bar pass for Repositories
self.report.user.begin_progress(_("Narrated Web Site Report"),
with self.report.user.progress(_("Narrated Web Site Report"),
_('Creating repository pages'),
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)
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)
# 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]
self.report.user.step_progress()
self.RepositoryPage(self.report, title, repo, handle)
self.report.user.end_progress()
step()
self.RepositoryPage(self.report, title, repo, handle)
def RepositoryListPage(self, report, title, repos_dict, keys):
self.dbase_ = report.database
@ -7137,24 +7130,22 @@ class NavWebReport(Report):
self.obj_dict[obj_class] = defaultdict(set)
ind_list = self.database.iter_person_handles()
self.user.begin_progress(_("Narrated Web Site Report"),
with self.user.progress(_("Narrated Web Site Report"),
_('Applying Person Filter...'),
self.database.get_number_of_people())
ind_list = self.filter.apply(self.database, ind_list,
self.user.step_progress)
self.user.end_progress()
self.database.get_number_of_people()) as step:
ind_list = self.filter.apply(self.database, ind_list,
step)
self.user.begin_progress(_("Narrated Web Site Report"),
with self.user.progress(_("Narrated Web Site Report"),
_('Constructing list of other objects...'),
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()
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, "", "")
log.debug("final object dictionary \n" +
"".join(("%s: %s\n" % item) for item in self.obj_dict.items()))
@ -7563,19 +7554,18 @@ class NavWebReport(Report):
def build_gendex(self, ind_list):
if self.inc_gendex:
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:
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.write_gendex(fp_gendex, person)
self.close_file(fp_gendex, gendex_io)
self.user.end_progress()
if self.archive:
self.write_gendex(gendex_io, person)
else:
self.write_gendex(fp_gendex, person)
self.close_file(fp_gendex, gendex_io)
def write_gendex(self, fp, person):
"""
@ -7608,29 +7598,27 @@ class NavWebReport(Report):
"""
local_list = sort_people(self.database, ind_list)
self.user.begin_progress(_("Narrated Web Site Report"),
_("Creating surname pages"), len(local_list))
with self.user.progress(_("Narrated Web Site Report"),
_("Creating surname pages"), len(local_list)) as step:
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)
self.user.step_progress()
self.user.end_progress()
for (surname, handle_list) in local_list:
SurnamePage(self, self.title, surname, handle_list)
step()
def thumbnail_preview_page(self):
"""
creates the thumbnail preview page
"""
self.user.begin_progress(_("Narrated Web Site Report"),
with self.user.progress(_("Narrated Web Site Report"),
_("Creating thumbnail preview page..."),
len(self.obj_dict[MediaObject]))
ThumbnailPreviewPage(self, self.title, self.user.step_progress)
self.user.end_progress()
len(self.obj_dict[MediaObject])) as step:
ThumbnailPreviewPage(self, self.title, step)
def addressbook_pages(self, ind_list):
"""
@ -7668,13 +7656,12 @@ class NavWebReport(Report):
# begin Address Book pages
addr_size = len(url_addr_res)
self.user.begin_progress(_("Narrated Web Site Report"),
with self.user.progress(_("Narrated Web Site Report"),
_("Creating address book pages ..."),
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()
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()
def base_pages(self):
"""

View File

@ -296,21 +296,20 @@ class WebCalReport(Report):
def __get_holidays(self, year):
# _('translation')
self._user.begin_progress(_("Web Calendar Report"),
with self._user.progress(_("Web Calendar Report"),
(_('Calculating Holidays for year %04d') % year),
365)
365) as 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()
""" 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()
def copy_calendar_files(self):
"""
@ -839,59 +838,58 @@ class WebCalReport(Report):
nr_up = 1 # Number of directory levels up to get to self.html_dir / root
self._user.begin_progress(_("Web Calendar Report"),
_('Formatting months ...'), 12)
with self._user.progress(_("Web Calendar Report"),
_('Formatting months ...'), 12) as step:
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)
self._user.step_progress()
self._user.end_progress()
step()
def year_glance(self, year):
"""
@ -902,55 +900,54 @@ class WebCalReport(Report):
nr_up = 1 # Number of directory levels up to get to root
# generate progress pass for "Year At A Glance"
self._user.begin_progress(_("Web Calendar Report"),
_('Creating Year At A Glance calendar'), 12)
with self._user.progress(_("Web Calendar Report"),
_('Creating Year At A Glance calendar'), 12) as step:
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
self._user.step_progress()
# increase progress bar
step()
# 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)
self._user.end_progress()
# send calendar page to web output
# and close the file
self.XHTMLWriter(yearglance, of)
def one_day(self, event_date, fname_date, day_list):
"""
@ -1083,114 +1080,112 @@ class WebCalReport(Report):
db = self.database
people = db.iter_person_handles()
self._user.begin_progress(_("Web Calendar Report"),
with self._user.progress(_("Web Calendar Report"),
_('Applying Filter...'),
db.get_number_of_people())
people = self.filter.apply(db, people, self._user.step_progress)
self._user.end_progress()
db.get_number_of_people()) as step:
people = self.filter.apply(db, people, step_progress)
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()
with self._user.progress(_("Web Calendar Report"),
_("Reading database..."), len(people)) as step:
for person in map(db.get_person_from_handle, people):
step()
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._user.end_progress()
self.add_day_item(text, year, month, day, 'Anniversary')
def write_footer(self, nr_up):
"""