当前位置: 首页>>代码示例>>Python>>正文


Python PlaceRef.ref方法代码示例

本文整理汇总了Python中gramps.gen.lib.PlaceRef.ref方法的典型用法代码示例。如果您正苦于以下问题:Python PlaceRef.ref方法的具体用法?Python PlaceRef.ref怎么用?Python PlaceRef.ref使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gramps.gen.lib.PlaceRef的用法示例。


在下文中一共展示了PlaceRef.ref方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __add_place

# 需要导入模块: from gramps.gen.lib import PlaceRef [as 别名]
# 或者: from gramps.gen.lib.PlaceRef import ref [as 别名]
 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
开发者ID:DaAwesomeP,项目名称:gramps,代码行数:30,代码来源:geography.py

示例2: __add_place

# 需要导入模块: from gramps.gen.lib import PlaceRef [as 别名]
# 或者: from gramps.gen.lib.PlaceRef import ref [as 别名]
 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)
         elif isinstance(parent, gi.overrides.Gtk.TreeModelRow):
             # We are here because we selected a place from geocoding
             # parent[0] : country
             # parent[1] : state
             # parent[2] : town
             # parent[3] : name
             value = PlaceSelection.untag_text(parent[2], 1)
             plname = PlaceName()
             plname.set_value(value)
             handle = self.place_exists(value)
             if handle:
                 # The town already exists. We create a place with name
                 placeref = PlaceRef()
                 placeref.ref = handle
                 new_place.add_placeref(placeref)
                 value = PlaceSelection.untag_text(parent[3], 1)
                 plname.set_value(value)
             new_place.set_name(plname)
         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
开发者ID:prculley,项目名称:gramps,代码行数:48,代码来源:geography.py

示例3: __get_places

# 需要导入模块: from gramps.gen.lib import PlaceRef [as 别名]
# 或者: from gramps.gen.lib.PlaceRef import ref [as 别名]
    def __get_places(self, obj):
        gov_id = self.entry.get_text()
        to_do = [gov_id]
        try:
            preferred_lang = config.get('preferences.place-lang')
        except AttributeError:
            fmt = config.get('preferences.place-format')
            pf = _pd.get_formats()[fmt]
            preferred_lang = pf.language
        if len(preferred_lang) != 2:
            preferred_lang = 'de'
        visited = {}

        type_dic = dict()
        type_url = 'http://gov.genealogy.net/types.owl/'
        response = urlopen(type_url)
        data = response.read()
        dom = parseString(data)
        for group in dom.getElementsByTagName('owl:Class') :
            url_value = group.attributes['rdf:about'].value
            group_number = 'j.0:' + url_value.split('#')[1]
            for element in dom.getElementsByTagName(group_number):
                type_number = element.attributes['rdf:about'].value.split('#')[1]
                for pname in element.getElementsByTagName('rdfs:label'):
                    type_lang = pname.attributes['xml:lang'].value
                    type_text = pname.childNodes[0].data
                    type_dic[type_number,type_lang] = type_text

        with DbTxn(_('Add GOV-id place %s') % gov_id, self.dbstate.db) as trans:
            while to_do:
                gov_id = to_do.pop()
                place = self.dbstate.db.get_place_from_gramps_id(gov_id)
                if place is not None:
                    visited[gov_id] = (place, [])
                else:
                    place, ref_list = self.__get_place(gov_id, type_dic, preferred_lang)
                    if place.get_name().get_value is not '':
                        self.dbstate.db.add_place(place, trans)
                        visited[gov_id] = (place, ref_list)
                        for ref, date in ref_list:
                            if (ref not in to_do) and (ref not in visited):
                                to_do.append(ref)

            for place, ref_list in visited.values():
                if len(ref_list) > 0:
                    for ref, date in ref_list:
                        handle = visited[ref][0].handle
                        place_ref = PlaceRef()
                        place_ref.ref = handle
                        place_ref.set_date_object(date)
                        place.add_placeref(place_ref)
                    self.dbstate.db.commit_place(place, trans)
开发者ID:daleathan,项目名称:addons-source,代码行数:54,代码来源:getgov.py

示例4: __edit_place

