本文整理汇总了Python中gramps.gen.lib.EventRef.set_role方法的典型用法代码示例。如果您正苦于以下问题:Python EventRef.set_role方法的具体用法?Python EventRef.set_role怎么用?Python EventRef.set_role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gramps.gen.lib.EventRef
的用法示例。
在下文中一共展示了EventRef.set_role方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_witness_line
# 需要导入模块: from gramps.gen.lib import EventRef [as 别名]
# 或者: from gramps.gen.lib.EventRef import set_role [as 别名]
def read_witness_line(self,line,fields):
LOG.debug("Witness:")
if fields[1] == "m:":
(idx,wit_p) = self.parse_person(fields,2,Person.MALE,None)
elif fields[1] == "f:":
(idx,wit_p) = self.parse_person(fields,2,Person.FEMALE,None)
else:
(idx,wit_p) = self.parse_person(fields,1,None,None)
if wit_p:
mev = None
# search marriage event
for evr in self.current_family.get_event_ref_list():
ev = self.db.get_event_from_handle(evr.get_reference_handle())
if ev.get_type() == EventType.MARRIAGE:
mev = ev # found.
if not mev: # No marriage event found create a new one
mev = self.create_event(EventType.MARRIAGE, None, None, None, None)
mar_ref = EventRef()
mar_ref.set_reference_handle(mev.get_handle())
self.current_family.add_event_ref(mar_ref)
wit_ref = EventRef()
wit_ref.set_role(EventRoleType(EventRoleType.WITNESS))
wit_ref.set_reference_handle(mev.get_handle())
wit_p.add_event_ref(wit_ref)
self.db.commit_person(wit_p,self.trans)
return None
示例2: save
# 需要导入模块: from gramps.gen.lib import EventRef [as 别名]
# 或者: from gramps.gen.lib.EventRef import set_role [as 别名]
def save(self, trans):
"""
Save the census details to the database.
"""
# Update people on the census
all_people = []
for order, row in enumerate(self.model):
all_people.append(row[0])
person = self.db.get_person_from_handle(row[0])
event_ref = self.get_census_event_ref(person)
if event_ref is None:
# Add new link to census
event_ref = EventRef()
event_ref.ref = self.event.get_handle()
event_ref.set_role(EventRoleType.PRIMARY)
person.add_event_ref(event_ref)
# Write attributes
attrs = event_ref.get_attribute_list()
set_attribute(event_ref, attrs, ORDER_ATTR, str(order + 1))
for offset, name in enumerate(self.columns):
value = row[offset + 1]
if name == _('Name'):
if value != name_displayer.display(person):
set_attribute(event_ref, attrs, name, value)
else:
set_attribute(event_ref, attrs, name, value)
self.db.commit_person(person, trans)
# Remove links to people no longer on census
for handle in (set(self.initial_people) - set(all_people)):
person = self.db.get_person_from_handle(handle)
ref_list = [event_ref for event_ref in person.get_event_ref_list()
if event_ref.ref != self.event.handle]
person.set_event_ref_list(ref_list)
self.db.commit_person(person, trans)
示例3: handle_extra_type
# 需要导入模块: from gramps.gen.lib import EventRef [as 别名]
# 或者: from gramps.gen.lib.EventRef import set_role [as 别名]
def handle_extra_type(self, objtype, obj):
try:
ref = EventRef()
event = self.dbstate.db.get_event_from_handle(obj)
ref.set_role(self.default_role())
self.get_ref_editor()(
self.dbstate, self.uistate, self.track,
event, ref, self.object_added)
except WindowActiveError:
pass
示例4: add_button_clicked
# 需要导入模块: from gramps.gen.lib import EventRef [as 别名]
# 或者: from gramps.gen.lib.EventRef import set_role [as 别名]
def add_button_clicked(self, obj):
try:
ref = EventRef()
event = Event()
ref.set_role(self.default_role())
event.set_type(self.default_type())
self.get_ref_editor()(
self.dbstate, self.uistate, self.track,
event, ref, self.object_added)
except WindowActiveError:
pass
示例5: share_button_clicked
# 需要导入模块: from gramps.gen.lib import EventRef [as 别名]
# 或者: from gramps.gen.lib.EventRef import set_role [as 别名]
def share_button_clicked(self, obj):
SelectEvent = SelectorFactory('Event')
sel = SelectEvent(self.dbstate, self.uistate, self.track)
event = sel.run()
if event:
try:
ref = EventRef()
ref.set_role(self.default_role())
self.get_ref_editor()(
self.dbstate, self.uistate, self.track,
event, ref, self.object_added)
except WindowActiveError:
from ...dialog import WarningDialog
WarningDialog(_("Cannot share this reference"),
self.__blocked_text())
示例6: get_event_ref
# 需要导入模块: from gramps.gen.lib import EventRef [as 别名]
# 或者: from gramps.gen.lib.EventRef import set_role [as 别名]
def get_event_ref(event, obj, role):
"""
Return the event reference for a given person or family that points
to the event being edited.
"""
for event_ref in obj.get_event_ref_list():
if (event_ref.ref == event.get_handle() and
event_ref.get_role() == role):
return event_ref
# Add new event reference
event_ref = EventRef()
event_ref.ref = event.get_handle()
event_ref.set_role(role)
obj.add_event_ref(event_ref)
return event_ref
示例7: parse_marriage
# 需要导入模块: from gramps.gen.lib import EventRef [as 别名]
# 或者: from gramps.gen.lib.EventRef import set_role [as 别名]
def parse_marriage(self,fields,idx):
mariageDataRe = re.compile("^[+#-0-9].*$")
mar_date = None
mar_place = None
mar_source = None
sep_date = None
div_date = None
married = 1
engaged = 0
# skip to marriage date in case person contained unmatches tokens
#Alex: this failed when fields[idx] was an empty line. Fixed.
#while idx < len(fields) and not fields[idx][0] == "+":
while idx < len(fields) and not (fields[idx] and fields[idx][0] == "+"):
if fields[idx]:
LOG.warning(("parse_marriage(): Unknown field: " +
"'%s' in line %d!") % (fields[idx], self.lineno))
idx += 1
while idx < len(fields) and mariageDataRe.match(fields[idx]):
field = fields[idx]
idx += 1
if field.startswith("+"):
field = field[1:]
mar_date = self.parse_date(self.decode(field))
LOG.debug(" Married at: %s" % field)
elif field.startswith("-"):
field = field[1:]
div_date = self.parse_date(self.decode(field))
LOG.debug(" Div at: %s" % field)
elif field == "#mp" and idx < len(fields):
mar_place = self.get_or_create_place(self.decode(fields[idx]))
LOG.debug(" Marriage place: %s" % fields[idx])
idx += 1
elif field == "#ms" and idx < len(fields):
mar_source = self.get_or_create_source(self.decode(fields[idx]))
LOG.debug(" Marriage source: %s" % fields[idx])
idx += 1
elif field == "#sep" and idx < len(fields):
sep_date = self.parse_date(self.decode(fields[idx]))
LOG.debug(" Seperated since: %s" % fields[idx])
idx += 1
elif field == "#nm":
LOG.debug(" Are not married.")
married = 0
elif field == "#noment":
LOG.debug(" Not mentioned.")
elif field == "#eng":
LOG.debug(" Are engaged.")
engaged = 1
else:
LOG.warning(("parse_marriage(): Unknown field " +
"'%s'for mariage in line %d!") % (field, self.lineno))
if mar_date or mar_place or mar_source:
mar = self.create_event(
EventType.MARRIAGE, None, mar_date, mar_place, mar_source)
mar_ref = EventRef()
mar_ref.set_reference_handle(mar.get_handle())
mar_ref.set_role(EventRoleType.FAMILY)
self.current_family.add_event_ref(mar_ref)
self.current_family.set_relationship(
FamilyRelType(FamilyRelType.MARRIED))
if div_date:
div = self.create_event(
EventType.DIVORCE, None, div_date, None, None)
div_ref = EventRef()
div_ref.set_reference_handle(div.get_handle())
div_ref.set_role(EventRoleType.FAMILY)
self.current_family.add_event_ref(div_ref)
if sep_date or engaged:
sep = self.create_event(
EventType.ENGAGEMENT, None, sep_date, None, None)
sep_ref = EventRef()
sep_ref.set_reference_handle(sep.get_handle())
sep_ref.set_role(EventRoleType.FAMILY)
self.current_family.add_event_ref(sep_ref)
if not married:
self.current_family.set_relationship(
FamilyRelType(FamilyRelType.UNMARRIED))
self.db.commit_family(self.current_family,self.trans)
return idx
示例8: _parse_marriage
# 需要导入模块: from gramps.gen.lib import EventRef [as 别名]
# 或者: from gramps.gen.lib.EventRef import set_role [as 别名]
def _parse_marriage(self, line_number, row, col):
"Parse the content of a Marriage,Husband,Wife line."
marriage_ref = rd(line_number, row, col, "marriage")
husband = rd(line_number, row, col, "husband")
wife = rd(line_number, row, col, "wife")
marriagedate = rd(line_number, row, col, "date")
marriageplace = rd(line_number, row, col, "place")
marriageplace_id = rd(line_number, row, col, "place_id")
marriagesource = rd(line_number, row, col, "source")
note = rd(line_number, row, col, "note")
wife = self.lookup("person", wife)
husband = self.lookup("person", husband)
if husband is None and wife is None:
# might have children, so go ahead and add
LOG.warning("no parents on line %d; adding family anyway" %
line_number)
family = self.get_or_create_family(marriage_ref, husband, wife)
# adjust gender, if not already provided
if husband:
# this is just a guess, if unknown
if husband.get_gender() == Person.UNKNOWN:
husband.set_gender(Person.MALE)
self.db.commit_person(husband, self.trans)
if wife:
# this is just a guess, if unknown
if wife.get_gender() == Person.UNKNOWN:
wife.set_gender(Person.FEMALE)
self.db.commit_person(wife, self.trans)
if marriage_ref:
self.storeup("family", marriage_ref, family)
if marriagesource:
# add, if new
new, marriagesource = self.get_or_create_source(marriagesource)
if marriageplace and marriageplace_id:
raise Error("Error in marriage: can't have a place and place_id")
if marriageplace:
# add, if new
new, marriageplace = self.get_or_create_place(marriageplace)
elif marriageplace_id:
# better exist already, locally or in database:
marriageplace = self.lookup("place", marriageplace_id)
if marriagedate:
marriagedate = _dp.parse(marriagedate)
if marriagedate or marriageplace or marriagesource or note:
# add, if new; replace, if different
new, marriage = self.get_or_create_event(family,
EventType.MARRIAGE, marriagedate,
marriageplace, marriagesource)
if new:
mar_ref = EventRef()
mar_ref.set_reference_handle(marriage.get_handle())
mar_ref.set_role(EventRoleType(EventRoleType.FAMILY))
family.add_event_ref(mar_ref)
self.db.commit_family(family, self.trans)
# only add note to event:
# append notes, if previous notes
if note:
previous_notes_list = marriage.get_note_list()
updated_note = False
for note_handle in previous_notes_list:
previous_note = self.db.get_note_from_handle(
note_handle)
if previous_note.type == NoteType.EVENT:
previous_text = previous_note.get()
if note not in previous_text:
note = previous_text + "\n" + note
previous_note.set(note)
self.db.commit_note(previous_note, self.trans)
updated_note = True
break
if not updated_note:
# add new note here
new_note = Note()
new_note.handle = create_id()
new_note.type.set(NoteType.EVENT)
new_note.set(note)
if self.default_tag:
new_note.add_tag(self.default_tag.handle)
self.db.add_note(new_note, self.trans)
marriage.add_note(new_note.handle)
self.db.commit_event(marriage, self.trans)