Changes

Jump to navigation Jump to search
1,123 bytes added ,  17:47, 9 November 2011
Line 90: Line 90:     
If you are having trouble finding how a particular GTK class/method/constant has been named in PyGI, run [http://dev.laptop.org/~dsd/20110806/pygi-enumerate.py pygi-enumerate.py] and grep the output. (this app lists all identified methods and constants).
 
If you are having trouble finding how a particular GTK class/method/constant has been named in PyGI, run [http://dev.laptop.org/~dsd/20110806/pygi-enumerate.py pygi-enumerate.py] and grep the output. (this app lists all identified methods and constants).
 +
 +
 +
=== Constructor considerations ===
 +
 +
With PyGI it is possible to use Python-like constructors, or "new" functions e.g. the following are (probably) equivalent:
 +
label = Gtk.Label()
 +
label = Gtk.Label.new()
 +
 +
However, the first form is preferred: it is more Python-like. Internally, the difference is that Gtk.Label.new() translates to a call to gtk_label_new(), whereas Gtk.Label() (the preferred form) will directly construct an instance of GtkLabel at the GObject level.
 +
 +
If the constructor takes parameters, they '''must''' be named. The parameters correspond to GObject properties marked as "Construct" in the API documentation. For example, the following code will not work:
 +
 +
expander = Gtk.Expander("my expander")
 +
 +
The (confusing) error is:
 +
TypeError: GObject.__init__() takes exactly 0 arguments (1 given)
 +
 +
The solution is to go to the [http://developer.gnome.org/gtk3/3.2/GtkExpander.html#GtkExpander.properties GtkExpander API documentation] and find the appropriate "Construct" property that we wish to set. In this case it is <b>label</b>, so the code should be:
 +
 +
expander = Gtk.Expander(label="my expander")
    
==Make a release==
 
==Make a release==
105

edits

Navigation menu