On Mon, Apr 21, 2008 at 1:24 PM, Tomeu Vizoso <[EMAIL PROTECTED]> wrote:
> On Mon, Apr 21, 2008 at 7:20 PM, Eben Eliason <[EMAIL PROTECTED]> wrote:
> > > +from palettes import JobjectPalette, BuddyPalette
> > >
> > > What about EntryPalette instead of JobjectPalette? An entry in the
> > > journal is the UI representation of a datastore object/
> > >
> > > self._jobject = None
> > > + self._jobject_palette = None
> > >
> > > Same here, _jobject is the data, CollapsedEntry is one of the UI views
> > > of this data. I would call it _palette instead of _jobject_palette.
> >
> > Well, that's not actually accurate. See, the Collapsed entry is a
> > "container" for the entry, which contains various details about it.
> > The palette is specifically attached to the "object" itself, and not
> > the entry. Consider, for instance, an entry (in the future) with
> > several objects in it. Consider also, in the current design, that a
> > single entry may also have several people icons (and palettes)
> > attached to it. We need to make it clear that the palette belongs to
> > the icon/object and not the entry as a whole.
> >
> > I chose JobjectPalette and BuddyPalette since a) it seems like the
> > most direct mapping and b) these are also the classes of object that
> > they take as arguments to the constructor.
>
> I see. I would prefer ObjectPalette then. a) is the right reason but
> b) shouldn't affect the name of the class.
ObjectPalette it is. I also replaced commented blocks with TODOs and
added a condition in the delete signal handler to ensure that the
deleted object was the one currently shown in detail view.
- Eben
From ad32ad1f71f0e7b9cc514211f9820fdd7f4f31dc Mon Sep 17 00:00:00 2001
From: Eben Eliason <[EMAIL PROTECTED]>
Date: Sat, 19 Apr 2008 05:57:35 -0400
Subject: [PATCH] Add palettes to people and objects in Journal
---
collapsedentry.py | 7 +++
detailview.py | 3 +
expandedentry.py | 10 ++++-
journalactivity.py | 9 ++--
journaltoolbox.py | 9 ----
palettes.py | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 141 insertions(+), 14 deletions(-)
create mode 100644 palettes.py
diff --git a/collapsedentry.py b/collapsedentry.py
index 4b5efdf..e2fc149 100644
--- a/collapsedentry.py
+++ b/collapsedentry.py
@@ -31,6 +31,7 @@ from sugar.graphics.roundbox import CanvasRoundBox
from sugar.graphics.entry import CanvasEntry
from keepicon import KeepIcon
+from palettes import ObjectPalette, BuddyPalette
import misc
class BuddyList(hippo.CanvasBox):
@@ -50,6 +51,7 @@ class BuddyList(hippo.CanvasBox):
icon = CanvasIcon(icon_name='computer-xo',
xo_color=XoColor(color),
cache=True)
+ icon.set_palette(BuddyPalette(buddy))
self.append(icon)
class CollapsedEntry(hippo.CanvasBox):
@@ -76,6 +78,7 @@ class CollapsedEntry(hippo.CanvasBox):
orientation=hippo.ORIENTATION_HORIZONTAL)
self._jobject = None
+ self._object_palette = None
self._allow_resume = allow_resume
self._is_selected = False
@@ -266,6 +269,7 @@ class CollapsedEntry(hippo.CanvasBox):
self._cancel_title_change()
elif self._title.props.text != title:
self._title.props.text = title
+ self._object_palette.props.primary_text = title
self._jobject.metadata['title'] = title
self._jobject.metadata['title_set_by_user'] = '1'
datastore.write(self._jobject, update_mtime=False,
@@ -333,6 +337,9 @@ class CollapsedEntry(hippo.CanvasBox):
self._title.props.text = self._format_title()
self._title_entry.props.text = self._format_title()
+ self._object_palette = ObjectPalette(jobject)
+ self._icon.set_palette(self._object_palette)
+
self._buddies_list.set_model(self._decode_buddies())
if jobject.metadata.has_key('progress'):
diff --git a/detailview.py b/detailview.py
index 66fc62e..a08d0bc 100644
--- a/detailview.py
+++ b/detailview.py
@@ -80,6 +80,9 @@ class DetailView(gtk.VBox):
self._jobject = jobject
self._update_view()
+ def get_object_id(self):
+ return self._jobject.object_id
+
def refresh(self):
logging.debug('DetailView.refresh')
if self._jobject:
diff --git a/expandedentry.py b/expandedentry.py
index 1bb7993..031c270 100644
--- a/expandedentry.py
+++ b/expandedentry.py
@@ -34,6 +34,8 @@ from sugar.datastore import datastore
from tagbox import TagBox
from keepicon import KeepIcon
+from palettes import ObjectPalette, BuddyPalette
+
import misc
class Separator(hippo.CanvasBox, hippo.CanvasItem):
@@ -75,6 +77,7 @@ class BuddyList(hippo.CanvasBox):
icon = CanvasIcon(icon_name='computer-xo',
xo_color=XoColor(color),
size=style.STANDARD_ICON_SIZE)
+ icon.set_palette(BuddyPalette(buddy))
hbox.append(icon)
self.append(hbox)
@@ -86,6 +89,7 @@ class ExpandedEntry(hippo.CanvasBox):
self.props.padding_top = style.DEFAULT_SPACING * 3
self._jobject = datastore.get(object_id)
+ self._object_palette = None
self._update_title_sid = None
# Create header
@@ -163,7 +167,10 @@ class ExpandedEntry(hippo.CanvasBox):
self._jobject.metadata['icon-color']:
icon.props.xo_color = XoColor( \
self._jobject.metadata['icon-color'])
-
+
+ self._object_palette = ObjectPalette(self._jobject)
+ icon.set_palette(self._object_palette)
+
return icon
def _create_title(self):
@@ -343,6 +350,7 @@ class ExpandedEntry(hippo.CanvasBox):
old_title = self._jobject.metadata.get('title', None)
if old_title != self._title.props.text:
+ self._object_palette.props.primary_text = self._title.props.text
self._jobject.metadata['title'] = self._title.props.text
self._jobject.metadata['title_set_by_user'] = '1'
needs_update = True
diff --git a/journalactivity.py b/journalactivity.py
index ab7a313..03509ed 100755
--- a/journalactivity.py
+++ b/journalactivity.py
@@ -136,6 +136,7 @@ class JournalActivity(activity.Activity):
bus.get_object(DS_DBUS_SERVICE, DS_DBUS_PATH), DS_DBUS_INTERFACE)
data_store.connect_to_signal('Created', self._data_store_created_cb)
data_store.connect_to_signal('Updated', self._data_store_updated_cb)
+ data_store.connect_to_signal('Deleted', self._data_store_deleted_cb)
self._dbus_service = JournalActivityDBusService(self)
@@ -164,7 +165,6 @@ class JournalActivity(activity.Activity):
self._detail_toolbox = DetailToolbox()
entry_toolbar = self._detail_toolbox.entry_toolbar
- entry_toolbar.connect('entry-erased', self._entry_erased_cb)
self._detail_view = DetailView()
self._detail_view.connect('go-back-clicked', self.__go_back_clicked_cb)
@@ -228,9 +228,6 @@ class JournalActivity(activity.Activity):
self._show_secondary_view(jobject)
return True
- def _entry_erased_cb(self, toolbar):
- self._show_main_view()
-
def _volume_changed_cb(self, volume_toolbar, volume_id):
logging.debug('Selected volume: %r.' % volume_id)
self._main_toolbox.search_toolbar.set_volume_id(volume_id)
@@ -255,6 +252,10 @@ class JournalActivity(activity.Activity):
finally:
jobject.destroy()
+ def _data_store_deleted_cb(self, uid):
+ if uid == self._detail_view.get_object_id():
+ self._show_main_view()
+
def _focus_in_event_cb(self, window, event):
self.search_grab_focus()
self._list_view.update_dates()
diff --git a/journaltoolbox.py b/journaltoolbox.py
index 98d549b..08b6157 100644
--- a/journaltoolbox.py
+++ b/journaltoolbox.py
@@ -317,14 +317,6 @@ class DetailToolbox(Toolbox):
self.entry_toolbar.show()
class EntryToolbar(gtk.Toolbar):
- __gtype_name__ = 'EntryToolbar'
-
- __gsignals__ = {
- 'entry-erased' : (gobject.SIGNAL_RUN_FIRST,
- gobject.TYPE_NONE,
- ([]))
- }
-
def __init__(self):
gtk.Toolbar.__init__(self)
@@ -381,7 +373,6 @@ class EntryToolbar(gtk.Toolbar):
if bundle is not None and bundle.is_installed():
bundle.uninstall()
datastore.delete(self._jobject.object_id)
- self.emit('entry-erased')
def _resume_menu_item_activate_cb(self, menu_item, service_name):
if self._jobject:
diff --git a/palettes.py b/palettes.py
new file mode 100644
index 0000000..2eb389e
--- /dev/null
+++ b/palettes.py
@@ -0,0 +1,117 @@
+# Copyright (C) 2008 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 statvfs
+import logging
+from gettext import gettext as _
+
+import gtk
+
+from sugar import env
+from sugar import profile
+from sugar.graphics import style
+from sugar.graphics.palette import Palette
+from sugar.graphics.menuitem import MenuItem
+from sugar.graphics.icon import Icon
+from sugar.datastore import datastore
+from sugar.graphics.xocolor import XoColor
+
+import misc
+
+class ObjectPalette(Palette):
+ def __init__(self, jobject):
+
+ self._jobject = jobject
+
+ activity_icon = Icon(icon_size=gtk.ICON_SIZE_LARGE_TOOLBAR)
+ activity_icon.props.file = misc.get_icon_name(jobject)
+ if jobject.metadata.has_key('icon-color') and \
+ jobject.metadata['icon-color']:
+ activity_icon.props.xo_color = \
+ XoColor(jobject.metadata['icon-color'])
+ else:
+ avtivity_icon.props.xo_color = \
+ XoColor('%s,%s' % (style.COLOR_BUTTON_GREY.get_svg(),
+ style.COLOR_TRANSPARENT.get_svg()))
+
+ if jobject.metadata.has_key('title'):
+ title = jobject.metadata['title']
+ else:
+ title = _('Untitled')
+
+ Palette.__init__(self, primary_text=title,
+ icon=activity_icon)
+
+ if jobject.metadata.get('activity_id', ''):
+ resume_label = _('Resume')
+ else:
+ resume_label = _('Start')
+ menu_item = MenuItem(resume_label, 'activity-start')
+ menu_item.connect('activate', self.__start_activate_cb)
+ self.menu.append(menu_item)
+ menu_item.show()
+
+ # TODO: Add "Start with" menu item
+
+ menu_item = MenuItem(_('Copy'))
+ icon = Icon(icon_name='edit-copy', xo_color=profile.get_color(),
+ icon_size=gtk.ICON_SIZE_MENU)
+ menu_item.set_image(icon)
+ menu_item.connect('activate', self.__copy_activate_cb)
+ self.menu.append(menu_item)
+ menu_item.show()
+
+ menu_item = MenuItem(_('Erase'), 'dialog-cancel')
+ menu_item.connect('activate', self.__erase_activate_cb)
+ self.menu.append(menu_item)
+ menu_item.show()
+
+ def __start_activate_cb(self, menu_item):
+ self._jobject.resume()
+
+ def __copy_activate_cb(self, menu_item):
+ clipboard = gtk.Clipboard()
+ clipboard.set_with_data([('text/uri-list', 0, 0)],
+ self.__clipboard_get_func_cb,
+ self.__clipboard_clear_func_cb)
+
+ def __clipboard_get_func_cb(self, clipboard, selection_data, info, data):
+ selection_data.set('text/uri-list', 8, self._jobject.file_path)
+
+ def __clipboard_clear_func_cb(self, clipboard, data):
+ pass
+
+ def __erase_activate_cb(self, menu_item):
+ bundle = misc.get_bundle(self._jobject)
+ if bundle is not None and bundle.is_installed():
+ bundle.uninstall()
+ datastore.delete(self._jobject.object_id)
+
+
+class BuddyPalette(Palette):
+ def __init__(self, buddy):
+ self._buddy = buddy
+
+ nick, colors = buddy
+ buddy_icon = Icon(icon_name='computer-xo',
+ icon_size=style.STANDARD_ICON_SIZE,
+ xo_color=XoColor(colors))
+
+ Palette.__init__(self, primary_text=nick,
+ icon=buddy_icon)
+
+ # TODO: Support actions on buddies, like make friend, invite, etc.
--
1.5.3.3
_______________________________________________
Sugar mailing list
[email protected]
http://lists.laptop.org/listinfo/sugar