Merge branch 'treeview_perf2-try2' of https://github.com/godiard/sugar-toolkit-gtk3 into godiard-treeview_perf2-try2
commit
5818721818
@ -0,0 +1,71 @@
|
|||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
from sugar3.graphics import style
|
||||||
|
from sugar3.graphics.icon import CellRendererIcon
|
||||||
|
from sugar3.graphics.xocolor import XoColor
|
||||||
|
from sugar3.graphics.scrollingdetector import ScrollingDetector
|
||||||
|
from sugar3.graphics.palettewindow import TreeViewInvoker
|
||||||
|
import common
|
||||||
|
|
||||||
|
|
||||||
|
def _scroll_start_cb(event, treeview, invoker):
|
||||||
|
print "Scroll starts"
|
||||||
|
invoker.detach()
|
||||||
|
|
||||||
|
def _scroll_end_cb(event, treeview, invoker):
|
||||||
|
print "Scroll ends"
|
||||||
|
invoker.attach_treeview(treeview)
|
||||||
|
|
||||||
|
test = common.Test()
|
||||||
|
test.show()
|
||||||
|
|
||||||
|
model = Gtk.ListStore(str)
|
||||||
|
|
||||||
|
data_dir = os.getenv('GTK_DATA_PREFIX', '/usr/')
|
||||||
|
|
||||||
|
iconlist = os.listdir(os.path.join(data_dir,
|
||||||
|
'share/icons/sugar/scalable/actions/'))
|
||||||
|
print "Displaying %s icons" % len(iconlist)
|
||||||
|
for icon in iconlist:
|
||||||
|
icon = os.path.basename(icon)
|
||||||
|
icon = icon[:icon.find('.')]
|
||||||
|
model.append([icon])
|
||||||
|
|
||||||
|
scrolled = Gtk.ScrolledWindow()
|
||||||
|
scrolled.set_size_request(800, 800)
|
||||||
|
treeview = Gtk.TreeView()
|
||||||
|
|
||||||
|
treeview.set_model(model)
|
||||||
|
scrolled.add(treeview)
|
||||||
|
test.pack_start(scrolled, True, True, 0)
|
||||||
|
test.show_all()
|
||||||
|
|
||||||
|
col = Gtk.TreeViewColumn()
|
||||||
|
treeview.append_column(col)
|
||||||
|
|
||||||
|
xo_color = XoColor('#FF0000,#00FF00')
|
||||||
|
cell_icon = CellRendererIcon()
|
||||||
|
cell_icon.props.width = style.GRID_CELL_SIZE
|
||||||
|
cell_icon.props.height = style.GRID_CELL_SIZE
|
||||||
|
cell_icon.props.size = style.STANDARD_ICON_SIZE
|
||||||
|
cell_icon.props.xo_color = xo_color
|
||||||
|
|
||||||
|
col.pack_start(cell_icon, expand=False)
|
||||||
|
col.add_attribute(cell_icon, 'icon-name', 0)
|
||||||
|
cell_text = Gtk.CellRendererText()
|
||||||
|
col.pack_start(cell_text, expand=True)
|
||||||
|
col.add_attribute(cell_text, 'text', 0)
|
||||||
|
|
||||||
|
invoker = TreeViewInvoker()
|
||||||
|
invoker.attach_treeview(treeview)
|
||||||
|
|
||||||
|
detector = ScrollingDetector(scrolled)
|
||||||
|
detector.connect('scroll-start', _scroll_start_cb, treeview, invoker)
|
||||||
|
detector.connect('scroll-end', _scroll_end_cb, treeview, invoker)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
time_ini = time.time()
|
||||||
|
common.main(test)
|
@ -0,0 +1,61 @@
|
|||||||
|
# Copyright (C) 2014, Sugarlabs
|
||||||
|
#
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2 of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This library 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
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the
|
||||||
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
# Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
from gi.repository import GObject
|
||||||
|
from gi.repository import GLib
|
||||||
|
|
||||||
|
|
||||||
|
class ScrollingDetector(GObject.GObject):
|
||||||
|
"""
|
||||||
|
ScollingDetector emit signals when a ScrolledWindow starts and
|
||||||
|
finish scrolling. Other widets can use that information to
|
||||||
|
avoid do performance expensive operations.
|
||||||
|
"""
|
||||||
|
|
||||||
|
scroll_start_signal = GObject.Signal('scroll-start')
|
||||||
|
scroll_end_signal = GObject.Signal('scroll-end')
|
||||||
|
|
||||||
|
def __init__(self, scrolled_window, timeout=100):
|
||||||
|
self._scrolled_window = scrolled_window
|
||||||
|
self._timeout = timeout
|
||||||
|
self.is_scrolling = False
|
||||||
|
self._prev_value = 0
|
||||||
|
|
||||||
|
self.connect_scrolled_window()
|
||||||
|
GObject.GObject.__init__(self)
|
||||||
|
|
||||||
|
def connect_scrolled_window(self):
|
||||||
|
adj = self._scrolled_window.get_vadjustment()
|
||||||
|
adj.connect('value-changed', self._value_changed_cb)
|
||||||
|
|
||||||
|
def _check_scroll_cb(self, adj):
|
||||||
|
if (adj.props.value == self._prev_value):
|
||||||
|
self.is_scrolling = False
|
||||||
|
self.scroll_end_signal.emit()
|
||||||
|
return False
|
||||||
|
|
||||||
|
self._prev_value = adj.props.value
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _value_changed_cb(self, adj):
|
||||||
|
if (self.is_scrolling):
|
||||||
|
return
|
||||||
|
|
||||||
|
self.is_scrolling = True
|
||||||
|
self.scroll_start_signal.emit()
|
||||||
|
self._prev_value = adj.props.value
|
||||||
|
GLib.timeout_add(self._timeout, self._check_scroll_cb, adj)
|
Loading…
Reference in New Issue