[Sugar-devel] [PATCH shell 1/3] Port Sugar Palettes with mixed content to new API
Simon Schampijer
simon at schampijer.de
Thu Sep 13 10:56:24 EDT 2012
From: Simon Schampijer <simon at laptop.org>
As Palettes can either include a Gtk.Menu or a Gtk.Window we
have to use a "false" menu when we want to have both
functionality in a Palette. There is a new class PaletteMenuItem
in the toolkit for that.
Ported from the Frame: Journal Palette, Network Wireless Palette,
Speaker Palette
Signed-off-by: Simon Schampijer <simon at laptop.org>
---
extensions/deviceicon/network.py | 19 ++++++++++++-------
extensions/deviceicon/speaker.py | 33 +++++++++++++++++++--------------
src/jarabe/view/palettes.py | 29 +++++++++++++++++------------
3 files changed, 48 insertions(+), 33 deletions(-)
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index 51d3ac9..b4a5393 100644
--- a/extensions/deviceicon/network.py
+++ b/extensions/deviceicon/network.py
@@ -34,6 +34,8 @@ import dbus
from sugar3.graphics.icon import get_icon_state
from sugar3.graphics import style
from sugar3.graphics.palette import Palette
+from sugar3.graphics.palettemenuitem import PaletteMenuItem
+from sugar3.graphics.palettemenuitem import PaletteMenuItemSeparator
from sugar3.graphics.toolbutton import ToolButton
from sugar3.graphics.tray import TrayIcon
from sugar3.graphics.menuitem import MenuItem
@@ -76,6 +78,16 @@ class WirelessPalette(Palette):
self._info = Gtk.VBox()
+ self._disconnect_item = PaletteMenuItem(_('Disconnect'))
+ icon = Icon(icon_size=Gtk.IconSize.MENU, 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)
@@ -90,13 +102,6 @@ class WirelessPalette(Palette):
self._info.pack_start(_padded(self._ip_address_label), True, True, 0)
self._info.show_all()
- self._disconnect_item = MenuItem(_('Disconnect'))
- icon = Icon(icon_size=Gtk.IconSize.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
diff --git a/extensions/deviceicon/speaker.py b/extensions/deviceicon/speaker.py
index cc2c4ef..4a09e7b 100644
--- a/extensions/deviceicon/speaker.py
+++ b/extensions/deviceicon/speaker.py
@@ -26,6 +26,8 @@ from sugar3.graphics.icon import get_icon_state, Icon
from sugar3.graphics.menuitem import MenuItem
from sugar3.graphics.tray import TrayIcon
from sugar3.graphics.palette import Palette
+from sugar3.graphics.palettemenuitem import PaletteMenuItem
+from sugar3.graphics.palettemenuitem import PaletteMenuItemSeparator
from sugar3.graphics.xocolor import XoColor
from jarabe.frame.frameinvoker import FrameWidgetInvoker
@@ -102,6 +104,17 @@ class SpeakerPalette(Palette):
self.set_content(vbox)
vbox.show()
+ self._mute_item = PaletteMenuItem('')
+ self._mute_icon = Icon(icon_size=Gtk.IconSize.MENU)
+ self._mute_item.set_image(self._mute_icon)
+ vbox.add(self._mute_item)
+ self._mute_item.show()
+ self._mute_item.connect('activate', self.__mute_activate_cb)
+
+ separator = PaletteMenuItemSeparator()
+ vbox.pack_start(separator, True, True, 0)
+ separator.show()
+
vol_step = sound.VOLUME_STEP
self._adjustment = Gtk.Adjustment(value=self._model.props.level,
lower=0,
@@ -112,16 +125,9 @@ class SpeakerPalette(Palette):
self._hscale = Gtk.HScale()
self._hscale.set_adjustment(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.IconSize.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)
@@ -130,8 +136,6 @@ class SpeakerPalette(Palette):
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):
@@ -141,24 +145,25 @@ class SpeakerPalette(Palette):
else:
mute_item_text = _('Mute')
mute_item_icon_name = 'dialog-cancel'
- self._mute_item.get_child().set_text(mute_item_text)
+ self._mute_item.set_label(mute_item_text)
self._mute_icon.props.icon_name = mute_item_icon_name
+ self._mute_icon.show()
def _update_level(self):
- if self._adjustment.value != self._model.props.level:
+ if self._adjustment.props.value != self._model.props.level:
self._adjustment.handler_block(self._adjustment_handler_id)
try:
- self._adjustment.value = self._model.props.level
+ self._adjustment.props.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
+ self._model.props.level = self._adjustment.props.value
finally:
self._model.handler_unblock(self._model_notify_level_handler_id)
- self._model.props.muted = self._adjustment.value == 0
+ self._model.props.muted = self._adjustment.props.value == 0
def __level_changed_cb(self, pspec_, param_):
self._update_level()
diff --git a/src/jarabe/view/palettes.py b/src/jarabe/view/palettes.py
index 2d13cbd..50f6c83 100644
--- a/src/jarabe/view/palettes.py
+++ b/src/jarabe/view/palettes.py
@@ -25,6 +25,8 @@ from gi.repository import Gtk
from sugar3 import env
from sugar3.graphics.palette import Palette
+from sugar3.graphics.palettemenuitem import PaletteMenuItem
+from sugar3.graphics.palettemenuitem import PaletteMenuItemSeparator
from sugar3.graphics.menuitem import MenuItem
from sugar3.graphics.icon import Icon
from sugar3.graphics import style
@@ -166,6 +168,21 @@ class JournalPalette(BasePalette):
self.set_content(vbox)
vbox.show()
+ menu_item = PaletteMenuItem(_('Show contents'))
+ icon = Icon(file=self._home_activity.get_icon_path(),
+ icon_size=Gtk.IconSize.MENU,
+ xo_color=self._home_activity.get_icon_color())
+ menu_item.set_image(icon)
+ icon.show()
+
+ menu_item.connect('activate', self.__open_activate_cb)
+ vbox.add(menu_item)
+ menu_item.show()
+
+ separator = PaletteMenuItemSeparator()
+ vbox.pack_start(separator, True, True, 0)
+ separator.show()
+
self._progress_bar = Gtk.ProgressBar()
vbox.add(self._progress_bar)
self._progress_bar.show()
@@ -177,18 +194,6 @@ class JournalPalette(BasePalette):
self.connect('popup', self.__popup_cb)
- menu_item = MenuItem(_('Show contents'))
-
- icon = Icon(file=self._home_activity.get_icon_path(),
- icon_size=Gtk.IconSize.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()
-
def __open_activate_cb(self, menu_item):
self._home_activity.get_window().activate(Gtk.get_current_event_time())
--
1.7.11.4
More information about the Sugar-devel
mailing list