# 需要导入模块: from gramps.gen.lib import PlaceRef [as 别名]
# 或者: from gramps.gen.lib.PlaceRef import ref [as 别名]
 def __edit_place(self, parent, plat, plon):
     """
     Edit the selected place at the marker position
     """
     self.select_fct.close()
     place = self.dbstate.db.get_place_from_gramps_id(self.mark[9])
     place.set_latitude(str(plat))
     place.set_longitude(str(plon))
     if parent:
         placeref = PlaceRef()
         placeref.ref = parent
         place.add_placeref(placeref)
     try:
         EditPlace(self.dbstate, self.uistate, [], place)
     except WindowActiveError:
         pass
开发者ID:aignas,项目名称:gramps,代码行数:18,代码来源:geography.py

示例5: __add_place

# 需要导入模块: from gramps.gen.lib import PlaceRef [as 别名]
# 或者: from gramps.gen.lib.PlaceRef import ref [as 别名]
 def __add_place(self, name, type_num, parent, title, trans):
     """
     Add a missing place to the database.
     """
     place = Place()
     place_name = PlaceName()
     place_name.set_value(name)
     place.name = place_name
     place.title = title
     place.place_type = PlaceType(7-type_num)
     if parent is not None:
         placeref = PlaceRef()
         placeref.ref = handle2internal(parent)
         place.set_placeref_list([placeref])
     handle = self.db.add_place(place, trans)
     self.db.commit_place(place, trans)
     return handle
开发者ID:nblock,项目名称:gramps,代码行数:19,代码来源:libplaceimport.py

示例6: _parse_place

# 需要导入模块: from gramps.gen.lib import PlaceRef [as 别名]
# 或者: from gramps.gen.lib.PlaceRef import ref [as 别名]
 def _parse_place(self, line_number, row, col):
     "Parse the content of a Place line."
     place_id = rd(line_number, row, col, "place")
     place_title = rd(line_number, row, col, "title")
     place_name = rd(line_number, row, col, "name")
     place_type_str = rd(line_number, row, col, "type")
     place_latitude = rd(line_number, row, col, "latitude")
     place_longitude = rd(line_number, row, col, "longitude")
     place_code = rd(line_number, row, col, "code")
     place_enclosed_by_id = rd(line_number, row, col, "enclosed_by")
     place_date = rd(line_number, row, col, "date")
     #########################################################
     # if this place already exists, don't create it
     place = self.lookup("place", place_id)
     if place is None:
         # new place
         place = self.create_place()
         if place_id is not None:
             if place_id.startswith("[") and place_id.endswith("]"):
                 place.gramps_id = self.db.pid2user_format(place_id[1:-1])
             self.storeup("place", place_id, place)
     if place_title is not None:
         place.title = place_title
     if place_name is not None:
         place.name = PlaceName(value=place_name)
     if place_type_str is not None:
         place.place_type = self.get_place_type(place_type_str)
     if place_latitude is not None:
         place.lat = place_latitude
     if place_longitude is not None:
         place.long = place_longitude
     if place_code is not None:
         place.code = place_code
     if place_enclosed_by_id is not None:
         place_enclosed_by = self.lookup("place", place_enclosed_by_id)
         if place_enclosed_by is None:
             raise Exception("cannot enclose %s in %s as it doesn't exist" % (place.gramps_id, place_enclosed_by_id))
         if not place_enclosed_by.handle in place.placeref_list:
             placeref = PlaceRef()
             placeref.ref = place_enclosed_by.handle
             if place_date:
                 placeref.date = _dp.parse(place_date)
             place.placeref_list.append(placeref)
     #########################################################
     self.db.commit_place(place, self.trans)
开发者ID:SNoiraud,项目名称:gramps,代码行数:47,代码来源:importcsv.py

示例7: __add_place

# 需要导入模块: from gramps.gen.lib import PlaceRef [as 别名]
# 或者: from gramps.gen.lib.PlaceRef import ref [as 别名]
 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
开发者ID:aignas,项目名称:gramps,代码行数:20,代码来源:geography.py

示例8: add

# 需要导入模块: from gramps.gen.lib import PlaceRef [as 别名]
# 或者: from gramps.gen.lib.PlaceRef import ref [as 别名]
    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
开发者ID:ondrokrc,项目名称:gramps,代码行数:20,代码来源:placetreeview.py

