After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 620405 - add ListStore, TreeStore and TreeViewColumn APIs
add ListStore, TreeStore and TreeViewColumn APIs
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2010-06-02 20:58 UTC by johnp
Modified: 2010-06-23 21:21 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
add ListStore, TreeStore and TreeViewColumn APIs (3.75 KB, patch)
2010-06-02 20:58 UTC, johnp
needs-work Details | Review
add ListStore, TreeStore and TreeViewColumn APIs (6.63 KB, patch)
2010-06-03 18:51 UTC, johnp
needs-work Details | Review
add ListStore, TreeStore and TreeViewColumn APIs (6.84 KB, patch)
2010-06-21 16:11 UTC, johnp
none Details | Review
add ListStore, TreeStore and TreeViewColumn APIs (6.90 KB, patch)
2010-06-22 16:13 UTC, johnp
none Details | Review
add ListStore, TreeStore and TreeViewColumn APIs and expose pyg_type_from_object (7.22 KB, patch)
2010-06-23 20:32 UTC, johnp
needs-work Details | Review
add ListStore, TreeStore and TreeViewColumn APIs (6.35 KB, patch)
2010-06-23 21:06 UTC, johnp
none Details | Review
add ListStore, TreeStore and TreeViewColumn APIs (6.30 KB, patch)
2010-06-23 21:19 UTC, johnp
committed Details | Review

Description johnp 2010-06-02 20:58:17 UTC
* this is enough to support the gtk-demo.py shell
* TreeStore and ListStore allow passing in as an argument list
  of either python or GLib types to the constructor as a description
  of the columns in the model
* TreeStore and ListStore override the append method, allowing
  the application developer to send in a list of column values
  for one row in the model.  Unlike the append in C which
  just returns an iter that you can then add data to,
  this append actualy appends data in one step
* TreeViewColumn overrides the constructor to allow the adding
  of attributes and a cell renderer when constructing the
  column
Comment 1 johnp 2010-06-02 20:58:19 UTC
Created attachment 162572 [details] [review]
add ListStore, TreeStore and TreeViewColumn APIs
Comment 2 johnp 2010-06-02 21:01:28 UTC
Woops, git-bz has a different format than git-format-patch.  where HEAD == HEAD^ for some reason. Anyway, I don't have tests for this yet.
Comment 3 Johan (not receiving bugmail) Dahlin 2010-06-02 21:53:37 UTC
Review of attachment 162572 [details] [review]:

::: gi/overrides/Gtk.py
@@ +306,3 @@
+        return obj.__gtype__
+
+    raise TypeError('could not get typecode from object "%r"' % obj)

% (obj, )) or it will fail if someone passes in a list or tuple of something

@@ +309,3 @@
+
+class ListStore(Gtk.ListStore):
+    def __init__(self, *args, **kwds):

**kwargs seems unneeded
*args -> *column_types

@@ +323,3 @@
+        n_columns = self.get_n_columns();
+        if len(row) != n_columns:
+            raise ValueError('row sequence has the incorrect number of elements')

This matches PyGTK's behavior right?

@@ +325,3 @@
+            raise ValueError('row sequence has the incorrect number of elements')
+
+        for i in range(n_columns):

xrange?

@@ +336,3 @@
+
+    def __init__(self, *args, **kwds):
+        Gtk.TreeStore.__init__(self, **kwds)

See above

@@ +359,3 @@
+
+class TreeViewColumn(Gtk.TreeViewColumn):
+    def __init__(self, title = '',

no spaces around =

@@ +361,3 @@
+    def __init__(self, title = '',
+                 cell_renderer = None,
+                 **kwds):

kwds -> attributes

@@ +362,3 @@
+                 cell_renderer = None,
+                 **kwds):
+        Gtk.TreeViewColumn.__init__(self, title = title)

title=title
Comment 4 johnp 2010-06-03 18:51:23 UTC
Created attachment 162682 [details] [review]
add ListStore, TreeStore and TreeViewColumn APIs

* this is enough to support the gtk-demo.py shell
* TreeStore and ListStore allow passing in as an argument list
  of either python or GLib types to the constructor as a description
  of the columns in the model
* TreeStore and ListStore override the append method, allowing
  the application developer to send in a list of column values
  for one row in the model.  Unlike the append in C which
  just returns an iter that you can then add data to,
  this append actualy appends data in one step
* TreeViewColumn overrides the constructor to allow the adding
  of attributes and a cell renderer when constructing the
  column
Comment 5 johnp 2010-06-03 18:52:42 UTC
Added unit tests and cleaned up as per Johan's review
Comment 6 Tomeu Vizoso 2010-06-15 10:05:27 UTC
Review of attachment 162682 [details] [review]:

Great work!

::: gi/overrides/Gtk.py
@@ +306,3 @@
+        return obj.__gtype__
+
+    raise TypeError('could not get typecode from object "%r"' % (obj,))

Should be rather "could not get GType for object..."?

