本文整理汇总了Python中sugar3.graphics.palettemenu.PaletteMenuItem.set_image方法的典型用法代码示例。如果您正苦于以下问题:Python PaletteMenuItem.set_image方法的具体用法?Python PaletteMenuItem.set_image怎么用?Python PaletteMenuItem.set_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar3.graphics.palettemenu.PaletteMenuItem
的用法示例。
在下文中一共展示了PaletteMenuItem.set_image方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
def __init__(self):
ToolButton.__init__(self)
self._property = 'timestamp'
self._order = Gtk.SortType.ASCENDING
self.props.tooltip = _('Sort view')
self.props.icon_name = 'view-lastedit'
self.props.hide_tooltip_on_click = False
self.palette_invoker.props.toggle_palette = True
menu_box = PaletteMenuBox()
self.props.palette.set_content(menu_box)
menu_box.show()
for property_, icon, label in self._SORT_OPTIONS:
button = PaletteMenuItem(label)
button_icon = Icon(icon_size=Gtk.IconSize.MENU, icon_name=icon)
button.set_image(button_icon)
button_icon.show()
button.connect('activate',
self.__sort_type_changed_cb,
property_,
icon)
button.show()
menu_box.append_item(button)
示例2: create_palette
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
def create_palette(self):
primary_text = GLib.markup_escape_text(self._model.bundle.get_name())
secondary_text = GLib.markup_escape_text(self._model.get_name())
palette_icon = Icon(file=self._model.bundle.get_icon(),
xo_color=self._model.get_color())
palette_icon.props.icon_size = Gtk.IconSize.LARGE_TOOLBAR
palette = Palette(None,
primary_text=primary_text,
secondary_text=secondary_text,
icon=palette_icon)
private = self._model.props.private
joined = get_owner_instance() in self._model.props.buddies
menu_box = PaletteMenuBox()
if joined:
item = PaletteMenuItem(_('Resume'))
icon = Icon(icon_size=Gtk.IconSize.MENU, icon_name='activity-start')
item.set_image(icon)
item.connect('activate', self.__palette_item_clicked_cb)
menu_box.append_item(item)
elif not private:
item = PaletteMenuItem(_('Join'))
icon = Icon(icon_size=Gtk.IconSize.MENU, icon_name='activity-start')
item.set_image(icon)
item.connect('activate', self.__palette_item_clicked_cb)
menu_box.append_item(item)
palette.set_content(menu_box)
menu_box.show_all()
self.connect_to_palette_pop_events(palette)
return palette
示例3: __init__
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
def __init__(self):
ToolButton.__init__(self)
self._property = 'timestamp'
self._order = Gtk.SortType.ASCENDING
self.props.tooltip = _('Sort view')
self.props.icon_name = 'view-lastedit'
self.props.hide_tooltip_on_click = False
self.palette_invoker.props.toggle_palette = True
menu_box = PaletteMenuBox()
self.props.palette.set_content(menu_box)
menu_box.show()
sort_options = [
('timestamp', 'view-lastedit', _('Sort by date modified')),
('creation_time', 'view-created', _('Sort by date created')),
('filesize', 'view-size', _('Sort by size')),
]
for property_, icon, label in sort_options:
button = PaletteMenuItem(label)
button_icon = Icon(pixel_size=style.SMALL_ICON_SIZE,
icon_name=icon)
button.set_image(button_icon)
button_icon.show()
button.connect('activate',
self.__sort_type_changed_cb,
property_,
icon)
button.show()
menu_box.append_item(button)
示例4: DisplayPalette
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
class DisplayPalette(Palette):
def __init__(self):
Palette.__init__(self, label=_('My Display'))
self._screenshot = PaletteMenuItem(_('Take a screenshot'))
icon = Icon(icon_name='camera-external',
pixel_size=style.SMALL_ICON_SIZE)
self._screenshot.set_image(icon)
icon.show()
self._screenshot.connect('activate', self.__screenshot_cb)
self._screenshot.show()
self._box = PaletteMenuBox()
self._brightness_manager = None
# only add this widget if device available
if brightness.get_instance().get_path():
self._add_brightness_manager()
self._box.append_item(self._screenshot, 0, 0)
self._box.show()
self.set_content(self._box)
self.connect('popup', self.__popup_cb)
def _add_brightness_manager(self):
self._brightness_manager = BrightnessManagerWidget(_('Brightness'),
'brightness-100')
self._brightness_manager.show()
separator = PaletteMenuItemSeparator()
separator.show()
self._box.append_item(self._brightness_manager, 0, 0)
self._box.append_item(separator, 0, 0)
def __popup_cb(self, palette):
if self._brightness_manager is not None:
self._brightness_manager.update()
def __screenshot_cb(self, palette):
frame_ = frame.get_view()
frame_.hide()
GObject.idle_add(self.__take_screenshot_cb, frame_)
def __take_screenshot_cb(self, frame_):
if frame_.is_visible():
return True
take_screenshot()
frame_.show()
return False
示例5: set_palette_list
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
def set_palette_list(palette_list, nx, ny, item_height, return_dict=False):
palette_dict = {}
item_width = style.GRID_CELL_SIZE * 3
grid = Gtk.Grid()
grid.set_row_spacing(style.DEFAULT_PADDING)
grid.set_column_spacing(0)
grid.set_border_width(0)
scrolled_window = Gtk.ScrolledWindow()
scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
scrolled_window.set_size_request(nx * item_width, ny * item_height)
scrolled_window.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
scrolled_window.add_with_viewport(grid)
grid.show()
x = 0
y = 0
for item in palette_list:
menu_item = PaletteMenuItem()
menu_item.set_label(item['label'])
menu_item.set_image(item['icon'])
item['icon'].show()
if return_dict:
menu_item.set_image(item['selected'])
item['selected'].hide()
if return_dict:
palette_dict[item['label']] = {'menu': menu_item,
'icon': item['icon'],
'selected': item['selected']}
menu_item.connect('button-release-event', item['callback'],
item['label'])
grid.attach(menu_item, x, y, 1, 1)
x += 1
if x == nx:
x = 0
y += 1
menu_item.show()
if return_dict:
return scrolled_window, palette_dict
else:
return scrolled_window
示例6: create_palette
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
def create_palette(self):
palette = VolumePalette(self._mount)
palette.set_group_id('frame')
menu_item = PaletteMenuItem(_('Show contents'))
color = profile.get_color()
icon = Icon(icon_name=self._icon_name, icon_size=Gtk.IconSize.MENU,
xo_color=color)
menu_item.set_image(icon)
icon.show()
menu_item.connect('activate', self.__show_contents_cb)
palette.content_box.pack_start(menu_item, True, True, 0)
palette.content_box.reorder_child(menu_item, 0)
menu_item.show()
return palette
示例7: create_palette
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
def create_palette(self):
palette = VolumePalette(self._mount)
palette.set_group_id('frame')
menu_item = PaletteMenuItem(_('Show contents'))
client = GConf.Client.get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color'))
icon = Icon(icon_name=self._icon_name, icon_size=Gtk.IconSize.MENU,
xo_color=color)
menu_item.set_image(icon)
icon.show()
menu_item.connect('activate', self.__show_contents_cb)
palette.content_box.pack_start(menu_item, True, True, 0)
palette.content_box.reorder_child(menu_item, 0)
menu_item.show()
return palette
示例8: create_palette
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
def create_palette(self):
palette = VolumePalette(self._mount)
palette.set_group_id('frame')
menu_item = PaletteMenuItem(_('Show contents'))
color = get_mount_color(self._mount)
icon = Icon(icon_name=self._icon_name,
pixel_size=style.SMALL_ICON_SIZE,
xo_color=color)
menu_item.set_image(icon)
icon.show()
menu_item.connect('activate', self.__show_contents_cb)
palette.content_box.pack_start(menu_item, True, True, 0)
palette.content_box.reorder_child(menu_item, 0)
menu_item.show()
return palette
示例9: __init__
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
def __init__(self, mount):
Palette.__init__(self, label=mount.get_name())
self._mount = mount
path = mount.get_root().get_path()
self.props.secondary_text = glib.markup_escape_text(path)
self.content_box = PaletteMenuBox()
self.set_content(self.content_box)
self.content_box.show()
menu_item = PaletteMenuItem(pgettext('Volume', 'Remove'))
icon = Icon(icon_name='media-eject', icon_size=Gtk.IconSize.MENU)
menu_item.set_image(icon)
icon.show()
menu_item.connect('activate', self.__unmount_activate_cb)
self.content_box.append_item(menu_item)
menu_item.show()
separator = PaletteMenuItemSeparator()
self.content_box.append_item(separator)
separator.show()
free_space_box = Gtk.VBox()
free_space_box.set_spacing(style.DEFAULT_PADDING)
self.content_box.append_item(free_space_box, vertical_padding=0)
free_space_box.show()
self._progress_bar = Gtk.ProgressBar()
free_space_box.pack_start(self._progress_bar, True, True, 0)
self._progress_bar.show()
self._free_space_label = Gtk.Label()
self._free_space_label.set_alignment(0.5, 0.5)
free_space_box.pack_start(self._free_space_label, True, True, 0)
self._free_space_label.show()
self.connect('popup', self.__popup_cb)
示例10: setup_palette
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
def setup_palette(self):
title = self._home_activity.get_title()
self.set_primary_text(GLib.markup_escape_text(title))
box = PaletteMenuBox()
self.set_content(box)
box.show()
menu_item = PaletteMenuItem(_("Show contents"))
icon = Icon(
file=self._home_activity.get_icon_path(),
pixel_size=style.SMALL_ICON_SIZE,
xo_color=self._home_activity.get_icon_color(),
)
menu_item.set_image(icon)
icon.show()
menu_item.connect("activate", self.__open_activate_cb)
box.append_item(menu_item)
menu_item.show()
separator = PaletteMenuItemSeparator()
box.append_item(separator)
separator.show()
inner_box = Gtk.VBox()
inner_box.set_spacing(style.DEFAULT_PADDING)
box.append_item(inner_box, vertical_padding=0)
inner_box.show()
self._progress_bar = Gtk.ProgressBar()
inner_box.add(self._progress_bar)
self._progress_bar.show()
self._free_space_label = Gtk.Label()
self._free_space_label.set_alignment(0.5, 0.5)
inner_box.add(self._free_space_label)
self._free_space_label.show()
self.connect("popup", self.__popup_cb)
示例11: create_palette
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
def create_palette(self):
primary_text = self._model.bundle.get_name()
secondary_text = self._model.get_name()
palette_icon = Icon(file=self._model.bundle.get_icon(),
pixel_size=style.STANDARD_ICON_SIZE,
xo_color=self._model.get_color())
palette = Palette(None,
primary_text=primary_text,
secondary_text=secondary_text,
icon=palette_icon)
private = self._model.props.private
joined = get_owner_instance() in self._model.props.buddies
is_joinable = self._is_joinable is None or self._is_joinable()
menu_box = PaletteMenuBox()
if joined:
item = PaletteMenuItem(_('Resume'))
icon = Icon(
pixel_size=style.SMALL_ICON_SIZE, icon_name='activity-start')
item.set_image(icon)
item.connect('activate', self.__palette_item_clicked_cb)
menu_box.append_item(item)
elif not private and is_joinable:
item = PaletteMenuItem(_('Join'))
icon = Icon(
pixel_size=style.SMALL_ICON_SIZE, icon_name='activity-start')
item.set_image(icon)
item.connect('activate', self.__palette_item_clicked_cb)
menu_box.append_item(item)
palette.set_content(menu_box)
menu_box.show_all()
self.connect_to_palette_pop_events(palette)
return palette
示例12: GsmPalette
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
class GsmPalette(Palette):
__gtype_name__ = 'SugarGsmPalette'
__gsignals__ = {
'gsm-connect': (GObject.SignalFlags.RUN_FIRST, None, ([])),
'gsm-disconnect': (GObject.SignalFlags.RUN_FIRST, None, ([])),
}
def __init__(self):
Palette.__init__(self, primary_text=_('Wireless modem'))
self._current_state = None
self._failed_connection = False
self.info_box = Gtk.VBox()
self._toggle_state_item = PaletteMenuItem('')
self._toggle_state_item.connect('activate', self.__toggle_state_cb)
self.info_box.pack_start(self._toggle_state_item, True, True, 0)
self._toggle_state_item.show()
self.error_title_label = Gtk.Label(label="")
self.error_title_label.set_alignment(0, 0.5)
self.error_title_label.set_line_wrap(True)
self.info_box.pack_start(self.error_title_label, True, True, 0)
self.error_description_label = Gtk.Label(label="")
self.error_description_label.set_alignment(0, 0.5)
self.error_description_label.set_line_wrap(True)
self.info_box.pack_start(self.error_description_label, True, True, 0)
self.connection_info_box = Gtk.HBox()
icon = Icon(icon_name='data-upload',
pixel_size=style.SMALL_ICON_SIZE)
self.connection_info_box.pack_start(icon, True, True, 0)
icon.show()
self._data_label_up = Gtk.Label()
self._data_label_up.props.xalign = 0.0
label_alignment = self._add_widget_with_padding(self._data_label_up)
self.connection_info_box.pack_start(label_alignment, True, True, 0)
self._data_label_up.show()
label_alignment.show()
icon = Icon(icon_name='data-download',
pixel_size=style.SMALL_ICON_SIZE)
self.connection_info_box.pack_start(icon, True, True, 0)
icon.show()
self._data_label_down = Gtk.Label()
self._data_label_down.props.xalign = 0.0
label_alignment = self._add_widget_with_padding(self._data_label_down)
self.connection_info_box.pack_start(label_alignment, True, True, 0)
self._data_label_down.show()
label_alignment.show()
self.info_box.pack_start(self.connection_info_box, True, True, 0)
self.info_box.show()
self.set_content(self.info_box)
self.update_state(_GSM_STATE_NOT_READY)
def _add_widget_with_padding(self, child, xalign=0, yalign=0.5):
alignment = Gtk.Alignment.new(xalign=xalign, yalign=yalign,
xscale=1, yscale=0.33)
alignment.set_padding(style.DEFAULT_SPACING,
style.DEFAULT_SPACING,
style.DEFAULT_SPACING,
style.DEFAULT_SPACING)
alignment.add(child)
return alignment
def update_state(self, state, reason=0):
self._current_state = state
self._update_label_and_text(reason)
def _update_label_and_text(self, reason=0):
if self._current_state == _GSM_STATE_NOT_READY:
self._toggle_state_item.set_label('...')
self.props.secondary_text = _('Please wait...')
elif self._current_state == _GSM_STATE_DISCONNECTED:
if not self._failed_connection:
self._toggle_state_item.set_label(_('Connect'))
self.props.secondary_text = _('Disconnected')
icon = Icon(icon_name='dialog-ok',
pixel_size=style.SMALL_ICON_SIZE)
self._toggle_state_item.set_image(icon)
elif self._current_state == _GSM_STATE_CONNECTING:
self._toggle_state_item.set_label(_('Cancel'))
self.props.secondary_text = _('Connecting...')
icon = Icon(icon_name='dialog-cancel',
pixel_size=style.SMALL_ICON_SIZE)
self._toggle_state_item.set_image(icon)
elif self._current_state == _GSM_STATE_CONNECTED:
self._failed_connection = False
self._toggle_state_item.set_label(_('Disconnect'))
self.update_connection_time()
icon = Icon(icon_name='media-eject',
#.........这里部分代码省略.........
示例13: WirelessPalette
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
class WirelessPalette(Palette):
__gtype_name__ = 'SugarWirelessPalette'
__gsignals__ = {
'deactivate-connection': (GObject.SignalFlags.RUN_FIRST, None,
([])),
}
def __init__(self, primary_text):
Palette.__init__(self, label=primary_text)
self._disconnect_item = None
self._channel_label = Gtk.Label()
self._channel_label.props.xalign = 0.0
self._channel_label.show()
self._ip_address_label = Gtk.Label()
self._ip_address_label.props.xalign = 0.0
self._ip_address_label.show()
self._info = Gtk.VBox()
self._disconnect_item = PaletteMenuItem(_('Disconnect'))
icon = Icon(pixel_size=style.SMALL_ICON_SIZE,
icon_name='media-eject')
self._disconnect_item.set_image(icon)
self._disconnect_item.connect('activate',
self.__disconnect_activate_cb)
self._info.add(self._disconnect_item)
separator = PaletteMenuItemSeparator()
self._info.pack_start(separator, True, True, 0)
def _padded(child, xalign=0, yalign=0.5):
padder = Gtk.Alignment.new(xalign=xalign, yalign=yalign,
xscale=1, yscale=0.33)
padder.set_padding(style.DEFAULT_SPACING,
style.DEFAULT_SPACING,
style.DEFAULT_SPACING,
style.DEFAULT_SPACING)
padder.add(child)
return padder
self._info.pack_start(_padded(self._channel_label), True, True, 0)
self._info.pack_start(_padded(self._ip_address_label), True, True, 0)
self._info.show_all()
def set_connecting(self):
self.props.secondary_text = _('Connecting...')
def _set_connected(self, iaddress):
self.set_content(self._info)
self.props.secondary_text = _('Connected')
self._set_ip_address(iaddress)
self._disconnect_item.show()
def set_connected_with_frequency(self, frequency, iaddress):
self._set_connected(iaddress)
self._set_frequency(frequency)
def set_connected_with_channel(self, channel, iaddress):
self._set_connected(iaddress)
self._set_channel(channel)
def set_disconnected(self):
self.props.primary_text = _('No wireless connection')
self.props.secondary_text = ''
self._disconnect_item.hide()
self.set_content(None)
def __disconnect_activate_cb(self, menuitem):
self.emit('deactivate-connection')
def _set_frequency(self, frequency):
channel = network.frequency_to_channel(frequency)
self._set_channel(channel)
def _set_channel(self, channel):
if channel == 0:
self._channel_label.set_text('%s: %s' % (_('Channel'),
_('Unknown')))
else:
self._channel_label.set_text('%s: %d' % (_('Channel'),
channel))
def _set_ip_address(self, ip_address):
if ip_address is not None:
ip_address_text = IP_ADDRESS_TEXT_TEMPLATE % ip_address
else:
ip_address_text = ""
self._ip_address_label.set_text(ip_address_text)
示例14: OlpcMeshView
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
class OlpcMeshView(EventPulsingIcon):
def __init__(self, mesh_mgr, channel):
EventPulsingIcon.__init__(self, icon_name=_OLPC_MESH_ICON_NAME,
pixel_size=style.STANDARD_ICON_SIZE,
cache=True)
self._bus = dbus.SystemBus()
self._channel = channel
self._mesh_mgr = mesh_mgr
self._disconnect_item = None
self._connect_item = None
self._filtered = False
self._device_state = None
self._active = False
device = mesh_mgr.mesh_device
interface_props = dbus.Interface(device, dbus.PROPERTIES_IFACE)
interface_props.Get(network.NM_DEVICE_IFACE, 'State',
reply_handler=self.__get_device_state_reply_cb,
error_handler=self.__get_device_state_error_cb)
interface_props.Get(network.NM_OLPC_MESH_IFACE, 'ActiveChannel',
reply_handler=self.__get_active_channel_reply_cb,
error_handler=self.__get_active_channel_error_cb)
self._bus.add_signal_receiver(self.__device_state_changed_cb,
signal_name='StateChanged',
path=device.object_path,
dbus_interface=network.NM_DEVICE_IFACE)
self._bus.add_signal_receiver(
self.__wireless_properties_changed_cb,
signal_name='PropertiesChanged',
path=device.object_path,
dbus_interface=network.NM_OLPC_MESH_IFACE)
pulse_color = XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(),
style.COLOR_TRANSPARENT.get_svg()))
self.props.pulse_color = pulse_color
self.props.base_color = profile.get_color()
self.palette_invoker.props.toggle_palette = True
self._palette = self._create_palette()
self.set_palette(self._palette)
def _create_palette(self):
_palette = palette.Palette(_('Mesh Network %d') % (self._channel, ))
self.menu_box = Gtk.VBox()
self._connect_item = PaletteMenuItem(_('Connect'))
icon = Icon(pixel_size=style.SMALL_ICON_SIZE, icon_name='dialog-ok')
self._connect_item.set_image(icon)
self._connect_item.connect('activate', self.__connect_activate_cb)
self.menu_box.add(self._connect_item)
_palette.set_content(self.menu_box)
self.menu_box.show_all()
return _palette
def __get_device_state_reply_cb(self, state):
self._device_state = state
self._update()
def __get_device_state_error_cb(self, err):
logging.error('Error getting the device state: %s', err)
def __device_state_changed_cb(self, new_state, old_state, reason):
self._device_state = new_state
self._update()
self._update_color()
def __get_active_channel_reply_cb(self, channel):
self._active = (channel == self._channel)
self._update()
def __get_active_channel_error_cb(self, err):
logging.error('Error getting the active channel: %s', err)
def __wireless_properties_changed_cb(self, properties):
if 'ActiveChannel' in properties:
channel = properties['ActiveChannel']
self._active = (channel == self._channel)
self._update()
def _update(self):
if self._active:
state = self._device_state
else:
state = network.NM_DEVICE_STATE_UNKNOWN
if state in [network.NM_DEVICE_STATE_PREPARE,
network.NM_DEVICE_STATE_CONFIG,
network.NM_DEVICE_STATE_NEED_AUTH,
network.NM_DEVICE_STATE_IP_CONFIG]:
if self._disconnect_item:
self._disconnect_item.show()
self._connect_item.hide()
self._palette.props.secondary_text = _('Connecting...')
self.props.pulsing = True
elif state == network.NM_DEVICE_STATE_ACTIVATED:
if self._disconnect_item:
#.........这里部分代码省略.........
示例15: BuddyMenu
# 需要导入模块: from sugar3.graphics.palettemenu import PaletteMenuItem [as 别名]
# 或者: from sugar3.graphics.palettemenu.PaletteMenuItem import set_image [as 别名]
#.........这里部分代码省略.........
self.menu_box.pack_start(item, True, True, 0)
item.show()
item = PaletteMenuItem(_("My Settings"), "preferences-system")
item.connect("activate", self.__controlpanel_activate_cb)
self.menu_box.pack_start(item, True, True, 0)
item.show()
def _quit(self, action):
jarabe.desktop.homewindow.get_instance().busy()
action()
GObject.timeout_add_seconds(3, self.__quit_timeout_cb)
def __quit_timeout_cb(self):
jarabe.desktop.homewindow.get_instance().unbusy()
alert = TimeoutAlert(30)
alert.props.title = _("An activity is not responding.")
alert.props.msg = _("You may lose unsaved work if you continue.")
alert.connect("response", self.__quit_accept_cb)
jarabe.desktop.homewindow.get_instance().add_alert(alert)
alert.show()
def __quit_accept_cb(self, alert, response_id):
jarabe.desktop.homewindow.get_instance().remove_alert(alert)
if response_id is Gtk.ResponseType.CANCEL:
get_session_manager().cancel_shutdown()
else:
jarabe.desktop.homewindow.get_instance().busy()
get_session_manager().shutdown_completed()
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):
# hide the frame when control panel is shown
import jarabe.frame
frame = jarabe.frame.get_view()
frame.hide()
# show the control panel
panel = ControlPanel()
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()
self._invite_menu.set_label(_("Invite to %s") % title)
icon = Icon(file=activity.get_icon_path(), pixel_size=style.SMALL_ICON_SIZE)
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(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: