本文整理汇总了Python中gramps.gen.lib.Tag类的典型用法代码示例。如果您正苦于以下问题:Python Tag类的具体用法?Python Tag怎么用?Python Tag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tag类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_struct
def from_struct(struct):
"""
Given a struct with metadata, create a Gramps object.
"""
from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
Repository, MediaObject, Note, Tag)
if isinstance(struct, dict):
if "_class" in struct.keys():
if struct["_class"] == "Person":
return Person.create(Person.from_struct(struct))
elif struct["_class"] == "Family":
return Family.create(Family.from_struct(struct))
elif struct["_class"] == "Event":
return Event.create(Event.from_struct(struct))
elif struct["_class"] == "Source":
return Source.create(Source.from_struct(struct))
elif struct["_class"] == "Place":
return Place.create(Place.from_struct(struct))
elif struct["_class"] == "Citation":
return Citation.create(Citation.from_struct(struct))
elif struct["_class"] == "Repository":
return Repository.create(Repository.from_struct(struct))
elif struct["_class"] == "MediaObject":
return MediaObject.create(MediaObject.from_struct(struct))
elif struct["_class"] == "Note":
return Note.create(Note.from_struct(struct))
elif struct["_class"] == "Tag":
return Tag.create(Tag.from_struct(struct))
raise AttributeError("invalid struct: %s" % struct)
示例2: instance_from_struct
def instance_from_struct(cls, struct):
"""
Given a struct with metadata, create a Gramps object.
self is class when called as a classmethod.
"""
from gramps.gen.lib import (Person, Family, Event, Source, Place, Citation,
Repository, Media, Note, Tag, Date)
if isinstance(struct, dict):
if "_class" in struct.keys():
if struct["_class"] == "Person":
return Person.create(Person.from_struct(struct))
elif struct["_class"] == "Family":
return Family.create(Family.from_struct(struct))
elif struct["_class"] == "Event":
return Event.create(Event.from_struct(struct))
elif struct["_class"] == "Source":
return Source.create(Source.from_struct(struct))
elif struct["_class"] == "Place":
return Place.create(Place.from_struct(struct))
elif struct["_class"] == "Citation":
return Citation.create(Citation.from_struct(struct))
elif struct["_class"] == "Repository":
return Repository.create(Repository.from_struct(struct))
elif struct["_class"] == "Media":
return Media.create(Media.from_struct(struct))
elif struct["_class"] == "Note":
return Note.create(Note.from_struct(struct))
elif struct["_class"] == "Tag":
return Tag.create(Tag.from_struct(struct))
elif struct["_class"] == "Date":
return Date().unserialize(Date.from_struct(struct, full=True))
raise AttributeError("invalid struct: %s" % struct)
示例3: cb_new_tag
def cb_new_tag(self, action):
"""
Create a new tag and tag the selected objects.
"""
tag = Tag()
tag.set_priority(self.db.get_number_of_tags())
EditTag(self.db, self.uistate, [], tag)
if tag.get_handle():
self.tag_selected_rows(tag.get_handle())
示例4: importData
def importData(db, filename, user):
"""Function called by Gramps to import data on persons in CSV format."""
db.disable_signals()
try:
with DbTxn(_("JSON import"), db, batch=True) as trans:
with OpenFileOrStdin(filename, encoding="utf-8") as fp:
line = fp.readline()
while line:
data = json.loads(line)
if data["_class"] == "Person":
obj = Person.create(Person.from_struct(data))
db.add_person(obj, trans)
elif data["_class"] == "Family":
obj = Family.create(Family.from_struct(data))
db.add_family(obj, trans)
elif data["_class"] == "Event":
obj = Event.create(Event.from_struct(data))
db.add_event(obj, trans)
elif data["_class"] == "Media":
obj = Media.create(Media.from_struct(data))
db.add_media(obj, trans)
elif data["_class"] == "Repository":
obj = Repository.create(Repository.from_struct(data))
db.add_repository(obj, trans)
elif data["_class"] == "Tag":
obj = Tag.create(Tag.from_struct(data))
db.add_tag(obj, trans)
elif data["_class"] == "Source":
obj = Source.create(Source.from_struct(data))
db.add_source(obj, trans)
elif data["_class"] == "Citation":
obj = Citation.create(Citation.from_struct(data))
db.add_citation(obj, trans)
elif data["_class"] == "Note":
obj = Note.create(Note.from_struct(data))
db.add_note(obj, trans)
elif data["_class"] == "Place":
obj = Place.create(Place.from_struct(data))
db.add_place(obj, trans)
else:
LOG.warn("ignored: " + data)
line = fp.readline()
except EnvironmentError as err:
user.notify_error(_("%s could not be opened\n") % filename, str(err))
db.enable_signals()
db.request_rebuild()
示例5: cb_add_clicked
def cb_add_clicked(self, button, top):
"""
Create a new tag.
"""
tag = Tag()
tag.set_priority(self.db.get_number_of_tags())
EditTag(self.db, self.uistate, self.track, tag)
if tag.get_handle():
self.namemodel.add((tag.get_priority(),
tag.get_handle(),
tag.get_name(),
tag.get_color()))
示例6: get_tag_from_name
def get_tag_from_name(self, name):
"""
Find a Tag in the database from the passed Tag name.
If no such Tag exists, None is returned.
"""
self.dbapi.execute("SELECT blob_data FROM tag WHERE name = ?", [name])
row = self.dbapi.fetchone()
if row:
return Tag.create(pickle.loads(row[0]))
return None
示例7: cb_add_clicked
def cb_add_clicked(self, button, top):
"""
Create a new tag.
"""
tag = Tag()
tag.set_priority(self.db.get_number_of_tags())
edit_dialog = EditTag(self.db, top, tag)
edit_dialog.run()
if tag.get_handle():
self.namemodel.add((tag.get_priority(),
tag.get_handle(),
tag.get_name(),
tag.get_color()))
示例8: create_tag
def create_tag(self, tag_name, tag_color):
"""
Create a tag if it doesn't already exist.
"""
tag = self.db.get_tag_from_name(tag_name)
if tag is None:
tag = Tag()
tag.set_name(tag_name)
if tag_color is not None:
tag.set_color(tag_color)
tag.set_priority(self.db.get_number_of_tags())
tag_handle = self.db.add_tag(tag, self.trans)
else:
tag_handle = tag.get_handle()
return tag_handle
示例9: on_ok_clicked
def on_ok_clicked(self, obj):
clean = self.clear_button.get_active()
copy = self.copy_button.get_active()
tag = self.tag_button.get_active()
if not (copy or clean or tag):
return
self.db.disable_signals()
if tag:
tag_name = _('Legacy place')
# start the db transaction
with DbTxn("Tag for place titles", self.db) as self.tag_trans:
mark = self.db.get_tag_from_name(tag_name)
if not mark:
# create the tag if it doesn't already exist
mark = Tag()
mark.set_name(tag_name)
mark.set_priority(self.db.get_number_of_tags())
tag_handle = self.db.add_tag(mark, self.tag_trans)
else:
tag_handle = mark.get_handle()
with DbTxn(_("Modify Place titles"), self.db, batch=True) as trans:
for row in self.model:
if row[1] == True:
place = self.db.get_place_from_handle(row[0])
if copy:
self.create_note(place, row[2], trans)
if clean:
place.set_title("")
if tag:
place.add_tag(tag_handle)
self.db.commit_place(place, trans)
self.db.enable_signals()
self.db.request_rebuild()
self.close()
示例10: applyTagClicked
def applyTagClicked(self, button) :
progress = None
rows = self.treeSelection.count_selected_rows()
tag_name = str(self.tagcombo.get_active_text())
# start the db transaction
with DbTxn("Tag not related", self.db) as transaction:
tag = self.db.get_tag_from_name(tag_name)
if not tag:
# create the tag if it doesn't already exist
tag = Tag()
tag.set_name(tag_name)
tag.set_priority(self.db.get_number_of_tags())
tag_handle = self.db.add_tag(tag, transaction)
else:
tag_handle = tag.get_handle()
# if more than 1 person is selected, use a progress indicator
if rows > 1:
progress = ProgressMeter(self.title,_('Starting'),
parent=self.window)
progress.set_pass(
# translators: leave all/any {...} untranslated
#TRANS: no singular form needed, as rows is always > 1
ngettext("Setting tag for {number_of} person",
"Setting tag for {number_of} people",
rows).format(number_of=rows),
rows)
# iterate through all of the selected rows
(model, paths) = self.treeSelection.get_selected_rows()
for path in paths:
if progress:
progress.step()
# for the current row, get the GID and the person from the database
iter = self.model.get_iter(path)
personGid = self.model.get_value(iter, 1)
person = self.db.get_person_from_gramps_id(personGid)
# add the tag to the person
person.add_tag(tag_handle)
# save this change
self.db.commit_person(person, transaction)
# refresh the tags column
self.treeView.set_model(None)
for path in paths:
iter = self.model.get_iter(path)
personGid = self.model.get_value(iter, 1)
person = self.db.get_person_from_gramps_id(personGid)
self.model.set_value(iter, 3, self.get_tag_list(person))
self.treeView.set_model(self.model)
self.treeView.expand_all()
if progress:
progress.close()
示例11: __init__
#.........这里部分代码省略.........
column2label = {
"surname": ("Lastname", "Surname", _("Surname"), "lastname",
"last_name", "surname", _("surname")),
"firstname": ("Firstname", "Given name", _("Given name"), "Given",
_("Given"), "firstname", "first_name", "given_name",
"given name", _("given name"), "given", _("given")),
"callname": ("Callname", "Call name", _("Call name"), "Call",
_("Call"), "callname", "call_name", "call name", "call",
_("call")),
"title": ("Title", _("Person or Place|Title"), "title", _("Person or Place|title")),
"prefix": ("Prefix", _("Prefix"), "prefix", _("prefix")),
"suffix": ("Suffix", _("Suffix"), "suffix", _("suffix")),
"gender": ("Gender", _("Gender"), "gender", _("gender")),
"source": ("Source", _("Source"), "source", _("source")),
"note": ("Note", _("Note"), "note", _("note")),
"birthplace": ("Birthplace", "Birth place", _("Birth place"),
"birthplace", "birth_place", "birth place", _("birth place")),
"birthplace_id": ("Birthplaceid", "Birth place id", _("Birth place id"),
"birthplaceid", "birth_place_id", "birth place id", _("birth place id"),
"birthplace_id"),
"birthdate": ("Birthdate", "Birth date", _("Birth date"),
"birthdate", "birth_date", "birth date", _("birth date")),
"birthsource": ("Birthsource", "Birth source", _("Birth source"),
"birthsource", "birth_source", "birth source",
_("birth source")),
"baptismplace": ("Baptismplace", "Baptism place",
_("Baptism place"), "baptismplace", "baptism place",
_("baptism place")),
"baptismplace_id": ("Baptismplaceid", "Baptism place id",
_("Baptism place id"), "baptismplaceid", "baptism place id",
_("baptism place id"), "baptism_place_id",
"baptismplace_id"),
"baptismdate": ("Baptismdate", "Baptism date", _("Baptism date"),
"baptismdate", "baptism date", _("baptism date")),
"baptismsource": ("Baptismsource", "Baptism source",
_("Baptism source"), "baptismsource", "baptism source",
_("baptism source")),
"burialplace": ("Burialplace", "Burial place", _("Burial place"),
"burialplace", "burial place", _("burial place")),
"burialplace_id": ("Burialplaceid", "Burial place id", _("Burial place id"),
"burialplaceid", "burial place id", _("burial place id"),
"burial_place_id", "burialplace_id"),
"burialdate": ("Burialdate", "Burial date", _("Burial date"),
"burialdate", "burial date", _("burial date")),
"burialsource": ("Burialsource", "Burial source",
_("Burial source"), "burialsource", "burial source",
_("burial source")),
"deathplace": ("Deathplace", "Death place", _("Death place"),
"deathplace", "death_place", "death place", _("death place")),
"deathplace_id": ("Deathplaceid", "Death place id", _("Death place id"),
"deathplaceid", "death_place_id", "death place id", _("death place id"),
"death_place_id", "deathplace_id"),
"deathdate": ("Deathdate", "Death date", _("Death date"),
"deathdate", "death_date", "death date", _("death date")),
"deathsource": ("Deathsource", "Death source", _("Death source"),
"deathsource", "death_source", "death source",
_("death source")),
"deathcause": ("Deathcause", "Death cause", _("Death cause"),
"deathcause", "death_cause", "death cause", _("death cause")),
"grampsid": ("Grampsid", "ID", "Gramps id", _("Gramps ID"),
"grampsid", "id", "gramps_id", "gramps id", _("Gramps id")),
"person": ("Person", _("Person"), "person", _("person")),
# ----------------------------------
"child": ("Child", _("Child"), "child", _("child")),
"family": ("Family", _("Family"), "family", _("family")),
# ----------------------------------
"wife": ("Mother", _("Mother"), "Wife", _("Wife"), "Parent2",
_("Parent2"), "mother", _("mother"), "wife", _("wife"),
"parent2", _("parent2")),
"husband": ("Father", _("Father"), "Husband", _("Husband"),
"Parent1", _("Parent1"), "father", _("father"), "husband",
_("husband"), "parent1", _("parent1")),
"marriage": ("Marriage", _("Marriage"), "marriage", _("marriage")),
"date": ("Date", _("Date"), "date", _("date")),
"place": ("Place", _("Place"), "place", _("place")),
"place_id": ("Placeid", "place id", "Place id", "place_id", "placeid"),
"name": ("Name", _("Name"), "name", _("name")),
"type": ("Type", _("Type"), "type", _("type")),
"latitude": ("Latitude", _("latitude"), "latitude", _("latitude")),
"longitude": ("Longitude", _("Longitude"), "longitude", _("longitude")),
"code": ("Code", _("Code"), "code", _("code")),
"enclosed_by": ("Enclosed by", _("Enclosed by"), "enclosed by", _("enclosed by"),
"enclosed_by", _("enclosed_by"), "Enclosed_by", _("Enclosed_by"),
"enclosedby")
}
lab2col_dict = []
for key in list(column2label.keys()):
for val in column2label[key]:
lab2col_dict.append((val, key))
self.label2column = dict(lab2col_dict)
if default_tag_format:
name = time.strftime(default_tag_format)
tag = self.db.get_tag_from_name(name)
if tag:
self.default_tag = tag
else:
self.default_tag = Tag()
self.default_tag.set_name(name)
else:
self.default_tag = None
示例12: exportData
#.........这里部分代码省略.........
len(database.family_map) +
len(database.repository_map) +
len(database.place_map) +
len(database.media_map) +
len(database.citation_map) +
len(database.source_map) +
len(database.tag_map))
count = 0.0
# ---------------------------------
# Notes
# ---------------------------------
for handle in database.note_map.keys():
serial = database.note_map[handle]
write_line(fp, Note.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Event
# ---------------------------------
for handle in database.event_map.keys():
serial = database.event_map[handle]
write_line(fp, Event.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Person
# ---------------------------------
for handle in database.person_map.keys():
serial = database.person_map[handle]
write_line(fp, Person.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Family
# ---------------------------------
for handle in database.family_map.keys():
serial = database.family_map[handle]
write_line(fp, Family.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Repository
# ---------------------------------
for handle in database.repository_map.keys():
serial = database.repository_map[handle]
write_line(fp, Repository.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Place
# ---------------------------------
for handle in database.place_map.keys():
serial = database.place_map[handle]
write_line(fp, Place.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Source
# ---------------------------------
for handle in database.source_map.keys():
serial = database.source_map[handle]
write_line(fp, Source.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Citation
# ---------------------------------
for handle in database.citation_map.keys():
serial = database.citation_map[handle]
write_line(fp, Citation.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Media
# ---------------------------------
for handle in database.media_map.keys():
serial = database.media_map[handle]
write_line(fp, Media.create(serial))
count += 1
callback(100 * count/total)
# ---------------------------------
# Tag
# ---------------------------------
for handle in database.tag_map.keys():
serial = database.tag_map[handle]
write_line(fp, Tag.create(serial))
count += 1
callback(100 * count/total)
return True
示例13: __init__
def __init__(self, dbase, user, default_tag_format=None):
self.db = dbase
self.user = user
self.trans = None
self.lineno = 0
self.index = 0
self.fam_count = 0
self.indi_count = 0
self.pref = {} # person ref, internal to this sheet
self.fref = {} # family ref, internal to this sheet
column2label = {
"surname": ("Lastname", "Surname", _("Surname"), "lastname",
"last_name", "surname", _("surname")),
"firstname": ("Firstname", "Given name", _("Given name"), "Given",
_("Given"), "firstname", "first_name", "given_name",
"given name", _("given name"), "given", _("given")),
"callname": ("Callname", "Call name", _("Call name"), "Call",
_("Call"), "callname", "call_name", "call name", "call",
_("call")),
"title": ("Title", _("Person|Title"), "title", _("Person|title")),
"prefix": ("Prefix", _("Prefix"), "prefix", _("prefix")),
"suffix": ("Suffix", _("Suffix"), "suffix", _("suffix")),
"gender": ("Gender", _("Gender"), "gender", _("gender")),
"source": ("Source", _("Source"), "source", _("source")),
"note": ("Note", _("Note"), "note", _("note")),
"birthplace": ("Birthplace", "Birth place", _("Birth place"),
"birthplace", "birth_place", "birth place", _("birth place")),
"birthdate": ("Birthdate", "Birth date", _("Birth date"),
"birthdate", "birth_date", "birth date", _("birth date")),
"birthsource": ("Birthsource", "Birth source", _("Birth source"),
"birthsource", "birth_source", "birth source",
_("birth source")),
"baptismplace": ("Baptismplace", "Baptism place",
_("Baptism place"), "baptismplace", "baptism place",
_("baptism place")),
"baptismdate": ("Baptismdate", "Baptism date", _("Baptism date"),
"baptismdate", "baptism date", _("baptism date")),
"baptismsource": ("Baptismsource", "Baptism source",
_("Baptism source"), "baptismsource", "baptism source",
_("baptism source")),
"burialplace": ("Burialplace", "Burial place", _("Burial place"),
"burialplace", "burial place", _("burial place")),
"burialdate": ("Burialdate", "Burial date", _("Burial date"),
"burialdate", "burial date", _("burial date")),
"burialsource": ("Burialsource", "Burial source",
_("Burial source"), "burialsource", "burial source",
_("burial source")),
"deathplace": ("Deathplace", "Death place", _("Death place"),
"deathplace", "death_place", "death place", _("death place")),
"deathdate": ("Deathdate", "Death date", _("Death date"),
"deathdate", "death_date", "death date", _("death date")),
"deathsource": ("Deathsource", "Death source", _("Death source"),
"deathsource", "death_source", "death source",
_("death source")),
"deathcause": ("Deathcause", "Death cause", _("Death cause"),
"deathcause", "death_cause", "death cause", _("death cause")),
"grampsid": ("Grampsid", "ID", "Gramps id", _("Gramps ID"),
"grampsid", "id", "gramps_id", "gramps id", _("Gramps id")),
"person": ("Person", _("Person"), "person", _("person")),
# ----------------------------------
"child": ("Child", _("Child"), "child", _("child")),
"family": ("Family", _("Family"), "family", _("family")),
# ----------------------------------
"wife": ("Mother", _("Mother"), "Wife", _("Wife"), "Parent2",
_("Parent2"), "mother", _("mother"), "wife", _("wife"),
"parent2", _("parent2")),
"husband": ("Father", _("Father"), "Husband", _("Husband"),
"Parent1", _("Parent1"), "father", _("father"), "husband",
_("husband"), "parent1", _("parent1")),
"marriage": ("Marriage", _("Marriage"), "marriage", _("marriage")),
"date": ("Date", _("Date"), "date", _("date")),
"place": ("Place", _("Place"), "place", _("place")),
}
lab2col_dict = []
for key in list(column2label.keys()):
for val in column2label[key]:
lab2col_dict.append((val, key))
self.label2column = dict(lab2col_dict)
if default_tag_format:
name = time.strftime(default_tag_format)
tag = self.db.get_tag_from_name(name)
if tag:
self.default_tag = tag
else:
self.default_tag = Tag()
self.default_tag.set_name(name)
else:
self.default_tag = None