[Sugar-devel] [PATCH] Only add one time every object in the clipboard v3 - SL #3371

Simon Schampijer simon at schampijer.de
Fri Apr 20 13:34:07 EDT 2012


Great both new versions of your patches do what they describe they would 
do :)

There is one trace in the shell.log related to the clipboard when the 
clipboard owner changes, a TypeError, targets is None.

Please have a look at it, all the rest looks already really good.

Regards,
    Simon


On 04/20/2012 04:17 PM, godiard at sugarlabs.org wrote:
> From: Gonzalo Odiard<godiard at gmail.com>
>
> This patch change the behaviour of the clipboard tray,
> every object is added only one time, if already exist,
> the already added object is selected.
> Is needed because a bad interaction between the clipboard in write and
> the text to speech feature. See the ticket for more information.
>
> v2: Select the already added object if needed, as sugested by Sasha.
> v3: Show the notification when copy a already existing object, as sugested by Gary
>
> Signed-off-by: Gonzalo Odiard<gonzalo at laptop.org>
> ---
>   src/jarabe/frame/clipboard.py            |   17 +++++++++++++----
>   src/jarabe/frame/clipboardicon.py        |   18 ++++++++++--------
>   src/jarabe/frame/clipboardpanelwindow.py |    5 ++++-
>   src/jarabe/frame/clipboardtray.py        |    7 +++++++
>   4 files changed, 34 insertions(+), 13 deletions(-)
>
> diff --git a/src/jarabe/frame/clipboard.py b/src/jarabe/frame/clipboard.py
> index be2b902..ae1ceb9 100644
> --- a/src/jarabe/frame/clipboard.py
> +++ b/src/jarabe/frame/clipboard.py
> @@ -36,7 +36,9 @@ class Clipboard(gobject.GObject):
>           'object-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
>                           ([object])),
>           'object-deleted': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
> -                        ([int])),
> +                        ([long])),
> +        'object-selected': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
> +                        ([long])),
>           'object-state-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
>                           ([object])),
>       }
> @@ -51,9 +53,16 @@ class Clipboard(gobject.GObject):
>           self._next_id += 1
>           return self._next_id
>
> -    def add_object(self, name):
> -        logging.debug('Clipboard.add_object')
> -        object_id = self._get_next_object_id()
> +    def add_object(self, name, data_hash=None):
> +        logging.debug('Clipboard.add_object hash %s', data_hash)
> +        if data_hash is None:
> +            object_id = self._get_next_object_id()
> +        else:
> +            object_id = data_hash
> +        if object_id in self._objects:
> +            logging.debug('Object rejected, already exist')
> +            self.emit('object-selected', object_id)
> +            return None
>           self._objects[object_id] = ClipboardObject(object_id, name)
>           self.emit('object-added', self._objects[object_id])
>           return object_id
> diff --git a/src/jarabe/frame/clipboardicon.py b/src/jarabe/frame/clipboardicon.py
> index aa72d8a..7bc4dc3 100644
> --- a/src/jarabe/frame/clipboardicon.py
> +++ b/src/jarabe/frame/clipboardicon.py
> @@ -128,17 +128,19 @@ class ClipboardIcon(RadioToolButton):
>           # Clipboard object became complete. Make it the active one.
>           if self._current_percent<  100 and cb_object.get_percent() == 100:
>               self.props.active = True
> +            self.show_notification()
>
> -            self._notif_icon = NotificationIcon()
> -            self._notif_icon.props.icon_name = self._icon.props.icon_name
> -            self._notif_icon.props.xo_color = \
> -                    XoColor('%s,%s' % (self._icon.props.stroke_color,
> -                                       self._icon.props.fill_color))
> -            frame = jarabe.frame.get_view()
> -            frame.add_notification(self._notif_icon,
> -                                   gtk.CORNER_BOTTOM_LEFT)
>           self._current_percent = cb_object.get_percent()
>
> +    def show_notification(self):
> +        self._notif_icon = NotificationIcon()
> +        self._notif_icon.props.icon_name = self._icon.props.icon_name
> +        self._notif_icon.props.xo_color = \
> +                XoColor('%s,%s' % (self._icon.props.stroke_color,
> +                                   self._icon.props.fill_color))
> +        frame = jarabe.frame.get_view()
> +        frame.add_notification(self._notif_icon, gtk.CORNER_BOTTOM_LEFT)
> +
>       def _drag_begin_cb(self, widget, context):
>           # TODO: We should get the pixbuf from the icon, with colors, etc.
>           icon_theme = gtk.icon_theme_get_default()
> diff --git a/src/jarabe/frame/clipboardpanelwindow.py b/src/jarabe/frame/clipboardpanelwindow.py
> index b73572e..28c5726 100644
> --- a/src/jarabe/frame/clipboardpanelwindow.py
> +++ b/src/jarabe/frame/clipboardpanelwindow.py
> @@ -70,7 +70,10 @@ class ClipboardPanelWindow(FrameWindow):
>                   cb_selections.append(selection)
>
>           if len(cb_selections)>  0:
> -            key = cb_service.add_object(name="")
> +            key = cb_service.add_object(name="",
> +                    data_hash=hash(selection.data))
> +            if key is None:
> +                return
>               cb_service.set_object_percent(key, percent=0)
>               for selection in cb_selections:
>                   self._add_selection(key, selection)
> diff --git a/src/jarabe/frame/clipboardtray.py b/src/jarabe/frame/clipboardtray.py
> index f49b799..f736295 100644
> --- a/src/jarabe/frame/clipboardtray.py
> +++ b/src/jarabe/frame/clipboardtray.py
> @@ -70,6 +70,7 @@ class ClipboardTray(tray.VTray):
>           cb_service = clipboard.get_instance()
>           cb_service.connect('object-added', self._object_added_cb)
>           cb_service.connect('object-deleted', self._object_deleted_cb)
> +        cb_service.connect('object-selected', self._object_selected_cb)
>
>       def owns_clipboard(self):
>           for icon in self._icons.values():
> @@ -125,6 +126,12 @@ class ClipboardTray(tray.VTray):
>           del self._icons[object_id]
>           logging.debug('ClipboardTray: %r was deleted', object_id)
>
> +    def _object_selected_cb(self, cb_service, object_id):
> +        icon = self._icons[object_id]
> +        icon.props.active = True
> +        icon.show_notification()
> +        logging.debug('ClipboardTray: %r was activated', object_id)
> +
>       def drag_motion_cb(self, widget, context, x, y, time):
>           logging.debug('ClipboardTray._drag_motion_cb')
>



More information about the Sugar-devel mailing list