From a7e4092b0e4f3d30a21ee5a7982aecd5252a0822 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Sun, 05 Nov 2006 18:52:46 +0000 Subject: Created SugarDownloadManager and ClipboardService's wrapper. Show and hide the frame when adding an object to the clipboard. --- (limited to 'shell') diff --git a/shell/view/ClipboardIcon.py b/shell/view/ClipboardIcon.py index 9a9b6f4..db23353 100644 --- a/shell/view/ClipboardIcon.py +++ b/shell/view/ClipboardIcon.py @@ -1,10 +1,12 @@ from sugar.graphics.menuicon import MenuIcon from view.ClipboardMenu import ClipboardMenu from sugar.activity import ActivityFactory +from sugar.clipboard import ClipboardService class ClipboardIcon(MenuIcon): + def __init__(self, menu_shell, file_name): - MenuIcon.__init__(self, menu_shell, icon_name='stock-written-doc') + MenuIcon.__init__(self, menu_shell, icon_name='activity-xbook') self._file_name = file_name self._percent = 0 self.connect('activated', self._icon_activated_cb) @@ -21,13 +23,15 @@ class ClipboardIcon(MenuIcon): self._menu.set_percent(percent) def _icon_activated_cb(self, icon): - activity = ActivityFactory.create("org.laptop.sugar.Xbook") - activity.execute("open_document", [self._file_name]) + if self._percent == 100: + activity = ActivityFactory.create("org.laptop.sugar.Xbook") + activity.execute("open_document", [self._file_name]) def _popup_action_cb(self, popup, action): -# self.popdown() -# -# if action == ClipboardMenu.ACTION_DELETE: -# activity = self._shell.get_current_activity() -# activity.invite(ps_buddy) - pass + self.popdown() + + if action == ClipboardMenu.ACTION_STOP_DOWNLOAD: + raise "Stopping downloads still not implemented." + elif action == ClipboardMenu.ACTION_DELETE: + cb_service = ClipboardService.get_instance() + cb_service.delete_object(self._file_name) diff --git a/shell/view/ClipboardMenu.py b/shell/view/ClipboardMenu.py index 16a0384..0964fc3 100644 --- a/shell/view/ClipboardMenu.py +++ b/shell/view/ClipboardMenu.py @@ -43,16 +43,32 @@ class ClipboardMenu(Menu): self._progress_bar = ClipboardMenuItem(percent) self._root.append(self._progress_bar) - icon = CanvasIcon(icon_name='stock-share-mesh') - self.add_action(icon, ClipboardMenu.ACTION_SHARE) + #icon = CanvasIcon(icon_name='stock-share-mesh') + #self.add_action(icon, ClipboardMenu.ACTION_SHARE) + self._remove_icon = None + self._stop_icon = None + + self._create_icons(percent) + + def _create_icons(self, percent): if percent == 100: - icon = CanvasIcon(icon_name='stock-remove') - self.add_action(icon, ClipboardMenu.ACTION_DELETE) + if not self._remove_icon: + self._remove_icon = CanvasIcon(icon_name='stock-remove') + self.add_action(self._remove_icon, ClipboardMenu.ACTION_DELETE) + + if self._stop_icon: + self.remove_action(self._stop_icon) + self._stop_icon = None else: - icon = CanvasIcon(icon_name='stock-close') - self.add_action(icon, ClipboardMenu.ACTION_STOP_DOWNLOAD) + if not self._stop_icon: + self._stop_icon = CanvasIcon(icon_name='stock-close') + self.add_action(self._stop_icon, ClipboardMenu.ACTION_STOP_DOWNLOAD) + if self._remove_icon: + self.remove_action(self._remove_icon) + self._remove_icon = None + def set_percent(self, percent): self._progress_bar.set_property('percent', percent) - + self._create_icons(percent) diff --git a/shell/view/frame/ClipboardBox.py b/shell/view/frame/ClipboardBox.py index 9eae973..1ca1a8c 100644 --- a/shell/view/frame/ClipboardBox.py +++ b/shell/view/frame/ClipboardBox.py @@ -4,58 +4,39 @@ import hippo from sugar.graphics import style from view.ClipboardIcon import ClipboardIcon +from sugar.clipboard import ClipboardService class ClipboardBox(hippo.CanvasBox): - - _CLIPBOARD_SERVICE = "org.laptop.Clipboard" - _CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard" - def __init__(self, shell, menu_shell): + def __init__(self, frame, menu_shell): hippo.CanvasBox.__init__(self) - self._shell = shell + self._frame = frame self._menu_shell = menu_shell self._icons = {} - - bus = dbus.SessionBus() - bus.add_signal_receiver(self.name_owner_changed_cb, - signal_name="NameOwnerChanged", - dbus_interface="org.freedesktop.DBus") - # Try to register to ClipboardService, if we fail, we'll try later. - try: - self._connect_clipboard_signals() - except dbus.DBusException, exception: - pass - def _connect_clipboard_signals(self): - bus = dbus.SessionBus() - proxy_obj = bus.get_object(self._CLIPBOARD_SERVICE, self._CLIPBOARD_OBJECT_PATH) - iface = dbus.Interface(proxy_obj, self._CLIPBOARD_SERVICE) - iface.connect_to_signal('object_added', self.object_added_callback) - iface.connect_to_signal('object_deleted', self.object_deleted_callback) - iface.connect_to_signal('object_state_updated', self.object_state_updated_callback) + cb_service = ClipboardService.get_instance() + cb_service.connect('object-added', self._object_added_cb) + cb_service.connect('object-deleted', self._object_deleted_cb) + cb_service.connect('object-state-updated', self._object_state_updated_cb) - def name_owner_changed_cb(self, name, old, new): - if name != self._CLIPBOARD_SERVICE: - return - if (not old and not len(old)) and (new and len(new)): - # ClipboardService started up - self._connect_clipboard_signals() - - def object_added_callback(self, mimeType, fileName): + def _object_added_cb(self, cb_service, mimeType, fileName): icon = ClipboardIcon(self._menu_shell, fileName) style.apply_stylesheet(icon, 'frame.BuddyIcon') self.append(icon) self._icons[fileName] = icon + if not self._frame.is_visible(): + self._frame.show_and_hide(0.1) + logging.debug('ClipboardBox: ' + fileName + ' was added.') - def object_deleted_callback(self, fileName): + def _object_deleted_cb(self, cb_service, fileName): icon = self._icons[fileName] self.remove(icon) - self._icons.remove(icon) + del self._icons[fileName] logging.debug('ClipboardBox: ' + fileName + ' was deleted.') - def object_state_updated_callback(self, fileName, percent): + def _object_state_updated_cb(self, cb_service, fileName, percent): icon = self._icons[fileName] icon.set_percent(percent) logging.debug('ClipboardBox: ' + fileName + ' state was updated.') diff --git a/shell/view/frame/Frame.py b/shell/view/frame/Frame.py index ad6a390..4a5f31a 100644 --- a/shell/view/frame/Frame.py +++ b/shell/view/frame/Frame.py @@ -201,7 +201,7 @@ class Frame: # Left panel [menu_shell, root] = self._create_panel(grid, 0, 1, 1, 10) - box = ClipboardBox(self._shell, menu_shell) + box = ClipboardBox(self, menu_shell) root.append(box) def _create_panel(self, grid, x, y, width, height): -- cgit v0.9.1