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


Python MenuItem.get_children方法代码示例

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


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

示例1: BuddyMenu

# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import get_children [as 别名]

#.........这里部分代码省略.........
        home_model = shell.get_model()
        self._active_activity_changed_hid = home_model.connect(
                'active-activity-changed', self._cur_activity_changed_cb)
        activity = home_model.get_active_activity()
        self._update_invite_menu(activity)

    def _add_my_items(self):
        item = MenuItem(_('Shutdown'), 'system-shutdown')
        item.connect('activate', self.__shutdown_activate_cb)
        self.menu.append(item)
        item.show()

        client = gconf.client_get_default()

        if client.get_bool('/desktop/sugar/show_restart'):
            item = MenuItem(_('Restart'), 'system-restart')
            item.connect('activate', self.__reboot_activate_cb)
            self.menu.append(item)
            item.show()

        if client.get_bool('/desktop/sugar/show_logout'):
            item = MenuItem(_('Logout'), 'system-logout')
            item.connect('activate', self.__logout_activate_cb)
            self.menu.append(item)
            item.show()

        item = MenuItem(_('My Settings'), 'preferences-system')
        item.connect('activate', self.__controlpanel_activate_cb)
        self.menu.append(item)
        item.show()

    def _quit(self, action):
        home_window = jarabe.desktop.homewindow.get_instance()
        home_window.busy_during_delayed_action(action)

    def __logout_activate_cb(self, menu_item):
        self._quit(get_session_manager().logout)

    def __reboot_activate_cb(self, menu_item):
        self._quit(get_session_manager().reboot)

    def __shutdown_activate_cb(self, menu_item):
        self._quit(get_session_manager().shutdown)

    def __controlpanel_activate_cb(self, menu_item):
        panel = ControlPanel()
        panel.set_transient_for(self.get_toplevel())
        panel.show()

    def _update_invite_menu(self, activity):
        buddy_activity = self._buddy.props.current_activity
        if buddy_activity is not None:
            buddy_activity_id = buddy_activity.activity_id
        else:
            buddy_activity_id = None

        if activity is None or activity.is_journal() or \
           activity.get_activity_id() == buddy_activity_id:
            self._invite_menu.hide()
        else:
            title = activity.get_title()
            label = self._invite_menu.get_children()[0]
            label.set_text(_('Invite to %s') % title)

            icon = Icon(file=activity.get_icon_path())
            icon.props.xo_color = activity.get_icon_color()
            self._invite_menu.set_image(icon)
            icon.show()

            self._invite_menu.show()

    def _cur_activity_changed_cb(self, home_model, activity_model):
        self._update_invite_menu(activity_model)

    def __buddy_notify_nick_cb(self, buddy, pspec):
        self.set_primary_text(glib.markup_escape_text(buddy.props.nick))

    def _make_friend_cb(self, menuitem):
        friends.get_model().make_friend(self._buddy)

    def _remove_friend_cb(self, menuitem):
        friends.get_model().remove(self._buddy)

    def _invite_friend_cb(self, menuitem):
        activity = shell.get_model().get_active_activity()
        service = activity.get_service()
        if service:
            try:
                service.InviteContact(self._buddy.props.account,
                                      self._buddy.props.contact_id)
            except dbus.DBusException, e:
                expected_exceptions = [
                        'org.freedesktop.DBus.Error.UnknownMethod',
                        'org.freedesktop.DBus.Python.NotImplementedError']
                if e.get_dbus_name() in expected_exceptions:
                    logging.warning('Trying deprecated Activity.Invite')
                    service.Invite(self._buddy.props.key)
                else:
                    raise
        else:
开发者ID:nemesiscodex,项目名称:JukyOS-sugar,代码行数:104,代码来源:buddymenu.py


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