Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2006-11-01 18:43:59 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2006-11-01 18:43:59 (GMT)
commit23565cfd483e38d3a64cd5980deea47cccb28581 (patch)
treef56a4a4d15308a3b20276edae8e93bff30c1d314 /shell
parentcf508c1d229df5f4f645b7a66d568c1959bc6f62 (diff)
First version of the ClipboardService. Added support for showing the progress of a pdf download in the clipboard.
Diffstat (limited to 'shell')
-rw-r--r--shell/view/ClipboardIcon.py33
-rw-r--r--shell/view/ClipboardMenu.py58
-rw-r--r--shell/view/Makefile.am2
-rw-r--r--shell/view/frame/ClipboardBox.py61
-rw-r--r--shell/view/frame/Frame.py6
-rw-r--r--shell/view/frame/Makefile.am1
6 files changed, 160 insertions, 1 deletions
diff --git a/shell/view/ClipboardIcon.py b/shell/view/ClipboardIcon.py
new file mode 100644
index 0000000..9a9b6f4
--- /dev/null
+++ b/shell/view/ClipboardIcon.py
@@ -0,0 +1,33 @@
+from sugar.graphics.menuicon import MenuIcon
+from view.ClipboardMenu import ClipboardMenu
+from sugar.activity import ActivityFactory
+
+class ClipboardIcon(MenuIcon):
+ def __init__(self, menu_shell, file_name):
+ MenuIcon.__init__(self, menu_shell, icon_name='stock-written-doc')
+ self._file_name = file_name
+ self._percent = 0
+ self.connect('activated', self._icon_activated_cb)
+ self._menu = None
+
+ def create_menu(self):
+ self._menu = ClipboardMenu(self._file_name, self._percent)
+ self._menu.connect('action', self._popup_action_cb)
+ return self._menu
+
+ def set_percent(self, percent):
+ self._percent = percent
+ if self._menu:
+ 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])
+
+ 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
diff --git a/shell/view/ClipboardMenu.py b/shell/view/ClipboardMenu.py
new file mode 100644
index 0000000..16a0384
--- /dev/null
+++ b/shell/view/ClipboardMenu.py
@@ -0,0 +1,58 @@
+import gtk
+import gobject
+import hippo
+
+from sugar.graphics.menu import Menu
+from sugar.graphics.canvasicon import CanvasIcon
+from sugar.graphics.ClipboardBubble import ClipboardBubble
+from sugar.graphics import style
+
+clipboard_bubble = {
+ 'fill-color' : 0x646464FF,
+ 'stroke-color' : 0x646464FF,
+ 'progress-color': 0x333333FF,
+ 'spacing' : style.space_unit,
+ 'padding' : style.space_unit * 1.5
+}
+
+clipboard_menu_item_title = {
+ 'xalign': hippo.ALIGNMENT_START,
+ 'padding-left': 5,
+ 'color' : 0xFFFFFFFF,
+ 'font' : style.get_font_description('Bold', 1.2)
+}
+
+style.register_stylesheet("clipboard.Bubble", clipboard_bubble)
+style.register_stylesheet("clipboard.MenuItem.Title", clipboard_menu_item_title)
+
+class ClipboardMenuItem(ClipboardBubble):
+
+ def __init__(self, percent = 0, stylesheet="clipboard.Bubble"):
+ ClipboardBubble.__init__(self, percent = percent)
+ style.apply_stylesheet(self, stylesheet)
+
+class ClipboardMenu(Menu):
+
+ ACTION_DELETE = 0
+ ACTION_SHARE = 1
+ ACTION_STOP_DOWNLOAD = 2
+
+ def __init__(self, file_name, percent):
+ Menu.__init__(self, file_name)
+
+ 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)
+
+ if percent == 100:
+ icon = CanvasIcon(icon_name='stock-remove')
+ self.add_action(icon, ClipboardMenu.ACTION_DELETE)
+ else:
+ icon = CanvasIcon(icon_name='stock-close')
+ self.add_action(icon, ClipboardMenu.ACTION_STOP_DOWNLOAD)
+
+ def set_percent(self, percent):
+ self._progress_bar.set_property('percent', percent)
+
diff --git a/shell/view/Makefile.am b/shell/view/Makefile.am
index 0e3951a..4438f9b 100644
--- a/shell/view/Makefile.am
+++ b/shell/view/Makefile.am
@@ -7,6 +7,8 @@ sugar_PYTHON = \
FirstTimeDialog.py \
BuddyIcon.py \
BuddyMenu.py \
+ ClipboardIcon.py \
+ ClipboardMenu.py \
OverlayWindow.py \
Shell.py \
stylesheet.py
diff --git a/shell/view/frame/ClipboardBox.py b/shell/view/frame/ClipboardBox.py
new file mode 100644
index 0000000..9eae973
--- /dev/null
+++ b/shell/view/frame/ClipboardBox.py
@@ -0,0 +1,61 @@
+import logging
+import dbus
+import hippo
+
+from sugar.graphics import style
+from view.ClipboardIcon import ClipboardIcon
+
+class ClipboardBox(hippo.CanvasBox):
+
+ _CLIPBOARD_SERVICE = "org.laptop.Clipboard"
+ _CLIPBOARD_OBJECT_PATH = "/org/laptop/Clipboard"
+
+ def __init__(self, shell, menu_shell):
+ hippo.CanvasBox.__init__(self)
+ self._shell = shell
+ 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)
+
+ 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):
+ icon = ClipboardIcon(self._menu_shell, fileName)
+ style.apply_stylesheet(icon, 'frame.BuddyIcon')
+ self.append(icon)
+ self._icons[fileName] = icon
+
+ logging.debug('ClipboardBox: ' + fileName + ' was added.')
+
+ def object_deleted_callback(self, fileName):
+ icon = self._icons[fileName]
+ self.remove(icon)
+ self._icons.remove(icon)
+ logging.debug('ClipboardBox: ' + fileName + ' was deleted.')
+
+ def object_state_updated_callback(self, 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 80fb4d1..ad6a390 100644
--- a/shell/view/frame/Frame.py
+++ b/shell/view/frame/Frame.py
@@ -23,6 +23,7 @@ from view.frame.ActivitiesBox import ActivitiesBox
from view.frame.ZoomBox import ZoomBox
from view.frame.overlaybox import OverlayBox
from view.frame.FriendsBox import FriendsBox
+from view.frame.ClipboardBox import ClipboardBox
from view.frame.PanelWindow import PanelWindow
from view.frame.notificationtray import NotificationTray
from sugar.graphics.timeline import Timeline
@@ -198,7 +199,10 @@ class Frame:
root.append(box)
# Left panel
- self._create_panel(grid, 0, 1, 1, 10)
+ [menu_shell, root] = self._create_panel(grid, 0, 1, 1, 10)
+
+ box = ClipboardBox(self._shell, menu_shell)
+ root.append(box)
def _create_panel(self, grid, x, y, width, height):
panel = PanelWindow()
diff --git a/shell/view/frame/Makefile.am b/shell/view/frame/Makefile.am
index eec6d0f..23e24af 100644
--- a/shell/view/frame/Makefile.am
+++ b/shell/view/frame/Makefile.am
@@ -2,6 +2,7 @@ sugardir = $(pkgdatadir)/shell/view/frame
sugar_PYTHON = \
__init__.py \
ActivitiesBox.py \
+ ClipboardBox.py \
FriendsBox.py \
PanelWindow.py \
Frame.py \