Support iteration and indexing on structs
Submitted by Simon Feltman
Link to original bug (#696027)
Description
The idea is to add generic support for __iter__
to the Boxed and Struct types. This will allow better compatibility with PyGTK as well as being a general convenience for Python programming. PyGTK generally did not expose structs and instead used tuples for data and this will also help compatibility through a generic technique.
There are a handful of functions which either replicate this behaviour for certain structs in overrides when returned, would benefit from the proposal, or the behaviour has been removed in PyGI and would help compatibility with PyGTK:
- Gdk.Color
- Gdk.RGBA
- Gtk.TargetEntry
- Gtk.Border
- GObject.SignalQuery
- Clutter.Point
- Clutter.Size
- Clutter.Vertex
- Clutter.Geometry
- Clutter.Knot
- Clutter.ActorBox
- Gdk.Rectangle
- Pango.Rectangle
A second part of this proposal would be to allow coercion from tuples and dicts to Structs when marshaling from Python (similar to bug 686261). The benefit of this (and the above) is not only in removal of overrides which provide a similar thing, but more importantly it will guarantee API consistency throughout all methods which accept a particular struct instance as well as a tuple (Widget.drag_dest_set_target_list and related methods for example)