示例9: __get_places

# 需要导入模块: from gramps.gen.lib import PlaceRef [as 别名]
# 或者: from gramps.gen.lib.PlaceRef import ref [as 别名]
    def __get_places(self, _obj):
        gov_id = self.entry.get_text()
        to_do = [gov_id]
        try:
            preferred_lang = config.get('preferences.place-lang')
        except AttributeError:
            fmt = config.get('preferences.place-format')
            pf = _pd.get_formats()[fmt]
            preferred_lang = pf.language
        if len(preferred_lang) != 2:
            preferred_lang = glocale.lang
        visited = {}

        if not self.type_dic:
            self.__get_types()

        with DbTxn(_('Add GOV-id place %s') % gov_id,
                   self.dbstate.db) as trans:
            while to_do:
                gov_id = to_do.pop()
                place = self.dbstate.db.get_place_from_gramps_id(gov_id)
                if place is not None:
                    visited[gov_id] = (place, [])
                else:
                    place, ref_list = self.__get_place(gov_id, self.type_dic,
                                                       preferred_lang)
                    if place.get_name().get_value is not '':
                        self.dbstate.db.add_place(place, trans)
                        visited[gov_id] = (place, ref_list)
                        for ref, date in ref_list:
                            if (ref not in to_do) and (ref not in visited):
                                to_do.append(ref)

            for place, ref_list in visited.values():
                if len(ref_list) > 0:
                    for ref, date in ref_list:
                        handle = visited[ref][0].handle
                        place_ref = PlaceRef()
                        place_ref.ref = handle
                        place_ref.set_date_object(date)
                        place.add_placeref(place_ref)
                    self.dbstate.db.commit_place(place, trans)
        self.dbstate.db.save_place_types()
开发者ID:gramps-project,项目名称:addons-source,代码行数:45,代码来源:getgov.py

示例10: __link_place

# 需要导入模块: from gramps.gen.lib import PlaceRef [as 别名]
# 或者: from gramps.gen.lib.PlaceRef import ref [as 别名]
 def __link_place(self, parent, plat, plon):
     """
     Link an existing place using longitude and latitude of location centered
     on the map
     """
     selector = SelectPlace(self.dbstate, self.uistate, [])
     place = selector.run()
     if place:
         self.select_fct.close()
         place.set_latitude(str(plat))
         place.set_longitude(str(plon))
         if parent:
             placeref = PlaceRef()
             placeref.ref = parent
             place.add_placeref(placeref)
         try:
             EditPlace(self.dbstate, self.uistate, [], place)
             self.add_marker(None, None, plat, plon, None, True, 0)
         except WindowActiveError:
             pass
开发者ID:aignas,项目名称:gramps,代码行数:22,代码来源:geography.py

示例11: generate_hierarchy

# 需要导入模块: from gramps.gen.lib import PlaceRef [as 别名]
# 或者: from gramps.gen.lib.PlaceRef import ref [as 别名]
    def generate_hierarchy(self, trans):
        """
        Generate missing places in the place hierarchy.
        """
        for handle, location in self.handle2loc.items():

            # find title and type
            for type_num, name in enumerate(location):
                if name:
                    break

            loc = list(location)
            loc[type_num] = ''

            # find top parent
            parent = None
            for n in range(7):
                if loc[n]:
                    tup = tuple([''] * n + loc[n:])
                    parent = self.loc2handle.get(tup)
                    if parent:
                        break

            # create missing parent places
            if parent:
                n -= 1
            while n > type_num:
                if loc[n]:
                    # TODO for Arabic, should the next comma be translated?
                    title = ', '.join([item for item in loc[n:] if item])
                    parent = self.__add_place(loc[n], n, parent, title, trans)
                    self.loc2handle[tuple([''] * n + loc[n:])] = parent
                n -= 1

            # link to existing place
            if parent:
                place = self.db.get_place_from_handle(handle)
                placeref = PlaceRef()
                placeref.ref = parent
                place.set_placeref_list([placeref])
                self.db.commit_place(place, trans, place.get_change_time())
开发者ID:SNoiraud,项目名称:gramps,代码行数:43,代码来源:libplaceimport.py


注:本文中的gramps.gen.lib.PlaceRef.ref方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。