本文整理汇总了Python中gramps.gen.lib.Place类的典型用法代码示例。如果您正苦于以下问题:Python Place类的具体用法?Python Place怎么用?Python Place使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Place类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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)
示例2: 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)
示例3: create_place
def create_place(self):
""" Used to create a new person we know doesn't exist """
place = Place()
if self.default_tag:
place.add_tag(self.default_tag.handle)
self.db.add_place(place, self.trans)
self.place_count += 1
return place
示例4: column_title
def column_title(self, data):
handle = data[0]
cached, value = self.get_cached_value(handle, "PLACE")
if not cached:
place = Place()
place.unserialize(data)
value = place_displayer.display(self.db, place)
self.set_cached_value(handle, "PLACE", value)
return value
示例5: __add_place
def __add_place(self, parent, plat, plon):
"""
Add a new place using longitude and latitude of location centered
on the map
"""
self.select_fct.close()
new_place = Place()
new_place.set_latitude(str(plat))
new_place.set_longitude(str(plon))
if parent:
if isinstance(parent, Place):
placeref = PlaceRef()
placeref.ref = parent
new_place.add_placeref(placeref)
else:
found = None
for place in self.dbstate.db.iter_places():
found = place
if place.name.get_value() == parent:
break
placeref = PlaceRef()
placeref.ref = found.get_handle()
new_place.add_placeref(placeref)
try:
EditPlace(self.dbstate, self.uistate, [], new_place)
self.add_marker(None, None, plat, plon, None, True, 0)
except WindowActiveError:
pass
示例6: test_editreference
def test_editreference(self):
dbstate = DbState()
dbstate.db = self.db
source = Place()
source.gramps_id = "P0001"
self.db.place_map[source.handle] = source
editor = MockEditReference(dbstate, uistate=None, track=[],
source=source, source_ref=None, update=None)
with patch('gramps.gui.editors.editreference.ErrorDialog') as MockED:
editor.check_for_duplicate_id("Place")
self.assertTrue(MockED.called)
示例7: get_or_create_place
def get_or_create_place(self,place_name):
place = None
if place_name in self.pkeys:
place = self.db.get_place_from_handle(self.pkeys[place_name])
else:
place = Place()
place.set_title(place_name)
self.db.add_place(place,self.trans)
self.db.commit_place(place,self.trans)
self.pkeys[place_name] = place.get_handle()
return place
示例8: get_or_create_place
def get_or_create_place(self, place_name):
"Return the requested place object tuple-packed with a new indicator."
LOG.debug("get_or_create_place: looking for: %s", place_name)
for place_handle in self.db.iter_place_handles():
place = self.db.get_place_from_handle(place_handle)
place_title = place_displayer.display(self.db, place)
if place_title == place_name:
return (0, place)
place = Place()
place.set_title(place_name)
self.db.add_place(place, self.trans)
return (1, place)
示例9: __init__
def __init__(self, dbstate, uistate, clicked):
self.clicked_func = clicked
self.filter_id = widgets.BasicEntry()
self.filter_name = widgets.BasicEntry()
self.filter_place = Place()
self.filter_place.set_type((PlaceType.CUSTOM, ''))
self.ptype = Gtk.ComboBox(has_entry=True)
if dbstate.is_open():
self.custom_types = dbstate.db.get_place_types()
else:
self.custom_types = []
self.place_menu = widgets.MonitoredDataType(
self.ptype,
self.filter_place.set_type,
self.filter_place.get_type,
False, # read-only
self.custom_types
)
self.filter_code = widgets.BasicEntry()
self.filter_enclosed = widgets.PlaceEntry(dbstate, uistate, [])
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, "Place")
示例10: 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()
示例11: add
def add(self, obj):
"""
Add a new place. Use the currently selected rows as parent places.
"""
parent_list = []
for handle in self.selected_handles():
placeref = PlaceRef()
placeref.ref = handle
parent_list.append(placeref)
place = Place()
if len(parent_list) > 0:
place.placeref_list = parent_list
try:
EditPlace(self.dbstate, self.uistate, [], place)
except WindowActiveError:
pass
示例12: test_editreference
def test_editreference(self):
dbstate = DbState()
db = make_database("bsddb")
path = "/tmp/edit_ref_test"
try:
os.mkdir(path)
except:
pass
db.load(path)
dbstate.change_database(db)
source = Place()
source.gramps_id = "P0001"
dbstate.db.place_map[source.handle] = source.serialize()
editor = MockEditReference(dbstate, uistate=None, track=[],
source=source, source_ref=None, update=None)
with patch('gramps.gui.editors.editreference.ErrorDialog') as MockED:
editor.check_for_duplicate_id("Place")
self.assertTrue(MockED.called)
示例13: add_place_from_kml
def add_place_from_kml(self, menu, event, lat, lon):
"""
Add new place(s) from a kml file
1 - ask for a kml file ?
2 - Read the kml file.
3 - create the place(s) with name and title found in the kml marker.
"""
# Ask for the kml file
filtering = Gtk.FileFilter()
filtering.add_pattern("*.kml")
kml = Gtk.FileChooserDialog(
_("Select a kml file used to add places"),
action=Gtk.FileChooserAction.OPEN,
parent=self.uistate.window,
buttons=(_('_Cancel'), Gtk.ResponseType.CANCEL,
_('_Apply'), Gtk.ResponseType.OK))
mpath = HOME_DIR
kml.set_current_folder(os.path.dirname(mpath))
kml.set_filter(filtering)
status = kml.run()
if status == Gtk.ResponseType.OK:
val = kml.get_filename()
if val:
kmlfile = Kml(val)
points = kmlfile.add_points()
for place in points:
(name, coords) = place
latlong = coords.pop()
(lat, lon) = latlong
place_name = PlaceName()
place_name.set_value(name)
new_place = Place()
new_place.set_name(place_name)
new_place.set_title(name)
new_place.set_latitude(str(lat))
new_place.set_longitude(str(lon))
try:
EditPlace(self.dbstate, self.uistate, [], new_place)
except WindowActiveError:
pass
kml.destroy()
示例14: __add_place
def __add_place(self, parent, plat, plon):
"""
Add a new place using longitude and latitude of location centered
on the map
"""
self.select_fct.close()
new_place = Place()
new_place.set_latitude(str(plat))
new_place.set_longitude(str(plon))
if parent:
placeref = PlaceRef()
placeref.ref = parent
new_place.add_placeref(placeref)
try:
EditPlace(self.dbstate, self.uistate, [], new_place)
self.add_marker(None, None, plat, plon, None, True, 0)
except WindowActiveError:
pass
示例15: __init__
def __init__(self, dbstate, uistate, clicked):
self.clicked_func = clicked
self.filter_id = widgets.BasicEntry()
self.filter_title = widgets.BasicEntry()
self.filter_name = widgets.BasicEntry()
self.filter_place = Place()
self.filter_place.set_type((PlaceType.CUSTOM, ''))
self.ptype = Gtk.ComboBox(has_entry=True)
self.place_menu = widgets.MonitoredDataType(
self.ptype,
self.filter_place.set_type,
self.filter_place.get_type)
self.filter_code = 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, "Place")