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


Python ListModel.get_selected_objects方法代码示例

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


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

示例1: MediaBrowser

# 需要导入模块: from gramps.gui.listmodel import ListModel [as 别名]
# 或者: from gramps.gui.listmodel.ListModel import get_selected_objects [as 别名]
class MediaBrowser(Gramplet):
    """
    Displays an object tree and a media preview for a person.
    """

    def init(self):
        self.gui.WIDGET = self.build_gui()
        self.gui.get_container_widget().remove(self.gui.textview)
        self.gui.get_container_widget().add_with_viewport(self.gui.WIDGET)
        self.gui.WIDGET.show()

    def build_gui(self):
        """
        Build the GUI interface.
        """
        top = Gtk.HBox()
        self.photo = Photo()
        self.photo.show()
        view = Gtk.TreeView()
        titles = [(_("Object"), 1, 250)]
        self.model = ListModel(view, titles, list_mode="tree", select_func=self.row_selected)
        top.pack_start(view, True, True, 0)
        top.pack_start(self.photo, True, False, 5)
        top.show_all()
        return top

    def db_changed(self):
        self.dbstate.db.connect("person-update", self.update)
        self.update()

    def active_changed(self, handle):
        self.update()

    def update_has_data(self):
        active_handle = self.get_active("Person")
        active = self.dbstate.db.get_person_from_handle(active_handle)
        self.set_has_data(self.get_has_data(active))

    def main(self):
        active_handle = self.get_active("Person")
        active = self.dbstate.db.get_person_from_handle(active_handle)

        self.model.clear()
        self.photo.set_image(None)
        if active:
            self.display_data(active)
        else:
            self.set_has_data(False)

    def display_data(self, person):
        """
        Display the object tree for the active person.
        """
        self.add_media(person)
        self.add_events(person)
        self.add_sources(person)
        self.set_has_data(self.model.count > 0)

    def add_events(self, obj, parent_node=None):
        """
        Add event nodes to the model.
        """
        for event_ref in obj.get_event_ref_list():
            handle = event_ref.ref
            name, event = navigation_label(self.dbstate.db, "Event", handle)
            node = self.model.add([name], node=parent_node)
            self.add_sources(event, node)
            self.add_media(event, node)

    def add_sources(self, obj, parent_node=None):
        """
        Add source nodes to the model.
        """
        for citation_handle in obj.get_citation_list():
            citation = self.dbstate.db.get_citation_from_handle(citation_handle)
            handle = citation.get_reference_handle()
            name, src = navigation_label(self.dbstate.db, "Source", handle)
            node = self.model.add([name], node=parent_node)
            self.add_media(src, node)

    def add_media(self, obj, parent_node=None):
        """
        Add media object nodes to the model.
        """
        for media_ref in obj.get_media_list():
            handle = media_ref.ref
            name, media = navigation_label(self.dbstate.db, "Media", handle)
            full_path = media_path_full(self.dbstate.db, media.get_path())
            rect = media_ref.get_rectangle()
            self.model.add([name], info=media_ref, node=parent_node)

    def row_selected(self, selection):
        """
        Change the image when a row is selected.
        """
        selected = self.model.get_selected_objects()
        if selected:
            if selected[0]:
                self.load_image(selected[0])
            else:
#.........这里部分代码省略.........
开发者ID:killes,项目名称:addons-source,代码行数:103,代码来源:MediaBrowser.py


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