[pygobject] Add override for Gtk.TreeView.insert_column_with_attributes()
- From: Martin Pitt <martinpitt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Add override for Gtk.TreeView.insert_column_with_attributes()
- Date: Mon, 3 Sep 2012 11:08:14 +0000 (UTC)
commit 542cf22c9de9b2094868c4e879b0f24b15c4c012
Author: Marta Maria Casetti <mmcasetti gmail com>
Date: Mon Sep 3 13:06:22 2012 +0200
Add override for Gtk.TreeView.insert_column_with_attributes()
https://bugzilla.gnome.org/show_bug.cgi?id=679415
Co-Authored-By: Martin Pitt <martinpitt gnome org>
gi/overrides/Gtk.py | 7 +++++++
tests/test_overrides_gtk.py | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 231291d..5eab41b 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -1384,6 +1384,13 @@ class TreeView(Gtk.TreeView, Container):
path = TreePath(path)
return super(TreeView, self).get_cell_area(path, column)
+ def insert_column_with_attributes(self, position, title, cell, **kwargs):
+ column = TreeViewColumn()
+ column.set_title(title)
+ column.pack_start(cell, False)
+ self.insert_column(column, position)
+ column.set_attributes(cell, **kwargs)
+
TreeView = override(TreeView)
__all__.append('TreeView')
diff --git a/tests/test_overrides_gtk.py b/tests/test_overrides_gtk.py
index ed39e26..0527434 100644
--- a/tests/test_overrides_gtk.py
+++ b/tests/test_overrides_gtk.py
@@ -1339,6 +1339,44 @@ class TestTreeView(unittest.TestCase):
text=0,
style=2)
+ def test_tree_view_add_column_with_attributes(self):
+ model = Gtk.ListStore(str, str, str)
+ # deliberately use out-of-order sorting here; we assign column 0 to
+ # model index 2, etc.
+ model.append(['cell13', 'cell11', 'cell12'])
+ model.append(['cell23', 'cell21', 'cell22'])
+
+ tree = Gtk.TreeView(model)
+ cell1 = Gtk.CellRendererText()
+ cell2 = Gtk.CellRendererText()
+ cell3 = Gtk.CellRendererText()
+ cell4 = Gtk.CellRendererText()
+
+ tree.insert_column_with_attributes(0, 'Head2', cell2, text=2)
+ tree.insert_column_with_attributes(0, 'Head1', cell1, text=1)
+ tree.insert_column_with_attributes(-1, 'Head3', cell3, text=0)
+ # unconnected
+ tree.insert_column_with_attributes(-1, 'Head4', cell3)
+
+ self.assertEqual(tree.get_column(0).get_title(), 'Head1')
+ self.assertEqual(tree.get_column(1).get_title(), 'Head2')
+ self.assertEqual(tree.get_column(2).get_title(), 'Head3')
+ self.assertEqual(tree.get_column(3).get_title(), 'Head4')
+
+ # might cause a Pango warning, do not break on this
+ old_mask = GLib.log_set_always_fatal(
+ GLib.LogLevelFlags.LEVEL_CRITICAL | GLib.LogLevelFlags.LEVEL_ERROR)
+ # This will make cell.props.text receive a value, otherwise it
+ # will be None.
+ tree.get_preferred_size()
+ GLib.log_set_always_fatal(old_mask)
+
+ # cursor should be at the first row
+ self.assertEqual(cell1.props.text, 'cell11')
+ self.assertEqual(cell2.props.text, 'cell12')
+ self.assertEqual(cell3.props.text, 'cell13')
+ self.assertEqual(cell4.props.text, None)
+
def test_tree_view_column_set_attributes(self):
store = Gtk.ListStore(int, str)
directors = ['Fellini', 'Tarantino', 'Tarkovskiy']
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]