diff options
author | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2007-06-14 14:09:03 (GMT) |
---|---|---|
committer | Tomeu Vizoso <tomeu@tomeuvizoso.net> | 2007-06-14 14:09:03 (GMT) |
commit | 7146e50b60183fbcec46e8fc9e72cf7c1f52eb1e (patch) | |
tree | f86a21a68f0b735ec7bd18c6a5eaec453abf5412 /collapsedentry.py | |
parent | f0ef807e60085aebeedcb78133103e410e5a27bf (diff) |
Some refactoring. JournalEntry will have quite a bit of common functionality.
Diffstat (limited to 'collapsedentry.py')
-rw-r--r-- | collapsedentry.py | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/collapsedentry.py b/collapsedentry.py new file mode 100644 index 0000000..5b7863c --- /dev/null +++ b/collapsedentry.py @@ -0,0 +1,101 @@ +# 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 logging +from gettext import gettext as _ + +import hippo +import pango + +from sugar.graphics.canvasicon import CanvasIcon +from sugar.graphics.xocolor import XoColor +from sugar.graphics import font +from sugar.graphics import color +from sugar.graphics import units +from sugar.date import Date +from sugar.datastore import datastore + +from journalentry import JournalEntry +from buddylist import BuddyList + +class CollapsedEntry(JournalEntry): + _DATE_COL_WIDTH = units.points_to_pixels(150) + _BUDDIES_COL_WIDTH = units.points_to_pixels(60) + + def __init__(self, jobject): + JournalEntry.__init__(self, jobject) + self.props.box_height = units.grid_to_pixels(1) + self.props.spacing = units.points_to_pixels(5) + + date = hippo.CanvasText(text=self.format_date(), + xalign=hippo.ALIGNMENT_START, + font_desc=font.DEFAULT.get_pango_desc(), + box_width=self._DATE_COL_WIDTH) + self.append(date) + + icon = CanvasIcon(icon_name=self.get_icon_name(), + xo_color=XoColor(self.jobject.metadata['icon-color']), + box_width=units.grid_to_pixels(1)) + self.append(icon) + + title = hippo.CanvasText(text=self._format_title(), + xalign=hippo.ALIGNMENT_START, + font_desc=font.DEFAULT_BOLD.get_pango_desc(), + size_mode=hippo.CANVAS_SIZE_WRAP_WORD) + self.append(title) + + """ + if self.jobject.metadata['buddies']: + with_label = hippo.CanvasText(text=_('with:'), + xalign=hippo.ALIGNMENT_START) + with_label.props.font_desc=font.DEFAULT.get_pango_desc() + self.append(with_label, hippo.PACK_EXPAND) + + self._buddies = BuddyList(self._decode_buddy_list(self.jobject.metadata['buddies']), + self._BUDDIES_COL_WIDTH) + self.append(self._buddies) + """ + def _decode_buddy_list(self, string): + # Take out first and last brackets. + string = string.strip('[]') + # Split in buddies. + buddies = string.split('}, {') + # Take out first and last buddies' extra keys. + buddies[0] = buddies[0].strip('{') + buddies[len(buddies) - 1] = buddies[len(buddies) - 1].strip('}') + + buddy_list = [] + for buddy in buddies: + properties = buddy.split(', ') + buddy_dict = {} + + # color property + prop_key = properties[0].split(': ')[0] + prop_value = properties[0].split(': ')[1] + buddy_dict[prop_key.strip("'")] = prop_value.strip("'") + + # name property + prop_key = properties[1].split(': ')[0] + prop_value = properties[1].split(': ')[1] + buddy_dict[prop_key.strip("'")] = prop_value.strip("'") + + buddy_list.append(buddy_dict) + + return buddy_list + + def _format_title(self): + return '"%s"' % self.jobject.metadata['title'] + |