[pygtk] Re: list like behaviour for GtkListStore
Jonathan Blandford wrote: >James Henstridge <[EMAIL PROTECTED]> writes: > > > >>I added a quick modification to the GtkListStore wrapper so the >>following is now possible: >> >> >>> import gtk >> >>> store = gtk.ListStore(int, int, str, str) >> >> > >nice. Can I do 'object' too? > Yes. 'object' gets interpreted as 'arbitrary python object'. >>I plan to add some more features: >> >>* support for this to GtkTreeStore (so you could do >> treestore[0,3][0] = 42) >> This bit is working now :) >>* support for row deletion >>* support for assignments (eg. store[0] = (1,2,'foo','bar')) >>* an __iter__ slot for GtkListStore (which would return a sequence >> ofthese row objects). >>* maybe add __iter__ for tree stores too (iterates over the toplevel >> nodes, and iter(row) would iterate over the child nodes). >> >> > >so it would be: >for row in tree: >for row2 in row: >... > >I kinda would have expected that to iterate over values. This may be >more convenient, though. > Either that, or do: for row2 in row.iterchildren(): ... This would be similar to dictionaries where there is more than one thing that you may want to iterate over: * iter(d) iterates over keys * d.iterkeys() iterates over keys * d.itervalues() iterates over values * d.iteritems() iterates over (key, value) pairs So having an iterchildren() method for row objects would fit this pattern pretty well. James. -- Email: [EMAIL PROTECTED] | Linux.conf.au 2003 Call for Papers out WWW: http://www.daa.com.au/~james/ | http://conf.linux.org.au/cfp.html ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] Re: list like behaviour for GtkListStore
James Henstridge <[EMAIL PROTECTED]> writes: > I added a quick modification to the GtkListStore wrapper so the > following is now possible: > > >>> import gtk > >>> store = gtk.ListStore(int, int, str, str) nice. Can I do 'object' too? > >>> store.append() > > >>> len(store) > 1 > >>> store[0] > > >>> store[0][0] > 0 > >>> store[0][0] = 42 > >>> store[0][2] = 'foo' > >>> store[0][0], store[0][2] > 42, 'foo' Looks really nice. > I plan to add some more features: > > * support for this to GtkTreeStore (so you could do > treestore[0,3][0] = 42) > * support for row deletion > * support for assignments (eg. store[0] = (1,2,'foo','bar')) > * an __iter__ slot for GtkListStore (which would return a sequence > ofthese row objects). > * maybe add __iter__ for tree stores too (iterates over the toplevel > nodes, and iter(row) would iterate over the child nodes). so it would be: for row in tree: for row2 in row: ... I kinda would have expected that to iterate over values. This may be more convenient, though. Thanks, -Jonathan ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/