In any case, this functionality is already in PyGObject: pyg_type_from_object

Would be better to wrap it so it can be called from Python than to duplicate it.

@@ +312,3 @@
+        Gtk.ListStore.__init__(self)
+        col_gtypes = []
+        for col_type in column_types:

I would try to void these abbreviations in variable names.
Comment 7 johnp 2010-06-21 16:11:35 UTC
Created attachment 164229 [details] [review]
add ListStore, TreeStore and TreeViewColumn APIs

* this is enough to support the gtk-demo.py shell
* TreeStore and ListStore allow passing in as an argument list
  of either python or GLib types to the constructor as a description
  of the columns in the model
* TreeStore and ListStore override the append method, allowing
  the application developer to send in a list of column values
  for one row in the model.  Unlike the append in C which
  just returns an iter that you can then add data to,
  this append actualy appends data in one step
* TreeViewColumn overrides the constructor to allow the adding
  of attributes and a cell renderer when constructing the
  column
Comment 8 johnp 2010-06-22 16:13:33 UTC
Created attachment 164319 [details] [review]
add ListStore, TreeStore and TreeViewColumn APIs

* this is enough to support the gtk-demo.py shell
* TreeStore and ListStore allow passing in as an argument list
  of either python or GLib types to the constructor as a description
  of the columns in the model
* TreeStore and ListStore override the append method, allowing
  the application developer to send in a list of column values
  for one row in the model.  Unlike the append in C which
  just returns an iter that you can then add data to,
  this append actualy appends data in one step
* TreeViewColumn overrides the constructor to allow the adding
  of attributes and a cell renderer when constructing the
  column
Comment 9 johnp 2010-06-23 20:32:44 UTC
Created attachment 164433 [details] [review]
add ListStore, TreeStore and TreeViewColumn APIs and expose pyg_type_from_object

* this is enough to support the gtk-demo.py shell
* TreeStore and ListStore allow passing in as an argument list
  of either python or GLib types to the constructor as a description
  of the columns in the model
* TreeStore and ListStore override the append method, allowing
  the application developer to send in a list of column values
  for one row in the model.  Unlike the append in C which
  just returns an iter that you can then add data to,
  this append actualy appends data in one step
* TreeViewColumn overrides the constructor to allow the adding
  of attributes and a cell renderer when constructing the
  column
* pyg_type_from_object is exposed as gobject.GType.from_object and used by the
  overrides
Comment 10 Johan (not receiving bugmail) Dahlin 2010-06-23 20:56:37 UTC
Review of attachment 164433 [details] [review]:

::: gi/overrides/Gtk.py
@@ +346,3 @@
+        col_gtypes = []
+        for col_type in column_types:
+            col_gtypes.append(GObject.GType.from_object(col_type))

You should be able to pass in *column_types directly

@@ +351,3 @@
+
+    def append(self, row):
+        iter = Gtk.TreeIter()

do not use the variable name "iter", as it's a builtin python type.
titer/treeiter/tree_iter are fine named though. Fix this in this file and in the tests

::: gobject/pygtype.c
@@ +275,2 @@
 static PyObject*
+_wrap_g_type_from_object(PyGTypeWrapper *_, PyObject *args)

This shouldn't be needed

::: tests/test_overrides.py
@@ +209,3 @@
+        # check to see that we can instantiate a TreeViewColumn
+        cell = Gtk.CellRendererText()
+        column = Gtk.TreeViewColumn(title = 'This is just a test',

Kill spaces around =
Comment 11 johnp 2010-06-23 21:06:38 UTC
Created attachment 164435 [details] [review]
add ListStore, TreeStore and TreeViewColumn APIs

* this is enough to support the gtk-demo.py shell
* TreeStore and ListStore allow passing in as an argument list
  of either python or GLib types to the constructor as a description
  of the columns in the model
* TreeStore and ListStore override the append method, allowing
  the application developer to send in a list of column values
  for one row in the model.  Unlike the append in C which
  just returns an iter that you can then add data to,
  this append actualy appends data in one step
* TreeViewColumn overrides the constructor to allow the adding
  of attributes and a cell renderer when constructing the
  column
Comment 12 johnp 2010-06-23 21:19:05 UTC
Created attachment 164437 [details] [review]
add ListStore, TreeStore and TreeViewColumn APIs

* this is enough to support the gtk-demo.py shell
* TreeStore and ListStore allow passing in as an argument list
  of either python or GLib types to the constructor as a description
  of the columns in the model
* TreeStore and ListStore override the append method, allowing
  the application developer to send in a list of column values
  for one row in the model.  Unlike the append in C which
  just returns an iter that you can then add data to,
  this append actualy appends data in one step
* TreeViewColumn overrides the constructor to allow the adding
  of attributes and a cell renderer when constructing the
  column
Comment 13 johnp 2010-06-23 21:21:12 UTC
Comment on attachment 164437 [details] [review]
add ListStore, TreeStore and TreeViewColumn APIs

Fixed up with Johan's comments