[Sugar-devel] [Sugar] Only add a group of selections to the clipboard if there are anything available. -v2

godiard at sugarlabs.org godiard at sugarlabs.org
Tue Mar 13 09:02:43 EDT 2012


From: Gonzalo Odiard <godiard at gmail.com>

This problem is affecting Text to Speech with Write activity,
because there are only a selection in the secondary clipboard
but a icon is displayed in the frame without anything selected.

v2: Addressed comments from Sasha, add a line and do patch with -U4 option

Signed-off-by: Gonzalo Odiard
---
 src/jarabe/frame/clipboardpanelwindow.py |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/jarabe/frame/clipboardpanelwindow.py b/src/jarabe/frame/clipboardpanelwindow.py
index aefec7b..b73572e 100644
--- a/src/jarabe/frame/clipboardpanelwindow.py
+++ b/src/jarabe/frame/clipboardpanelwindow.py
@@ -55,23 +55,27 @@ class ClipboardPanelWindow(FrameWindow):
         if self._clipboard_tray.owns_clipboard():
             return
 
         cb_service = clipboard.get_instance()
-        key = cb_service.add_object(name="")
-        cb_service.set_object_percent(key, percent=0)
 
         targets = x_clipboard.wait_for_targets()
+        cb_selections = []
         for target in targets:
             if target not in ('TIMESTAMP', 'TARGETS',
                               'MULTIPLE', 'SAVE_TARGETS'):
                 logging.debug('Asking for target %s.', target)
                 selection = x_clipboard.wait_for_contents(target)
                 if not selection:
                     logging.warning('no data for selection target %s.', target)
                     continue
-                self._add_selection(key, selection)
+                cb_selections.append(selection)
 
-        cb_service.set_object_percent(key, percent=100)
+        if len(cb_selections) > 0:
+            key = cb_service.add_object(name="")
+            cb_service.set_object_percent(key, percent=0)
+            for selection in cb_selections:
+                self._add_selection(key, selection)
+            cb_service.set_object_percent(key, percent=100)
 
     def _add_selection(self, key, selection):
         if not selection.data:
             logging.warning('no data for selection target %s.', selection.type)
-- 
1.7.7.6



More information about the Sugar-devel mailing list