GNOME Bugzilla – Bug 620405
add ListStore, TreeStore and TreeViewColumn APIs
Last modified: 2010-06-23 21:21:22 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
Created attachment 162572 [details] [review] add ListStore, TreeStore and TreeViewColumn APIs
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.
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
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
Added unit tests and cleaned up as per Johan's review
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.
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
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
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
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 =
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
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 on attachment 164437 [details] [review] add ListStore, TreeStore and TreeViewColumn APIs Fixed up with Johan's comments