From af8e9a556a0f035b231977964e6471cac233985c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
Date: Thu, 22 Nov 2012 16:16:06 -0300
Subject: [PATCH shell] Change Journal model to make the buddy icons work
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
---
src/jarabe/journal/listmodel.py | 22 ++++++++++++++-------
src/jarabe/journal/listview.py | 42 ++++++++++++++++++++++-------------------
2 files changed, 38 insertions(+), 26 deletions(-)
diff --git a/src/jarabe/journal/listmodel.py b/src/jarabe/journal/listmodel.py
index b98d01c..f0fd369 100644
a
|
b
|
class ListModel(GObject.GObject, Gtk.TreeModel, Gtk.TreeDragSource): |
51 | 51 | COLUMN_CREATION_TIME = 6 |
52 | 52 | COLUMN_FILESIZE = 7 |
53 | 53 | COLUMN_PROGRESS = 8 |
54 | | COLUMN_BUDDY_1 = 9 |
55 | | COLUMN_BUDDY_2 = 10 |
56 | | COLUMN_BUDDY_3 = 11 |
| 54 | COLUMN_BUDDY_1_NAME = 9 |
| 55 | COLUMN_BUDDY_1_COLOR = 10 |
| 56 | COLUMN_BUDDY_2_NAME = 11 |
| 57 | COLUMN_BUDDY_2_COLOR = 12 |
| 58 | COLUMN_BUDDY_3_NAME = 13 |
| 59 | COLUMN_BUDDY_3_COLOR = 14 |
57 | 60 | |
58 | 61 | _COLUMN_TYPES = { |
59 | 62 | COLUMN_UID: str, |
… |
… |
class ListModel(GObject.GObject, Gtk.TreeModel, Gtk.TreeDragSource): |
65 | 68 | COLUMN_CREATION_TIME: str, |
66 | 69 | COLUMN_FILESIZE: str, |
67 | 70 | COLUMN_PROGRESS: int, |
68 | | COLUMN_BUDDY_1: object, |
69 | | COLUMN_BUDDY_3: object, |
70 | | COLUMN_BUDDY_2: object, |
| 71 | COLUMN_BUDDY_1_NAME: str, |
| 72 | COLUMN_BUDDY_1_COLOR: object, |
| 73 | COLUMN_BUDDY_2_NAME: str, |
| 74 | COLUMN_BUDDY_2_COLOR: object, |
| 75 | COLUMN_BUDDY_3_NAME: str, |
| 76 | COLUMN_BUDDY_3_COLOR: object, |
71 | 77 | } |
72 | 78 | |
73 | 79 | _PAGE_SIZE = 10 |
… |
… |
class ListModel(GObject.GObject, Gtk.TreeModel, Gtk.TreeDragSource): |
194 | 200 | logging.warning('Malformed buddies for %r: %s', |
195 | 201 | metadata['uid'], exception) |
196 | 202 | else: |
197 | | self._cached_row.append((nick, XoColor(color))) |
| 203 | self._cached_row.append(nick) |
| 204 | self._cached_row.append(XoColor(color)) |
198 | 205 | continue |
199 | 206 | |
200 | 207 | self._cached_row.append(None) |
| 208 | self._cached_row.append(None) |
201 | 209 | |
202 | 210 | return self._cached_row[column] |
203 | 211 | |
diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
index 4af6e3c..787f4c1 100644
a
|
b
|
class BaseListView(Gtk.Bin): |
176 | 176 | buddies_column.props.sizing = Gtk.TreeViewColumnSizing.FIXED |
177 | 177 | self.tree_view.append_column(buddies_column) |
178 | 178 | |
179 | | for column_index in [ListModel.COLUMN_BUDDY_1, |
180 | | ListModel.COLUMN_BUDDY_2, |
181 | | ListModel.COLUMN_BUDDY_3]: |
182 | | cell_icon = CellRendererBuddy(self.tree_view, |
183 | | column_index=column_index) |
| 179 | for n_ in xrange(0, 3): |
| 180 | index_name = getattr(ListModel, 'COLUMN_BUDDY_' \ |
| 181 | + str(n_ + 1) + '_NAME') |
| 182 | index_color = getattr(ListModel, 'COLUMN_BUDDY_' \ |
| 183 | + str(n_ + 1) + '_COLOR') |
| 184 | cell_icon = CellRendererBuddy(self.tree_view) |
184 | 185 | buddies_column.pack_start(cell_icon, True) |
185 | 186 | buddies_column.props.fixed_width += cell_icon.props.width |
186 | | buddies_column.add_attribute(cell_icon, 'buddy', column_index) |
| 187 | buddies_column.add_attribute(cell_icon, 'buddy-name', |
| 188 | index_name) |
| 189 | buddies_column.add_attribute(cell_icon, 'xo-color', |
| 190 | index_color) |
187 | 191 | buddies_column.set_cell_data_func(cell_icon, |
188 | 192 | self.__buddies_set_data_cb) |
189 | 193 | |
… |
… |
class CellRendererActivityIcon(CellRendererIcon): |
663 | 667 | class CellRendererBuddy(CellRendererIcon): |
664 | 668 | __gtype_name__ = 'JournalCellRendererBuddy' |
665 | 669 | |
666 | | def __init__(self, tree_view, column_index): |
| 670 | def __init__(self, tree_view): |
667 | 671 | CellRendererIcon.__init__(self, tree_view) |
668 | 672 | |
669 | 673 | self.props.width = style.STANDARD_ICON_SIZE |
… |
… |
class CellRendererBuddy(CellRendererIcon): |
671 | 675 | self.props.size = style.STANDARD_ICON_SIZE |
672 | 676 | self.props.mode = Gtk.CellRendererMode.ACTIVATABLE |
673 | 677 | |
| 678 | self._buddy_name = None |
674 | 679 | self.tree_view = tree_view |
675 | | self._model_column_index = column_index |
676 | 680 | |
677 | 681 | def create_palette(self): |
678 | | tree_model = self.tree_view.get_model() |
679 | | row = tree_model[self.props.palette_invoker.path] |
680 | | |
681 | | if row[self._model_column_index] is not None: |
682 | | nick, xo_color = row[self._model_column_index] |
683 | | return BuddyPalette((nick, xo_color.to_string())) |
| 682 | if self.props.buddy_name is not None: |
| 683 | return BuddyPalette((self.props.buddy_name, |
| 684 | self.props.xo_color.to_string())) |
684 | 685 | else: |
685 | 686 | return None |
686 | 687 | |
687 | | def set_buddy(self, buddy): |
688 | | if buddy is None: |
| 688 | def set_buddy_name(self, buddy_name): |
| 689 | self._buddy_name = buddy_name |
| 690 | if buddy_name is None: |
689 | 691 | self.props.icon_name = None |
690 | 692 | else: |
691 | | nick_, xo_color = buddy |
692 | 693 | self.props.icon_name = 'computer-xo' |
693 | | self.props.xo_color = xo_color |
694 | 694 | |
695 | | buddy = GObject.property(type=object, setter=set_buddy) |
| 695 | def get_buddy_name(self): |
| 696 | return self._buddy_name |
| 697 | |
| 698 | buddy_name = GObject.property(type=str, getter=get_buddy_name, |
| 699 | setter=set_buddy_name) |