First patch in the shell redesign series.
Thanks,
Tomeu
From 41a234e538402a71b44f036e101f259f4321b354 Mon Sep 17 00:00:00 2001
From: Tomeu Vizoso <[EMAIL PROTECTED]>
Date: Tue, 1 Apr 2008 19:33:56 +0200
Subject: [PATCH] New clipboard tray
---
src/view/clipboardmenu.py | 11 ++-
src/view/frame/Makefile.am | 2 +-
src/view/frame/clipboardbox.py | 193 --------------------------------
src/view/frame/clipboardpanelwindow.py | 15 ++-
src/view/frame/clipboardtray.py | 191 +++++++++++++++++++++++++++++++
5 files changed, 209 insertions(+), 203 deletions(-)
delete mode 100644 src/view/frame/clipboardbox.py
create mode 100644 src/view/frame/clipboardtray.py
diff --git a/src/view/clipboardmenu.py b/src/view/clipboardmenu.py
index b847828..7df2ee0 100644
--- a/src/view/clipboardmenu.py
+++ b/src/view/clipboardmenu.py
@@ -25,6 +25,7 @@ import hippo
from sugar.graphics.palette import Palette
from sugar.graphics.menuitem import MenuItem
+from sugar.graphics.icon import Icon
from sugar.graphics import style
from sugar.clipboard import clipboardservice
from sugar.datastore import datastore
@@ -60,7 +61,7 @@ class ClipboardMenu(Palette):
self.menu.append(self._remove_item)
self._remove_item.show()
- self._open_item = MenuItem(_('Open'))
+ self._open_item = MenuItem(_('Open'), 'zoom-activity')
self._open_item.connect('activate', self._open_item_activate_cb)
self.menu.append(self._open_item)
self._open_item.show()
@@ -70,7 +71,11 @@ class ClipboardMenu(Palette):
#self._stop_item.connect('activate', self._stop_item_activate_cb)
#self.append_menu_item(self._stop_item)
- self._journal_item = MenuItem(_('Add to journal'), 'document-save')
+ self._journal_item = MenuItem(_('Keep'))
+ icon = Icon(icon_name='document-save', icon_size=gtk.ICON_SIZE_MENU,
+ xo_color=profile.get_color())
+ self._journal_item.set_image(icon)
+
self._journal_item.connect('activate', self._journal_item_activate_cb)
self.menu.append(self._journal_item)
self._journal_item.show()
@@ -81,10 +86,12 @@ class ClipboardMenu(Palette):
def _update_open_submenu(self):
logging.debug('_update_open_submenu: %r' % self._activities)
if self._activities is None or len(self._activities) <= 1:
+ self._open_item.child.set_text(_('Open'))
if self._open_item.get_submenu() is not None:
self._open_item.remove_submenu()
return
+ self._open_item.child.set_text(_('Open with'))
submenu = self._open_item.get_submenu()
if submenu is None:
submenu = gtk.Menu()
diff --git a/src/view/frame/Makefile.am b/src/view/frame/Makefile.am
index 02951b9..9bf5952 100644
--- a/src/view/frame/Makefile.am
+++ b/src/view/frame/Makefile.am
@@ -3,8 +3,8 @@ sugar_PYTHON = \
__init__.py \
activitiestray.py \
activitybutton.py \
- clipboardbox.py \
clipboardpanelwindow.py \
+ clipboardtray.py \
frameinvoker.py \
friendstray.py \
eventarea.py \
diff --git a/src/view/frame/clipboardbox.py b/src/view/frame/clipboardbox.py
deleted file mode 100644
index 7702759..0000000
--- a/src/view/frame/clipboardbox.py
+++ /dev/null
@@ -1,193 +0,0 @@
-# Copyright (C) 2007, One Laptop Per Child
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-import os
-import logging
-import tempfile
-
-import hippo
-import gtk
-
-from sugar import util
-from sugar.clipboard import clipboardservice
-from sugar.graphics.tray import VTray
-from sugar.graphics import style
-
-from view.clipboardicon import ClipboardIcon
-
-class _ContextMap:
- """Maps a drag context to the clipboard object involved in the dragging."""
- def __init__(self):
- self._context_map = {}
-
- def add_context(self, context, object_id, data_types):
- """Establishes the mapping. data_types will serve us for reference-
- counting this mapping.
- """
- self._context_map[context] = [object_id, data_types]
-
- def get_object_id(self, context):
- """Retrieves the object_id associated with context.
- Will release the association when this function was called as many times
- as the number of data_types that this clipboard object contains.
- """
- [object_id, data_types_left] = self._context_map[context]
-
- data_types_left = data_types_left - 1
- if data_types_left == 0:
- del self._context_map[context]
- else:
- self._context_map[context] = [object_id, data_types_left]
-
- return object_id
-
- def has_context(self, context):
- return context in self._context_map
-
-class ClipboardBox(hippo.CanvasBox):
-
- MAX_ITEMS = gtk.gdk.screen_height() / style.GRID_CELL_SIZE - 2
-
- def __init__(self):
- hippo.CanvasBox.__init__(self)
- self._icons = {}
- self._context_map = _ContextMap()
-
- self._tray = VTray()
- self.append(hippo.CanvasWidget(widget=self._tray), hippo.PACK_EXPAND)
- self._tray.show()
-
- cb_service = clipboardservice.get_instance()
- cb_service.connect('object-added', self._object_added_cb)
- cb_service.connect('object-deleted', self._object_deleted_cb)
-
- def owns_clipboard(self):
- for icon in self._icons.values():
- if icon.owns_clipboard:
- return True
- return False
-
- def _add_selection(self, object_id, selection):
- if not selection.data:
- return
-
- logging.debug('ClipboardBox: adding type ' + selection.type)
-
- cb_service = clipboardservice.get_instance()
- if selection.type == 'text/uri-list':
- uris = selection.data.split('\n')
- if len(uris) > 1:
- raise NotImplementedError('Multiple uris in text/uri-list still not supported.')
-
- cb_service.add_object_format(object_id,
- selection.type,
- uris[0],
- on_disk=True)
- else:
- cb_service.add_object_format(object_id,
- selection.type,
- selection.data,
- on_disk=False)
-
- def _object_added_cb(self, cb_service, object_id, name):
- if self._icons:
- group = self._icons.values()[0]
- else:
- group = None
-
- icon = ClipboardIcon(object_id, name, group)
- self._tray.add_item(icon, 0)
- icon.show()
- self._icons[object_id] = icon
-
- objects_to_delete = self._tray.get_children()[ClipboardBox.MAX_ITEMS:]
- for icon in objects_to_delete:
- logging.debug('ClipboardBox: deleting surplus object')
- cb_service = clipboardservice.get_instance()
- cb_service.delete_object(icon.get_object_id())
-
- logging.debug('ClipboardBox: ' + object_id + ' was added.')
-
- def _object_deleted_cb(self, cb_service, object_id):
- icon = self._icons[object_id]
- self._tray.remove_item(icon)
- del self._icons[object_id]
- logging.debug('ClipboardBox: ' + object_id + ' was deleted.')
-
- def drag_motion_cb(self, widget, context, x, y, time):
- logging.debug('ClipboardBox._drag_motion_cb')
- context.drag_status(gtk.gdk.ACTION_COPY, time)
- return True;
-
- def drag_drop_cb(self, widget, context, x, y, time):
- logging.debug('ClipboardBox._drag_drop_cb')
- cb_service = clipboardservice.get_instance()
- object_id = cb_service.add_object(name="")
-
- self._context_map.add_context(context, object_id, len(context.targets))
-
- if 'XdndDirectSave0' in context.targets:
- window = context.source_window
- prop_type, format, filename = \
- window.property_get('XdndDirectSave0','text/plain')
-
- # FIXME query the clipboard service for a filename?
- base_dir = tempfile.gettempdir()
- dest_filename = util.unique_id()
-
- name, dot, extension = filename.rpartition('.')
- dest_filename += dot + extension
-
- dest_uri = 'file://' + os.path.join(base_dir, dest_filename)
-
- window.property_change('XdndDirectSave0', prop_type, format,
- gtk.gdk.PROP_MODE_REPLACE, dest_uri)
-
- widget.drag_get_data(context, 'XdndDirectSave0', time)
- else:
- for target in context.targets:
- if str(target) not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE'):
- widget.drag_get_data(context, target, time)
-
- cb_service.set_object_percent(object_id, percent=100)
-
- return True
-
- def drag_data_received_cb(self, widget, context, x, y, selection, targetType, time):
- logging.debug('ClipboardBox: got data for target %r' % selection.target)
-
- object_id = self._context_map.get_object_id(context)
- try:
- if selection is None:
- logging.warn('ClipboardBox: empty selection for target ' + selection.target)
- elif selection.target == 'XdndDirectSave0':
- if selection.data == 'S':
- window = context.source_window
-
- prop_type, format, dest = \
- window.property_get('XdndDirectSave0','text/plain')
-
- clipboard = clipboardservice.get_instance()
- clipboard.add_object_format(
- object_id, 'XdndDirectSave0', dest, on_disk=True)
- else:
- self._add_selection(object_id, selection)
-
- finally:
- # If it's the last target to be processed, finish the dnd transaction
- if not self._context_map.has_context(context):
- context.drop_finish(True, gtk.get_current_event_time())
-
diff --git a/src/view/frame/clipboardpanelwindow.py b/src/view/frame/clipboardpanelwindow.py
index e579b8c..04e7408 100644
--- a/src/view/frame/clipboardpanelwindow.py
+++ b/src/view/frame/clipboardpanelwindow.py
@@ -21,7 +21,7 @@ import gtk
import hippo
from view.frame.framewindow import FrameWindow
-from view.frame.clipboardbox import ClipboardBox
+from view.frame.clipboardtray import ClipboardTray
from sugar.clipboard import clipboardservice
from sugar import util
@@ -37,20 +37,21 @@ class ClipboardPanelWindow(FrameWindow):
self._clipboard = gtk.Clipboard()
self._clipboard.connect("owner-change", self._owner_change_cb)
- self._clipboard_box = ClipboardBox()
- self.append(self._clipboard_box, hippo.PACK_EXPAND)
+ self._clipboard_tray = ClipboardTray()
+ canvas_widget = hippo.CanvasWidget(widget=self._clipboard_tray)
+ self.append(canvas_widget, hippo.PACK_EXPAND)
# Receiving dnd drops
self.drag_dest_set(0, [], 0)
- self.connect("drag_motion", self._clipboard_box.drag_motion_cb)
- self.connect("drag_drop", self._clipboard_box.drag_drop_cb)
+ self.connect("drag_motion", self._clipboard_tray.drag_motion_cb)
+ self.connect("drag_drop", self._clipboard_tray.drag_drop_cb)
self.connect("drag_data_received",
- self._clipboard_box.drag_data_received_cb)
+ self._clipboard_tray.drag_data_received_cb)
def _owner_change_cb(self, clipboard, event):
logging.debug("owner_change_cb")
- if self._clipboard_box.owns_clipboard():
+ if self._clipboard_tray.owns_clipboard():
return
cb_service = clipboardservice.get_instance()
diff --git a/src/view/frame/clipboardtray.py b/src/view/frame/clipboardtray.py
new file mode 100644
index 0000000..a85551a
--- /dev/null
+++ b/src/view/frame/clipboardtray.py
@@ -0,0 +1,191 @@
+# Copyright (C) 2007, One Laptop Per Child
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import os
+import logging
+import tempfile
+
+import gtk
+
+from sugar import util
+from sugar.clipboard import clipboardservice
+from sugar.graphics.tray import VTray
+from sugar.graphics import style
+
+from view.clipboardicon import ClipboardIcon
+
+class _ContextMap:
+ """Maps a drag context to the clipboard object involved in the dragging."""
+ def __init__(self):
+ self._context_map = {}
+
+ def add_context(self, context, object_id, data_types):
+ """Establishes the mapping. data_types will serve us for reference-
+ counting this mapping.
+ """
+ self._context_map[context] = [object_id, data_types]
+
+ def get_object_id(self, context):
+ """Retrieves the object_id associated with context.
+ Will release the association when this function was called as many times
+ as the number of data_types that this clipboard object contains.
+ """
+ [object_id, data_types_left] = self._context_map[context]
+
+ data_types_left = data_types_left - 1
+ if data_types_left == 0:
+ del self._context_map[context]
+ else:
+ self._context_map[context] = [object_id, data_types_left]
+
+ return object_id
+
+ def has_context(self, context):
+ return context in self._context_map
+
+class ClipboardTray(VTray):
+
+ MAX_ITEMS = gtk.gdk.screen_height() / style.GRID_CELL_SIZE - 2
+
+ def __init__(self):
+ VTray.__init__(self)
+ self._icons = {}
+ self._context_map = _ContextMap()
+
+ cb_service = clipboardservice.get_instance()
+ cb_service.connect('object-added', self._object_added_cb)
+ cb_service.connect('object-deleted', self._object_deleted_cb)
+
+ def owns_clipboard(self):
+ for icon in self._icons.values():
+ if icon.owns_clipboard:
+ return True
+ return False
+
+ def _add_selection(self, object_id, selection):
+ if not selection.data:
+ return
+
+ logging.debug('ClipboardTray: adding type ' + selection.type)
+
+ cb_service = clipboardservice.get_instance()
+ if selection.type == 'text/uri-list':
+ uris = selection.data.split('\n')
+ if len(uris) > 1:
+ raise NotImplementedError('Multiple uris in text/uri-list still not supported.')
+
+ cb_service.add_object_format(object_id,
+ selection.type,
+ uris[0],
+ on_disk=True)
+ else:
+ cb_service.add_object_format(object_id,
+ selection.type,
+ selection.data,
+ on_disk=False)
+
+ def _object_added_cb(self, cb_service, object_id, name):
+ if self._icons:
+ group = self._icons.values()[0]
+ else:
+ group = None
+
+ icon = ClipboardIcon(object_id, name, group)
+ # TODO: cannot use pack_end here as it would store the icon in a
+ # different structure.
+ self.add_item(icon)
+ #self.pack_end(icon, expand=False, fill=False, padding=0)
+ icon.show()
+ self._icons[object_id] = icon
+
+ objects_to_delete = self.get_children()[self.MAX_ITEMS:]
+ for icon in objects_to_delete:
+ logging.debug('ClipboardTray: deleting surplus object')
+ cb_service = clipboardservice.get_instance()
+ cb_service.delete_object(icon.get_object_id())
+
+ logging.debug('ClipboardTray: ' + object_id + ' was added.')
+
+ def _object_deleted_cb(self, cb_service, object_id):
+ icon = self._icons[object_id]
+ self.remove_item(icon)
+ del self._icons[object_id]
+ logging.debug('ClipboardTray: ' + object_id + ' was deleted.')
+
+ def drag_motion_cb(self, widget, context, x, y, time):
+ logging.debug('ClipboardTray._drag_motion_cb')
+ context.drag_status(gtk.gdk.ACTION_COPY, time)
+ return True
+
+ def drag_drop_cb(self, widget, context, x, y, time):
+ logging.debug('ClipboardTray._drag_drop_cb')
+ cb_service = clipboardservice.get_instance()
+ object_id = cb_service.add_object(name="")
+
+ self._context_map.add_context(context, object_id, len(context.targets))
+
+ if 'XdndDirectSave0' in context.targets:
+ window = context.source_window
+ prop_type, format, filename = \
+ window.property_get('XdndDirectSave0','text/plain')
+
+ # FIXME query the clipboard service for a filename?
+ base_dir = tempfile.gettempdir()
+ dest_filename = util.unique_id()
+
+ name, dot, extension = filename.rpartition('.')
+ dest_filename += dot + extension
+
+ dest_uri = 'file://' + os.path.join(base_dir, dest_filename)
+
+ window.property_change('XdndDirectSave0', prop_type, format,
+ gtk.gdk.PROP_MODE_REPLACE, dest_uri)
+
+ widget.drag_get_data(context, 'XdndDirectSave0', time)
+ else:
+ for target in context.targets:
+ if str(target) not in ('TIMESTAMP', 'TARGETS', 'MULTIPLE'):
+ widget.drag_get_data(context, target, time)
+
+ cb_service.set_object_percent(object_id, percent=100)
+
+ return True
+
+ def drag_data_received_cb(self, widget, context, x, y, selection, targetType, time):
+ logging.debug('ClipboardTray: got data for target %r' % selection.target)
+
+ object_id = self._context_map.get_object_id(context)
+ try:
+ if selection is None:
+ logging.warn('ClipboardTray: empty selection for target ' + selection.target)
+ elif selection.target == 'XdndDirectSave0':
+ if selection.data == 'S':
+ window = context.source_window
+
+ prop_type, format, dest = \
+ window.property_get('XdndDirectSave0','text/plain')
+
+ clipboard = clipboardservice.get_instance()
+ clipboard.add_object_format(
+ object_id, 'XdndDirectSave0', dest, on_disk=True)
+ else:
+ self._add_selection(object_id, selection)
+
+ finally:
+ # If it's the last target to be processed, finish the dnd transaction
+ if not self._context_map.has_context(context):
+ context.drop_finish(True, gtk.get_current_event_time())
+
--
1.5.2.5
_______________________________________________
Sugar mailing list
[email protected]
http://lists.laptop.org/listinfo/sugar