本文整理汇总了Python中gramps.gen.lib.Event.set_type方法的典型用法代码示例。如果您正苦于以下问题:Python Event.set_type方法的具体用法?Python Event.set_type怎么用?Python Event.set_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gramps.gen.lib.Event
的用法示例。
在下文中一共展示了Event.set_type方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_event
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [as 别名]
def create_event(self, description=_("Estimated date"),
type=None, date=None, source=None,
note_text="", modifier=None):
event = Event()
event.set_description(description)
note = Note()
note.handle = create_id()
note.type.set(NoteType.EVENT)
note.set(note_text)
self.db.add_note(note, self.trans)
event.add_note(note.handle)
if type:
event.set_type(EventType(type))
if date:
if modifier:
date.set_modifier(modifier)
date.set_quality(Date.QUAL_ESTIMATED)
date.set_yr_mon_day(date.get_year(), 0, 0)
event.set_date_object(date)
if source:
citation = Citation()
citation.set_reference_handle(source.get_handle())
self.db.add_citation(citation, self.trans)
event.add_citation(citation.get_handle())
self.db.commit_source(source, self.trans)
self.db.add_event(event, self.trans)
return event
示例2: __new_census
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [as 别名]
def __new_census(self, widget):
"""
Create a new census and invoke the editor.
"""
event = Event()
event.set_type(EventType.CENSUS)
try:
CensusEditor(self.gui.dbstate, self.gui.uistate, [], event)
except WindowActiveError:
pass
示例3: add_button_clicked
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [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
示例4: add_occupation
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [as 别名]
def add_occupation(self, fields, data):
"""Read the ROLE property of a VCard."""
occupation = data.strip()
if occupation:
event = Event()
event.set_type(EventType(EventType.OCCUPATION))
event.set_description(self.unesc(occupation))
self.database.add_event(event, self.trans)
event_ref = EventRef()
event_ref.set_reference_handle(event.get_handle())
self.person.add_event_ref(event_ref)
示例5: create_event
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [as 别名]
def create_event(self,type,desc=None,date=None,place=None,source=None):
event = Event()
if type:
event.set_type(EventType(type))
if desc:
event.set_description(desc)
if date:
event.set_date_object(date)
if place:
event.set_place_handle(place.get_handle())
if source:
event.add_citation(source.get_handle())
self.db.add_event(event,self.trans)
self.db.commit_event(event,self.trans)
return event
示例6: add_birthday
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [as 别名]
def add_birthday(self, fields, data):
"""Read the BDAY property of a VCard."""
date_str = data.strip()
date_match = VCardParser.DATE_RE.match(date_str)
date = Date()
if date_match:
if date_match.group(2):
date_str = "%s-%s-%s" % (date_match.group(2),
date_match.group(3), date_match.group(4))
else:
date_str = date_match.group(1)
y, m, d = [int(x, 10) for x in date_str.split('-')]
try:
date.set(value=(d, m, y, False))
except DateError:
# TRANSLATORS: leave the {vcard_snippet} untranslated
# in the format string, but you may re-order it if needed.
self.__add_msg(_(
"Invalid date in BDAY {vcard_snippet}, "
"preserving date as text."
).format(vcard_snippet=data), self.line_num - 1)
date.set(modifier=Date.MOD_TEXTONLY, text=data)
else:
if date_str:
# TRANSLATORS: leave the {vcard_snippet} untranslated.
self.__add_msg(_(
"Date {vcard_snippet} not in appropriate format "
"yyyy-mm-dd, preserving date as text."
).format(vcard_snippet=date_str), self.line_num - 1)
date.set(modifier=Date.MOD_TEXTONLY, text=date_str)
else: # silently ignore an empty BDAY record
return
event = Event()
event.set_type(EventType(EventType.BIRTH))
event.set_date_object(date)
self.database.add_event(event, self.trans)
event_ref = EventRef()
event_ref.set_reference_handle(event.get_handle())
self.person.set_birth_ref(event_ref)
示例7: get_or_create_event
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [as 别名]
def get_or_create_event(self, object_, type_, date=None, place=None,
source=None):
""" Add or find a type event on object """
# first, see if it exists
LOG.debug("get_or_create_event")
ref_list = object_.get_event_ref_list()
LOG.debug("refs: %s", ref_list)
# look for a match, and possible correction
for ref in ref_list:
event = self.db.get_event_from_handle(ref.ref)
LOG.debug(" compare event type %s == %s", int(event.get_type()),
type_)
if int(event.get_type()) == type_:
# Match! Let's update
if date:
event.set_date_object(date)
if place:
event.set_place_handle(place.get_handle())
if source:
self.find_and_set_citation(event, source)
self.db.commit_event(event, self.trans)
LOG.debug(" returning existing event")
return (0, event)
# else create it:
LOG.debug(" creating event")
event = Event()
if type_:
event.set_type(EventType(type_))
if date:
event.set_date_object(date)
if place:
event.set_place_handle(place.get_handle())
if source:
self.find_and_set_citation(event, source)
self.db.add_event(event, self.trans)
return (1, event)
示例8: Event
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [as 别名]
from gramps.gen.relationship import get_relationship_calculator
from gramps.gen.const import GRAMPS_LOCALE as glocale
try:
_trans = glocale.get_addon_translator(__file__)
except ValueError:
_trans = glocale.translation
_ = _trans.gettext
# ------------------------------------------------------------------------
#
# Constants
#
# ------------------------------------------------------------------------
empty_birth = Event()
empty_birth.set_type(EventType.BIRTH)
empty_marriage = Event()
empty_marriage.set_type(EventType.MARRIAGE)
# ------------------------------------------------------------------------
#
# Relations report
#
# ------------------------------------------------------------------------
class Relations(Report):
"""
Relations is a page that contains all available info about the relationship
between two people.
"""
示例9: FamilySidebarFilter
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [as 别名]
class FamilySidebarFilter(SidebarFilter):
def __init__(self, dbstate, uistate, clicked):
self.clicked_func = clicked
self.filter_id = widgets.BasicEntry()
self.filter_father = widgets.BasicEntry()
self.filter_mother = widgets.BasicEntry()
self.filter_child = widgets.BasicEntry()
self.filter_event = Event()
self.filter_event.set_type((EventType.CUSTOM, ''))
self.etype = Gtk.ComboBox(has_entry=True)
self.family_stub = Family()
self.family_stub.set_relationship((FamilyRelType.CUSTOM, ''))
self.rtype = Gtk.ComboBox(has_entry=True)
self.event_menu = widgets.MonitoredDataType(
self.etype,
self.filter_event.set_type,
self.filter_event.get_type)
self.rel_menu = widgets.MonitoredDataType(
self.rtype,
self.family_stub.set_relationship,
self.family_stub.get_relationship)
self.filter_note = widgets.BasicEntry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox()
SidebarFilter.__init__(self, dbstate, uistate, "Family")
def create_widget(self):
cell = Gtk.CellRendererText()
cell.set_property('width', self._FILTER_WIDTH)
cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
self.generic.pack_start(cell, True)
self.generic.add_attribute(cell, 'text', 0)
self.on_filters_changed('Family')
cell = Gtk.CellRendererText()
cell.set_property('width', self._FILTER_WIDTH)
cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
self.tag.pack_start(cell, True)
self.tag.add_attribute(cell, 'text', 0)
self.etype.get_child().set_width_chars(5)
self.rtype.get_child().set_width_chars(5)
self.add_text_entry(_('ID'), self.filter_id)
self.add_text_entry(_('Father'), self.filter_father)
self.add_text_entry(_('Mother'), self.filter_mother)
self.add_text_entry(_('Child'), self.filter_child)
self.add_entry(_('Relationship'), self.rtype)
self.add_entry(_('Family Event'), self.etype)
self.add_text_entry(_('Family Note'), self.filter_note)
self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex)
def clear(self, obj):
self.filter_id.set_text('')
self.filter_father.set_text('')
self.filter_mother.set_text('')
self.filter_child.set_text('')
self.filter_note.set_text('')
self.etype.get_child().set_text('')
self.rtype.get_child().set_text('')
self.tag.set_active(0)
self.generic.set_active(0)
def get_filter(self):
gid = str(self.filter_id.get_text()).strip()
father = str(self.filter_father.get_text()).strip()
mother = str(self.filter_mother.get_text()).strip()
child = str(self.filter_child.get_text()).strip()
note = str(self.filter_note.get_text()).strip()
etype = self.filter_event.get_type().xml_str()
rtype = self.family_stub.get_relationship().xml_str()
regex = self.filter_regex.get_active()
tag = self.tag.get_active() > 0
generic = self.generic.get_active() > 0
empty = not (gid or father or mother or child or note
or regex or etype or rtype or tag or generic)
if empty:
generic_filter = None
else:
generic_filter = GenericFamilyFilter()
if gid:
rule = RegExpIdOf([gid], use_regex=regex)
generic_filter.add_rule(rule)
if father:
rule = RegExpFatherName([father], use_regex=regex)
generic_filter.add_rule(rule)
#.........这里部分代码省略.........
示例10: run_tool
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [as 别名]
#.........这里部分代码省略.........
# dates.append( d)
# except:
# d = Date()
# d.set_as_text("Date.set Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
# dates.append( d)
#self.progress.step()
#d = Date()
#d.set(Date.QUAL_NONE,Date.MOD_NONE,
# Date.CAL_GREGORIAN,(44,7,1789,False),"Text comment")
#dates.append( d)
#d = Date()
#d.set(Date.QUAL_NONE,Date.MOD_NONE,
# Date.CAL_GREGORIAN,(4,77,1789,False),"Text comment")
#dates.append( d)
#d = Date()
#d.set(Date.QUAL_NONE,Date.MOD_SPAN,
# Date.CAL_GREGORIAN,
# (4,7,1789,False,55,8,1876,False),"Text comment")
#dates.append( d)
#d = Date()
#d.set(Date.QUAL_NONE,Date.MOD_SPAN,
# Date.CAL_GREGORIAN,
# (4,7,1789,False,5,88,1876,False),"Text comment")
#dates.append( d)
with DbTxn(_("Date Test Plugin"), self.db, batch=True) as self.trans:
self.db.disable_signals()
self.progress.set_pass(_('Generating dates'),
len(dates))
# create pass and fail tags
pass_handle = self.create_tag(_('Pass'), '#0000FFFF0000')
fail_handle = self.create_tag(_('Fail'), '#FFFF00000000')
# now add them as birth to new persons
i = 1
for dateval in dates:
person = Person()
surname = Surname()
surname.set_surname("DateTest")
name = Name()
name.add_surname(surname)
name.set_first_name("Test %d" % i)
person.set_primary_name(name)
self.db.add_person(person, self.trans)
bevent = Event()
bevent.set_type(EventType.BIRTH)
bevent.set_date_object(dateval)
bevent.set_description("Date Test %d (source)" % i)
bevent_h = self.db.add_event(bevent, self.trans)
bevent_ref = EventRef()
bevent_ref.set_reference_handle(bevent_h)
# for the death event display the date as text and parse it back to a new date
ndate = None
try:
datestr = _dd.display( dateval)
try:
ndate = _dp.parse( datestr)
if not ndate:
ndate = Date()
ndate.set_as_text("DateParser None")
person.add_tag(fail_handle)
else:
person.add_tag(pass_handle)
except:
ndate = Date()
ndate.set_as_text("DateParser Exception %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
person.add_tag(fail_handle)
else:
person.add_tag(pass_handle)
except:
ndate = Date()
ndate.set_as_text("DateDisplay Exception: %s" % ("".join(traceback.format_exception(*sys.exc_info())),))
person.add_tag(fail_handle)
if dateval.get_modifier() != Date.MOD_TEXTONLY \
and ndate.get_modifier() == Date.MOD_TEXTONLY:
# parser was unable to correctly parse the string
ndate.set_as_text( "TEXTONLY: "+ndate.get_text())
person.add_tag(fail_handle)
if dateval.get_modifier() == Date.MOD_TEXTONLY \
and dateval.get_text().count("Traceback") \
and pass_handle in person.get_tag_list():
person.add_tag(fail_handle)
devent = Event()
devent.set_type(EventType.DEATH)
devent.set_date_object(ndate)
devent.set_description("Date Test %d (result)" % i)
devent_h = self.db.add_event(devent, self.trans)
devent_ref = EventRef()
devent_ref.set_reference_handle(devent_h)
person.set_birth_ref(bevent_ref)
person.set_death_ref(devent_ref)
self.db.commit_person(person, self.trans)
i = i + 1
self.progress.step()
self.db.enable_signals()
self.db.request_rebuild()
self.progress.close()
示例11: EventSidebarFilter
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [as 别名]
class EventSidebarFilter(SidebarFilter):
def __init__(self, dbstate, uistate, clicked):
self.clicked_func = clicked
self.filter_id = widgets.BasicEntry()
self.filter_desc = widgets.BasicEntry()
self.filter_event = Event()
self.filter_event.set_type((EventType.CUSTOM, ''))
self.etype = Gtk.ComboBox(has_entry=True)
self.custom_types = dbstate.db.get_event_types()
self.event_menu = widgets.MonitoredDataType(
self.etype,
self.filter_event.set_type,
self.filter_event.get_type,
custom_values=self.custom_types)
self.filter_mainparts = widgets.BasicEntry()
self.filter_date = widgets.DateEntry(uistate, [])
self.filter_place = widgets.BasicEntry()
self.filter_note = widgets.BasicEntry()
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox()
SidebarFilter.__init__(self, dbstate, uistate, "Event")
def create_widget(self):
cell = Gtk.CellRendererText()
cell.set_property('width', self._FILTER_WIDTH)
cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
self.generic.pack_start(cell, True)
self.generic.add_attribute(cell, 'text', 0)
self.on_filters_changed('Event')
cell = Gtk.CellRendererText()
cell.set_property('width', self._FILTER_WIDTH)
cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
self.tag.pack_start(cell, True)
self.tag.add_attribute(cell, 'text', 0)
self.etype.get_child().set_width_chars(5)
self.add_text_entry(_('ID'), self.filter_id)
self.add_text_entry(_('Description'), self.filter_desc)
self.add_entry(_('Type'), self.etype)
self.add_text_entry(_('Participants'), self.filter_mainparts)
self.add_text_entry(_('Date'), self.filter_date)
self.add_text_entry(_('Place'), self.filter_place)
self.add_text_entry(_('Note'), self.filter_note)
self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex)
def clear(self, obj):
self.filter_id.set_text('')
self.filter_desc.set_text('')
self.filter_mainparts.set_text('')
self.filter_date.set_text('')
self.filter_place.set_text('')
self.filter_note.set_text('')
self.etype.get_child().set_text('')
self.tag.set_active(0)
self.generic.set_active(0)
def get_filter(self):
gid = str(self.filter_id.get_text()).strip()
desc = str(self.filter_desc.get_text()).strip()
mainparts = str(self.filter_mainparts.get_text()).strip()
date = str(self.filter_date.get_text()).strip()
place = str(self.filter_place.get_text()).strip()
note = str(self.filter_note.get_text()).strip()
regex = self.filter_regex.get_active()
tag = self.tag.get_active() > 0
generic = self.generic.get_active() > 0
etype = self.filter_event.get_type().xml_str()
empty = not (gid or desc or mainparts or date or place or note
or etype or regex or tag or generic)
if empty:
generic_filter = None
else:
generic_filter = GenericEventFilter()
if gid:
rule = RegExpIdOf([gid], use_regex=regex)
generic_filter.add_rule(rule)
rule = HasEvent([etype, date, place, desc, mainparts],
use_regex=regex)
generic_filter.add_rule(rule)
if note:
rule = HasNoteRegexp([note], use_regex=regex)
generic_filter.add_rule(rule)
# check the Tag
if tag:
model = self.tag.get_model()
#.........这里部分代码省略.........
示例12: PersonSidebarFilter
# 需要导入模块: from gramps.gen.lib import Event [as 别名]
# 或者: from gramps.gen.lib.Event import set_type [as 别名]
class PersonSidebarFilter(SidebarFilter):
def __init__(self, dbstate, uistate, clicked):
self.clicked_func = clicked
self.filter_name = widgets.BasicEntry()
self.filter_id = widgets.BasicEntry()
self.filter_birth = widgets.DateEntry(uistate, [])
self.filter_death = widgets.DateEntry(uistate, [])
self.filter_event = Event()
self.filter_event.set_type((EventType.CUSTOM, ''))
self.etype = Gtk.ComboBox(has_entry=True)
if dbstate.is_open():
self.custom_types = dbstate.db.get_event_types()
else:
self.custom_types = []
self.event_menu = widgets.MonitoredDataType(
self.etype,
self.filter_event.set_type,
self.filter_event.get_type,
custom_values=self.custom_types)
self.filter_note = widgets.BasicEntry()
self.filter_gender = Gtk.ComboBoxText()
list(map(self.filter_gender.append_text,
[ _('any'), _('male'), _('female'), _('unknown') ]))
self.filter_gender.set_active(0)
self.filter_regex = Gtk.CheckButton(label=_('Use regular expressions'))
self.tag = Gtk.ComboBox()
self.generic = Gtk.ComboBox()
SidebarFilter.__init__(self, dbstate, uistate, "Person")
def create_widget(self):
cell = Gtk.CellRendererText()
cell.set_property('width', self._FILTER_WIDTH)
cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
self.generic.pack_start(cell, True)
self.generic.add_attribute(cell, 'text', 0)
self.on_filters_changed('Person')
cell = Gtk.CellRendererText()
cell.set_property('width', self._FILTER_WIDTH)
cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
self.tag.pack_start(cell, True)
self.tag.add_attribute(cell, 'text', 0)
self.etype.get_child().set_width_chars(5)
exdate1 = Date()
exdate2 = Date()
exdate1.set(Date.QUAL_NONE, Date.MOD_RANGE,
Date.CAL_GREGORIAN, (0, 0, 1800, False,
0, 0, 1900, False))
exdate2.set(Date.QUAL_NONE, Date.MOD_BEFORE,
Date.CAL_GREGORIAN, (0, 0, 1850, False))
msg1 = displayer.display(exdate1)
msg2 = displayer.display(exdate2)
self.add_text_entry(_('Name'), self.filter_name)
self.add_text_entry(_('ID'), self.filter_id)
self.add_entry(_('Gender'), self.filter_gender)
self.add_text_entry(_('Birth date'), self.filter_birth,
_('example: "%(msg1)s" or "%(msg2)s"') % {'msg1':msg1, 'msg2':msg2})
self.add_text_entry(_('Death date'), self.filter_death,
_('example: "%(msg1)s" or "%(msg2)s"') % {'msg1':msg1, 'msg2':msg2})
self.add_entry(_('Event'), self.etype)
self.add_text_entry(_('Note'), self.filter_note)
self.add_entry(_('Tag'), self.tag)
self.add_filter_entry(_('Custom filter'), self.generic)
self.add_regex_entry(self.filter_regex)
def clear(self, obj):
self.filter_name.set_text('')
self.filter_id.set_text('')
self.filter_birth.set_text('')
self.filter_death.set_text('')
self.filter_note.set_text('')
self.filter_gender.set_active(0)
self.etype.get_child().set_text('')
self.tag.set_active(0)
self.generic.set_active(0)
def get_filter(self):
"""
Extracts the text strings from the sidebar, and uses them to build up
a new filter.
"""
# extract text values from the entry widgets
name = extract_text(self.filter_name)
gid = extract_text(self.filter_id)
birth = extract_text(self.filter_birth)
death = extract_text(self.filter_death)
note = extract_text(self.filter_note)
# extract remaining data from the menus
etype = self.filter_event.get_type().xml_str()
#.........这里部分代码省略.........