[Sugar-devel] Treeview-Treemodel coupling, and persistence (in journal)

Ajay Garg ajay at activitycentral.com
Fri Feb 10 00:33:42 EST 2012


Hi all.

I have been trying to integrate the batch-operations (copy, erase) ([1]).
There is already a working patch landed at [2]

However, there is a major performance bottleneck; for every toggling
of the checkbox by the user, the metadata (corresponding to the
checkbox listview) is wriiten on-disk, and a refresh done.
As the number of entries become large, the performance degrades exponentially.

Codewise, the bottleneck is in the section at [2] (I am pasting a fair
section of code, for easy location)

"""
 # Copyright (C) 2009, Tomeu Vizoso
+# Copyright (C) 2012, Walter Bender  <walter at sugarlabs.org>
+# Copyright (C) 2012, Gonzalo Odiard <gonzalo at laptop.org>
+# Copyright (C) 2012, Martin Abente  <tch at sugarlabs.org>
+# Copyright (C) 2012, Ajay Garg      <ajay at activitycentral.com>
 #
 # 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
@@ -98,6 +102,8 @@  class BaseListView(gtk.Bin):
         self._title_column = None
         self.sort_column = None
         self._add_columns()
+        self._inhibit_refresh = False
+        self._selected_entries = 0

         self.tree_view.enable_model_drag_source(gtk.gdk.BUTTON1_MASK,
                                                 [('text/uri-list', 0, 0),
@@ -134,6 +140,18 @@  class BaseListView(gtk.Bin):
             return object_id.startswith(self._query['mountpoints'][0])

     def _add_columns(self):
+        cell_select = gtk.CellRendererToggle()
+        cell_select.props.indicator_size = style.zoom(26)
+        cell_select.props.activatable = True
+        cell_select.connect('toggled', self.__selected_cb)
+
+        column = gtk.TreeViewColumn()
+        column.props.sizing = gtk.TREE_VIEW_COLUMN_FIXED
+        column.props.fixed_width = style.GRID_CELL_SIZE
+        column.pack_start(cell_select)
+        column.add_attribute(cell_select, "active", ListModel.COLUMN_SELECT)
+        self.tree_view.append_column(column)
+
         cell_favorite = CellRendererFavorite(self.tree_view)
         cell_favorite.connect('clicked', self.__favorite_clicked_cb)

@@ -251,6 +269,30 @@  class BaseListView(gtk.Bin):
         else:
             cell.props.xo_color = None

+    def __selected_cb(self, cell, path):
+        row = self._model[path]
+        metadata = model.get(row[ListModel.COLUMN_UID])
+        if metadata.get('selected', '0') == '1':
+            metadata['selected'] = '0'
+            self._process_new_selected_status('0')
+        else:
+            metadata['selected'] = '1'
+            self._process_new_selected_status('1')
+
+        model.write(metadata, update_mtime=False)
+
+    def _process_new_selected_status(self, new_status):
+        from jarabe.journal.journalactivity import get_journal
+        journal = get_journal()
+
+        if new_status == '0':
+            self._selected_entries = self._selected_entries - 1
+            if self._selected_entries == 0:
+                journal.switch_to_editing_mode(False)
+        else:
+            self._selected_entries = self._selected_entries + 1
+            journal.switch_to_editing_mode(True)

"""

As can be seen at " def __selected_cb(self, cell, path)", whenever the
checkbox is toggled, the metadata field ("selected") is toggled, the
metadata wriiten on-disk, and _only then the toggling visible on the
UI_. This works fine when the number of entries is small, but
performance degrades considerably as the number of entries becomes
large.

I have already tried doing

"""
row = self._model[path]
ListModel.COLUMN_SELECT] = '1' (or "0")
"""

but what I get is the exception :

_TypeError: can not set cells in this tree model"_




So, I really need help; in particular, I would be grateful if I just
know that is it possible at all to effect the toggling _only in
memory, while at the same time displaying the toggling-effect on the
UI_.

Looking forward to a reply.


Regards,
Ajay


[1] http://wiki.sugarlabs.org/go/Features/Multi_selection
[2] http://patchwork.sugarlabs.org/patch/1172/


More information about the Sugar-devel mailing list