Skip to content

Commit

Permalink
Use the TreeViewInvoker
Browse files Browse the repository at this point in the history
Use the TreeViewIvoker, need move the creation fo the palettes,
from the CellRendererIcons to the TreeViews.
This simplify the code, and allow create the palettes only wehen needed.
  • Loading branch information
godiard committed May 9, 2014
1 parent 24419d9 commit 379da72
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 92 deletions.
47 changes: 23 additions & 24 deletions src/jarabe/desktop/activitieslist.py
Expand Up @@ -36,6 +36,7 @@
from sugar3.graphics.alert import Alert
from sugar3.graphics.palettemenu import PaletteMenuItem
from sugar3.graphics.scrollingdetector import ScrollingDetector
from sugar3.graphics.palettewindow import TreeViewInvoker

from jarabe.model import bundleregistry
from jarabe.model import desktop
Expand Down Expand Up @@ -72,16 +73,15 @@ def __init__(self):

cell_favorites = []
for i in range(desktop.get_number_of_views()):
cell_favorites.append(CellRendererFavorite(self, i))
cell_favorites.append(CellRendererFavorite(i))
cell_favorites[i].connect('clicked', self.__favorite_clicked_cb)
column.pack_start(cell_favorites[i], True)
column.set_cell_data_func(cell_favorites[i],
self.__favorite_set_data_cb)

self.append_column(column)

cell_icon = CellRendererActivityIcon(self)
cell_icon.connect('erase-activated', self.__erase_activated_cb)
cell_icon = CellRendererActivityIcon()
cell_icon.connect('clicked', self.__icon_clicked_cb)

column = Gtk.TreeViewColumn()
Expand Down Expand Up @@ -135,8 +135,8 @@ def __init__(self):
self.set_search_column(self._model.column_title)
self.set_enable_search(False)

def __erase_activated_cb(self, cell_renderer, bundle_id):
self.emit('erase-activated', bundle_id)
self._invoker = TreeViewInvoker()
self._invoker.attach_treeview(self)

def __favorite_set_data_cb(self, column, cell, model, tree_iter, data):
favorite = \
Expand Down Expand Up @@ -186,6 +186,20 @@ def do_row_activated(self, path, column):
if column == self._icon_column:
self._start_activity(path)

def create_palette(self, path, column):
if column == self._icon_column:
row = self.get_model()[path]
bundle_id = row[self.get_model().column_bundle_id]

registry = bundleregistry.get_registry()
palette = ActivityListPalette(registry.get_bundle(bundle_id))
palette.connect('erase-activated', self.__erase_activated_cb,
bundle_id)
return palette

def __erase_activated_cb(self, palette, event, bundle_id):
self.emit('erase-activated', bundle_id)


class ListModel(Gtk.TreeModelSort):
__gtype_name__ = 'SugarListModel'
Expand Down Expand Up @@ -296,8 +310,8 @@ def refilter(self):
class CellRendererFavorite(CellRendererIcon):
__gtype_name__ = 'SugarCellRendererFavorite'

def __init__(self, tree_view, favorite_view):
CellRendererIcon.__init__(self, tree_view)
def __init__(self, favorite_view):
CellRendererIcon.__init__(self)

self.favorite_view = favorite_view
self.props.width = style.GRID_CELL_SIZE
Expand All @@ -318,8 +332,8 @@ class CellRendererActivityIcon(CellRendererIcon):
([str])),
}

def __init__(self, tree_view):
CellRendererIcon.__init__(self, tree_view)
def __init__(self):
CellRendererIcon.__init__(self)

self.props.width = style.GRID_CELL_SIZE
self.props.height = style.GRID_CELL_SIZE
Expand All @@ -332,21 +346,6 @@ def __init__(self, tree_view):
self.props.prelit_stroke_color = prelit_color.get_stroke_color()
self.props.prelit_fill_color = prelit_color.get_fill_color()

self._tree_view = tree_view

def create_palette(self):
model = self._tree_view.get_model()
row = model[self.props.palette_invoker.path]
bundle_id = row[model.column_bundle_id]

registry = bundleregistry.get_registry()
palette = ActivityListPalette(registry.get_bundle(bundle_id))
palette.connect('erase-activated', self.__erase_activated_cb)
return palette

def __erase_activated_cb(self, palette, bundle_id):
self.emit('erase-activated', bundle_id)


class ClearMessageBox(Gtk.EventBox):
def __init__(self, message, button_callback):
Expand Down
8 changes: 4 additions & 4 deletions src/jarabe/journal/expandedentry.py
Expand Up @@ -123,7 +123,7 @@ def _init_model(self):
self.set_model(self._store)
col = Gtk.TreeViewColumn()

who_icon = CellRendererCommentIcon(self)
who_icon = CellRendererCommentIcon()
col.pack_start(who_icon, False)
col.add_attribute(who_icon, 'file-name', self.COMMENT_ICON)
col.add_attribute(who_icon, 'xo-color', self.COMMENT_ICON_COLOR)
Expand All @@ -136,7 +136,7 @@ def _init_model(self):
col.pack_start(comment_text, True)
col.add_attribute(comment_text, 'text', self.COMMENT_MESSAGE)

erase_icon = CellRendererCommentIcon(self)
erase_icon = CellRendererCommentIcon()
erase_icon.connect('clicked', self._erase_comment_cb)
col.pack_start(erase_icon, False)
col.add_attribute(erase_icon, 'file-name', self.COMMENT_ERASE_ICON)
Expand Down Expand Up @@ -188,8 +188,8 @@ def _erase_alert_response_cb(self, alert, response_id, entry):


class CellRendererCommentIcon(CellRendererIcon):
def __init__(self, tree_view):
CellRendererIcon.__init__(self, tree_view)
def __init__(self):
CellRendererIcon.__init__(self)

self.props.width = style.SMALL_ICON_SIZE
self.props.height = style.SMALL_ICON_SIZE
Expand Down

0 comments on commit 379da72

Please sign in to comment.