本文整理汇总了Python中sugar.graphics.menuitem.MenuItem.set_image方法的典型用法代码示例。如果您正苦于以下问题:Python MenuItem.set_image方法的具体用法?Python MenuItem.set_image怎么用?Python MenuItem.set_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sugar.graphics.menuitem.MenuItem
的用法示例。
在下文中一共展示了MenuItem.set_image方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import set_image [as 别名]
def __init__(self, file_name, document_path, title):
RadioToolButton.__init__(self)
self._document_path = document_path
self._title = title
self._jobject = None
self.props.tooltip = _('Instance Source')
client = gconf.client_get_default()
self._color = client.get_string('/desktop/sugar/user/color')
icon = Icon(file=file_name,
icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR,
xo_color=XoColor(self._color))
self.set_icon_widget(icon)
icon.show()
menu_item = MenuItem(_('Keep'))
icon = Icon(icon_name='document-save', icon_size=gtk.ICON_SIZE_MENU,
xo_color=XoColor(self._color))
menu_item.set_image(icon)
menu_item.connect('activate', self.__keep_in_journal_cb)
self.props.palette.menu.append(menu_item)
menu_item.show()
示例2: setup_palette
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import set_image [as 别名]
def setup_palette(self):
title = self._home_activity.get_title()
self.set_primary_text(glib.markup_escape_text(title))
vbox = gtk.VBox()
self.set_content(vbox)
vbox.show()
self._progress_bar = gtk.ProgressBar()
vbox.add(self._progress_bar)
self._progress_bar.show()
self._free_space_label = gtk.Label()
self._free_space_label.set_alignment(0.5, 0.5)
vbox.add(self._free_space_label)
self._free_space_label.show()
self.connect('popup', self.__popup_cb)
menu_item = MenuItem(_('Show contents'))
icon = Icon(file=self._home_activity.get_icon_path(),
icon_size=gtk.ICON_SIZE_MENU,
xo_color=self._home_activity.get_icon_color())
menu_item.set_image(icon)
icon.show()
menu_item.connect('activate', self.__open_activate_cb)
self.menu.append(menu_item)
menu_item.show()
示例3: __init__
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem 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)
vbox = gtk.VBox()
self.set_content(vbox)
vbox.show()
self._progress_bar = gtk.ProgressBar()
vbox.add(self._progress_bar)
self._progress_bar.show()
self._free_space_label = gtk.Label()
self._free_space_label.set_alignment(0.5, 0.5)
vbox.add(self._free_space_label)
self._free_space_label.show()
self.connect('popup', self.__popup_cb)
menu_item = MenuItem(pgettext('Volume', 'Remove'))
icon = Icon(icon_name='media-eject', icon_size=gtk.ICON_SIZE_MENU)
menu_item.set_image(icon)
icon.show()
menu_item.connect('activate', self.__unmount_activate_cb)
self.menu.append(menu_item)
menu_item.show()
示例4: _refresh_resume_palette
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import set_image [as 别名]
def _refresh_resume_palette(self):
if self._metadata.get('activity_id', ''):
# TRANS: Action label for resuming an activity.
self._resume.set_tooltip(_('Resume'))
else:
# TRANS: Action label for starting an entry.
self._resume.set_tooltip(_('Start'))
palette = self._resume.get_palette()
for menu_item in palette.menu.get_children():
palette.menu.remove(menu_item)
menu_item.destroy()
for activity_info in misc.get_activities(self._metadata):
menu_item = MenuItem(activity_info.get_name())
menu_item.set_image(Icon(file=activity_info.get_icon(),
icon_size=gtk.ICON_SIZE_MENU))
menu_item.connect('activate', self._resume_menu_item_activate_cb,
activity_info.get_bundle_id())
palette.menu.append(menu_item)
menu_item.show()
示例5: __init__
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import set_image [as 别名]
def __init__(self, browser, title, url, owner_document):
Palette.__init__(self)
self._browser = browser
self._title = title
self._url = url
self._owner_document = owner_document
if title is not None:
self.props.primary_text = title
self.props.secondary_text = url
else:
self.props.primary_text = url
menu_item = MenuItem(_('Follow link'), 'edit-copy')
menu_item.connect('activate', self.__follow_activate_cb)
self.menu.append(menu_item)
menu_item.show()
menu_item = MenuItem(_('Copy'))
icon = Icon(icon_name='edit-copy', xo_color=profile.get_color(),
icon_size=gtk.ICON_SIZE_MENU)
menu_item.set_image(icon)
menu_item.connect('activate', self.__copy_activate_cb)
self.menu.append(menu_item)
menu_item.show()
if url.startswith('javascript:'):
# only show if the link is a bookmarklet
menu_item = MenuItem(_('Save bookmarklet'))
menu_item.connect('activate', self.__bookmarklet_activate_cb)
self.menu.append(menu_item)
menu_item.show()
else:
# for all other links
menu_item = MenuItem(_('Download link'))
menu_item.connect('activate', self.__download_activate_cb)
self.menu.append(menu_item)
menu_item.show()
示例6: SpeakerPalette
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import set_image [as 别名]
class SpeakerPalette(Palette):
def __init__(self, primary_text, model):
Palette.__init__(self, label=primary_text)
self._model = model
vbox = gtk.VBox()
self.set_content(vbox)
vbox.show()
vol_step = sound.VOLUME_STEP
self._adjustment = gtk.Adjustment(value=self._model.props.level,
lower=0,
upper=100 + vol_step,
step_incr=vol_step,
page_incr=vol_step,
page_size=vol_step)
self._hscale = gtk.HScale(self._adjustment)
self._hscale.set_digits(0)
self._hscale.set_draw_value(False)
vbox.add(self._hscale)
self._hscale.show()
self._mute_item = MenuItem('')
self._mute_icon = Icon(icon_size=gtk.ICON_SIZE_MENU)
self._mute_item.set_image(self._mute_icon)
self.menu.append(self._mute_item)
self._mute_item.show()
self._adjustment_handler_id = \
self._adjustment.connect('value_changed',
self.__adjustment_changed_cb)
self._model_notify_level_handler_id = \
self._model.connect('notify::level', self.__level_changed_cb)
self._model.connect('notify::muted', self.__muted_changed_cb)
self._mute_item.connect('activate', self.__mute_activate_cb)
self.connect('popup', self.__popup_cb)
def _update_muted(self):
if self._model.props.muted:
mute_item_text = _('Unmute')
mute_item_icon_name = 'dialog-ok'
else:
mute_item_text = _('Mute')
mute_item_icon_name = 'dialog-cancel'
self._mute_item.get_child().set_text(mute_item_text)
self._mute_icon.props.icon_name = mute_item_icon_name
def _update_level(self):
if self._adjustment.value != self._model.props.level:
self._adjustment.handler_block(self._adjustment_handler_id)
try:
self._adjustment.value = self._model.props.level
finally:
self._adjustment.handler_unblock(self._adjustment_handler_id)
def __adjustment_changed_cb(self, adj_):
self._model.handler_block(self._model_notify_level_handler_id)
try:
self._model.props.level = self._adjustment.value
finally:
self._model.handler_unblock(self._model_notify_level_handler_id)
self._model.props.muted = self._adjustment.value == 0
def __level_changed_cb(self, pspec_, param_):
self._update_level()
def __mute_activate_cb(self, menuitem_):
self._model.props.muted = not self._model.props.muted
def __muted_changed_cb(self, pspec_, param_):
self._update_muted()
def __popup_cb(self, palette_):
self._update_level()
self._update_muted()
示例7: BuddyMenu
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import set_image [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:
示例8: ClipboardMenu
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import set_image [as 别名]
class ClipboardMenu(Palette):
def __init__(self, cb_object):
Palette.__init__(self, text_maxlen=100)
self._cb_object = cb_object
self.set_group_id('frame')
cb_service = clipboard.get_instance()
cb_service.connect('object-state-changed',
self._object_state_changed_cb)
self._progress_bar = None
self._remove_item = MenuItem(pgettext('Clipboard', 'Remove'),
'list-remove')
self._remove_item.connect('activate', self._remove_item_activate_cb)
self.menu.append(self._remove_item)
self._remove_item.show()
self._open_item = MenuItem(_('Open'), 'zoom-activity')
self._open_item.connect('activate', self._open_item_activate_cb)
self.menu.append(self._open_item)
self._open_item.show()
self._journal_item = MenuItem(_('Keep'))
client = gconf.client_get_default()
color = XoColor(client.get_string('/desktop/sugar/user/color'))
icon = Icon(icon_name='document-save', icon_size=gtk.ICON_SIZE_MENU,
xo_color=color)
self._journal_item.set_image(icon)
self._journal_item.connect('activate', self._journal_item_activate_cb)
self.menu.append(self._journal_item)
self._journal_item.show()
self._update()
def _update_open_submenu(self):
activities = self._get_activities()
logging.debug('_update_open_submenu: %r', activities)
child = self._open_item.get_child()
if activities is None or len(activities) <= 1:
child.set_text(_('Open'))
if self._open_item.get_submenu() is not None:
self._open_item.remove_submenu()
return
child.set_text(_('Open with'))
submenu = self._open_item.get_submenu()
if submenu is None:
submenu = gtk.Menu()
self._open_item.set_submenu(submenu)
submenu.show()
else:
for item in submenu.get_children():
submenu.remove(item)
for service_name in activities:
registry = bundleregistry.get_registry()
activity_info = registry.get_bundle(service_name)
if not activity_info:
logging.warning('Activity %s is unknown.', service_name)
item = gtk.MenuItem(activity_info.get_name())
item.connect('activate', self._open_submenu_item_activate_cb,
service_name)
submenu.append(item)
item.show()
def _update_items_visibility(self):
activities = self._get_activities()
installable = self._cb_object.is_bundle()
percent = self._cb_object.get_percent()
if percent == 100 and (activities or installable):
self._remove_item.props.sensitive = True
self._open_item.props.sensitive = True
self._journal_item.props.sensitive = True
elif percent == 100 and (not activities and not installable):
self._remove_item.props.sensitive = True
self._open_item.props.sensitive = False
self._journal_item.props.sensitive = True
else:
self._remove_item.props.sensitive = True
self._open_item.props.sensitive = False
self._journal_item.props.sensitive = False
self._update_progress_bar()
def _get_activities(self):
mime_type = self._cb_object.get_mime_type()
if not mime_type:
return ''
registry = bundleregistry.get_registry()
activities = registry.get_activities_for_type(mime_type)
if activities:
#.........这里部分代码省略.........
示例9: SpeechPalette
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import set_image [as 别名]
class SpeechPalette(Palette):
def __init__(self, primary_text, manager):
Palette.__init__(self, label=primary_text)
self._manager = manager
self._manager.connect('play', self._set_menu_state, 'play')
self._manager.connect('stop', self._set_menu_state, 'stop')
self._manager.connect('pause', self._set_menu_state, 'pause')
vbox = gtk.VBox()
self.set_content(vbox)
self._play_icon = Icon(icon_name='player_play')
self._pause_icon = Icon(icon_name='player_pause')
self._play_pause_menu = MenuItem(text_label=_('Say selected text'))
self._play_pause_menu.set_image(self._play_icon)
self._play_pause_menu.connect('activate', self.__play_activated_cb)
self._play_pause_menu.show()
self._stop_menu = MenuItem(icon_name='player_stop',
text_label=_('Stop playback'))
self._stop_menu.connect('activate', self.__stop_activated_cb)
self._stop_menu.set_sensitive(False)
self._stop_menu.show()
self.menu.append(self._play_pause_menu)
self.menu.append(self._stop_menu)
self._adj_pitch = gtk.Adjustment(value=self._manager.get_pitch(),
lower=self._manager.MIN_PITCH,
upper=self._manager.MAX_PITCH)
self._hscale_pitch = gtk.HScale(self._adj_pitch)
self._hscale_pitch.set_draw_value(False)
vbox.pack_start(gtk.Label(_('Pitch')), padding=style.DEFAULT_PADDING)
vbox.pack_start(self._hscale_pitch)
self._adj_rate = gtk.Adjustment(value=self._manager.get_rate(),
lower=self._manager.MIN_RATE,
upper=self._manager.MAX_RATE)
self._hscale_rate = gtk.HScale(self._adj_rate)
self._hscale_rate.set_draw_value(False)
vbox.pack_start(gtk.Label(_('Rate')), padding=style.DEFAULT_PADDING)
vbox.pack_start(self._hscale_rate)
vbox.show_all()
self._adj_pitch.connect('value_changed', self.__adj_pitch_changed_cb)
self._adj_rate.connect('value_changed', self.__adj_rate_changed_cb)
def __adj_pitch_changed_cb(self, adjustement):
self._manager.set_pitch(int(adjustement.value))
def __adj_rate_changed_cb(self, adjustement):
self._manager.set_rate(int(adjustement.value))
def __play_activated_cb(self, widget):
if self._manager.is_paused:
self._manager.restart()
elif not self._manager.is_playing:
self._manager.say_selected_text()
else:
self._manager.pause()
def __stop_activated_cb(self, widget):
self._manager.stop()
def _set_menu_state(self, manager, signal):
if signal == 'play':
self._play_pause_menu.set_image(self._pause_icon)
self._play_pause_menu.set_label(_('Pause playback'))
self._stop_menu.set_sensitive(True)
elif signal == 'pause':
self._play_pause_menu.set_image(self._play_icon)
self._play_pause_menu.set_label(_('Say selected text'))
self._stop_menu.set_sensitive(True)
elif signal == 'stop':
self._play_pause_menu.set_image(self._play_icon)
self._play_pause_menu.set_label(_('Say selected text'))
self._stop_menu.set_sensitive(False)
示例10: ActivityListPalette
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import set_image [as 别名]
class ActivityListPalette(ActivityPalette):
__gtype_name__ = 'SugarActivityListPalette'
__gsignals__ = {
'erase-activated': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([str])),
}
def __init__(self, activity_info):
ActivityPalette.__init__(self, activity_info)
self._bundle_id = activity_info.get_bundle_id()
self._version = activity_info.get_activity_version()
registry = bundleregistry.get_registry()
self._favorite = registry.is_bundle_favorite(self._bundle_id,
self._version)
self._favorite_item = MenuItem('')
self._favorite_icon = Icon(icon_name='emblem-favorite',
icon_size=gtk.ICON_SIZE_MENU)
self._favorite_item.set_image(self._favorite_icon)
self._favorite_item.connect('activate',
self.__change_favorite_activate_cb)
self.menu.append(self._favorite_item)
self._favorite_item.show()
if activity_info.is_user_activity():
self._add_erase_option(registry, activity_info)
registry = bundleregistry.get_registry()
self._activity_changed_sid = registry.connect('bundle_changed',
self.__activity_changed_cb)
self._update_favorite_item()
self.connect('destroy', self.__destroy_cb)
def _add_erase_option(self, registry, activity_info):
menu_item = MenuItem(_('Erase'), 'list-remove')
menu_item.connect('activate', self.__erase_activate_cb)
self.menu.append(menu_item)
menu_item.show()
if not os.access(activity_info.get_path(), os.W_OK) or \
registry.is_activity_protected(self._bundle_id):
menu_item.props.sensitive = False
def __destroy_cb(self, palette):
registry = bundleregistry.get_registry()
registry.disconnect(self._activity_changed_sid)
def _update_favorite_item(self):
label = self._favorite_item.child
if self._favorite:
label.set_text(_('Remove favorite'))
xo_color = XoColor('%s,%s' % (style.COLOR_WHITE.get_svg(),
style.COLOR_TRANSPARENT.get_svg()))
else:
label.set_text(_('Make favorite'))
client = gconf.client_get_default()
xo_color = XoColor(client.get_string('/desktop/sugar/user/color'))
self._favorite_icon.props.xo_color = xo_color
def __change_favorite_activate_cb(self, menu_item):
registry = bundleregistry.get_registry()
registry.set_bundle_favorite(self._bundle_id,
self._version,
not self._favorite)
def __activity_changed_cb(self, activity_registry, activity_info):
if activity_info.get_bundle_id() == self._bundle_id and \
activity_info.get_activity_version() == self._version:
registry = bundleregistry.get_registry()
self._favorite = registry.is_bundle_favorite(self._bundle_id,
self._version)
self._update_favorite_item()
def __erase_activate_cb(self, menu_item):
self.emit('erase-activated', self._bundle_id)
示例11: WirelessPalette
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import set_image [as 别名]
class WirelessPalette(Palette):
__gtype_name__ = 'SugarWirelessPalette'
__gsignals__ = {
'deactivate-connection': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_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._info = gtk.VBox()
def _padded(child, xalign=0, yalign=0.5):
padder = gtk.Alignment(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))
self._info.pack_start(_padded(self._ip_address_label))
self._info.show_all()
self._disconnect_item = MenuItem(_('Disconnect'))
icon = Icon(icon_size=gtk.ICON_SIZE_MENU, icon_name='media-eject')
self._disconnect_item.set_image(icon)
self._disconnect_item.connect('activate',
self.__disconnect_activate_cb)
self.menu.append(self._disconnect_item)
def set_connecting(self):
label = glib.markup_escape_text(_('Connecting...'))
self.props.secondary_text = label
def _set_connected(self, iaddress):
self.set_content(self._info)
self.props.secondary_text = glib.markup_escape_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):
label = glib.markup_escape_text(_('No wireless connection'))
self.props.primary_text = label
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):
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 % \
socket.inet_ntoa(struct.pack('I', ip_address))
else:
ip_address_text = ""
self._ip_address_label.set_text(ip_address_text)
示例12: GsmPalette
# 需要导入模块: from sugar.graphics.menuitem import MenuItem [as 别名]
# 或者: from sugar.graphics.menuitem.MenuItem import set_image [as 别名]
class GsmPalette(Palette):
__gtype_name__ = 'SugarGsmPalette'
__gsignals__ = {
'gsm-connect': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
'gsm-disconnect': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([])),
}
def __init__(self):
label = glib.markup_escape_text(_('Wireless modem'))
Palette.__init__(self, primary_text=label)
self._current_state = None
self._failed_connection = False
self._toggle_state_item = MenuItem('')
self._toggle_state_item.connect('activate', self.__toggle_state_cb)
self.menu.append(self._toggle_state_item)
self._toggle_state_item.show()
self.info_box = gtk.VBox()
self.error_title_label = gtk.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)
self.error_description_label = gtk.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)
self.connection_info_box = gtk.HBox()
icon = Icon(icon_name='data-upload', icon_size=gtk.ICON_SIZE_MENU)
self.connection_info_box.pack_start(icon)
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)
self._data_label_up.show()
label_alignment.show()
icon = Icon(icon_name='data-download', icon_size=gtk.ICON_SIZE_MENU)
self.connection_info_box.pack_start(icon)
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)
self._data_label_down.show()
label_alignment.show()
self.info_box.pack_start(self.connection_info_box)
self.info_box.show()
self.set_content(self.info_box)
self.set_state(_GSM_STATE_NOT_READY)
def _add_widget_with_padding(self, child, xalign=0, yalign=0.5):
alignment = gtk.Alignment(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.get_child().set_label('...')
label = glib.markup_escape_text(_('Please wait...'))
self.props.secondary_text = label
elif self._current_state == _GSM_STATE_DISCONNECTED:
if not self._failed_connection:
self._toggle_state_item.get_child().set_label(_('Connect'))
label = glib.markup_escape_text(_('Disconnected'))
self.props.secondary_text = label
icon = Icon(icon_name='dialog-ok', \
icon_size=gtk.ICON_SIZE_MENU)
self._toggle_state_item.set_image(icon)
elif self._current_state == _GSM_STATE_CONNECTING:
self._toggle_state_item.get_child().set_label(_('Cancel'))
label = glib.markup_escape_text(_('Connecting...'))
self.props.secondary_text = label
icon = Icon(icon_name='dialog-cancel', \
icon_size=gtk.ICON_SIZE_MENU)
self._toggle_state_item.set_image(icon)
elif self._current_state == _GSM_STATE_CONNECTED:
self._failed_connection = False
self._toggle_state_item.get_child().set_label(_('Disconnect'))
#.........这里部分代码省略.........