[Sugar-devel] [PATCH shell] Fix Speech device icon - SL #3931

Simon Schampijer simon at schampijer.de
Thu Sep 20 08:22:57 EDT 2012


Great - I like it, thanks for listing all the solutions to each point, 
makes it pleasant to review.

Saying text does not work yet, we have to investigate that - but is 
separate from this patch which is about making the Palette appear.

Please push,
    Simon


On 09/20/2012 04:41 AM, Manuel Quiñones wrote:
> - Port palette with mixed content to new API.
>
> - pack_start: the convert script got confused here.
>
> - Gtk.HScale API change: set adjustment with set_adjustment method,
>    not in the constructor.
>
> - Gtk.Adjustment API change: use get_value method because value
>    property was removed.
>
> - Gdk.Clipboard API changes: Gtk.Clipboard.get needs a GdkAtom [1] and
>    Gdk.SELECTION_PRIMARY is the one we need.
>    Gtk.Clipboard.request_text needs another argument user_data [2],
>    passing None seems to work, but maybe the annotations are wrong.
>
> - fixed long lines and a few indentations
>
> - fixed mispelled variable name 'adjustement' to 'adjustment'
>
> [1] http://developer.gnome.org/gtk3/stable/gtk3-Clipboards.html#gtk-clipboard-get
> [2] http://developer.gnome.org/gtk3/stable/gtk3-Clipboards.html#gtk-clipboard-request-text
>
> Signed-off-by: Manuel Quiñones <manuq at laptop.org>
> ---
>   extensions/deviceicon/speech.py | 44 ++++++++++++++++++++++++-----------------
>   src/jarabe/model/speech.py      |  5 +++--
>   2 files changed, 29 insertions(+), 20 deletions(-)
>
> diff --git a/extensions/deviceicon/speech.py b/extensions/deviceicon/speech.py
> index d89ad51..ba27e7a 100644
> --- a/extensions/deviceicon/speech.py
> +++ b/extensions/deviceicon/speech.py
> @@ -24,8 +24,9 @@ from gi.repository import GObject
>   from sugar3.graphics.icon import Icon
>   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 sugar3.graphics.menuitem import MenuItem
>   from sugar3.graphics import style
>
>   from jarabe.frame.frameinvoker import FrameWidgetInvoker
> @@ -74,47 +75,54 @@ class SpeechPalette(Palette):
>
>           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 = PaletteMenuItem(
> +            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()
> +        vbox.pack_start(self._play_pause_menu, True, True, 0)
>
> -        self._stop_menu = MenuItem(icon_name='player_stop',
> -                text_label=_('Stop playback'))
> +        self._stop_menu = PaletteMenuItem(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()
> +        vbox.pack_start(self._stop_menu, True, True, 0)
>
> -        self.menu.append(self._play_pause_menu)
> -        self.menu.append(self._stop_menu)
> +        separator = PaletteMenuItemSeparator()
> +        vbox.pack_start(separator, True, True, 0)
>
>           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)
> +                                         lower=self._manager.MIN_PITCH,
> +                                         upper=self._manager.MAX_PITCH)
> +        self._hscale_pitch = Gtk.HScale()
> +        self._hscale_pitch.set_adjustment(self._adj_pitch)
>           self._hscale_pitch.set_draw_value(False)
>
> -        vbox.pack_start(Gtk.Label(_('Pitch', True, True, 0)), padding=style.DEFAULT_PADDING)
> +        vbox.pack_start(Gtk.Label(_('Pitch')), True, True,
> +                        padding=style.DEFAULT_PADDING)
>           vbox.pack_start(self._hscale_pitch, True, True, 0)
>
>           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)
> +                                        lower=self._manager.MIN_RATE,
> +                                        upper=self._manager.MAX_RATE)
> +        self._hscale_rate = Gtk.HScale()
> +        self._hscale_rate.set_adjustment(self._adj_rate)
>           self._hscale_rate.set_draw_value(False)
>
> -        vbox.pack_start(Gtk.Label(_('Rate', True, True, 0)), padding=style.DEFAULT_PADDING)
> +        vbox.pack_start(Gtk.Label(_('Rate')), True, True,
> +                        padding=style.DEFAULT_PADDING)
>           vbox.pack_start(self._hscale_rate, True, True, 0)
>           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_pitch_changed_cb(self, adjustment):
> +        self._manager.set_pitch(int(adjustment.get_value()))
>
> -    def __adj_rate_changed_cb(self, adjustement):
> -        self._manager.set_rate(int(adjustement.value))
> +    def __adj_rate_changed_cb(self, adjustment):
> +        self._manager.set_rate(int(adjustment.get_value()))
>
>       def __play_activated_cb(self, widget):
>           if self._manager.is_paused:
> diff --git a/src/jarabe/model/speech.py b/src/jarabe/model/speech.py
> index 864f639..d34237a 100644
> --- a/src/jarabe/model/speech.py
> +++ b/src/jarabe/model/speech.py
> @@ -20,6 +20,7 @@ import logging
>   from gi.repository import GConf
>   from gi.repository import Gst
>   from gi.repository import Gtk
> +from gi.repository import Gdk
>   from gi.repository import GObject
>
>
> @@ -96,8 +97,8 @@ class SpeechManager(GObject.GObject):
>               self._player.speak(self._pitch, self._rate, self._voice_name, text)
>
>       def say_selected_text(self):
> -        clipboard = Gtk.clipboard_get(selection='PRIMARY')
> -        clipboard.request_text(self.__primary_selection_cb)
> +        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_PRIMARY)
> +        clipboard.request_text(self.__primary_selection_cb, None)
>
>       def pause(self):
>           self._player.pause_sound_device()
>



More information about the Sugar-devel mailing list