Changes

Jump to navigation Jump to search
Line 100: Line 100:  
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.
 
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:
+
If the constructor takes parameters, they '''must''' be named. The parameters correspond to GObject properties in the API documentation which are usually marked as "Construct". For example, the following code will not work:
    
  expander = Gtk.Expander("my expander")
 
  expander = Gtk.Expander("my expander")
Line 107: Line 107:  
  TypeError: GObject.__init__() takes exactly 0 arguments (1 given)
 
  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:
+
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 property that we wish to set. In this case it is <b>label</b> (which is a Construct property, further increasing our confidence of success), so the code should be:
    
  expander = Gtk.Expander(label="my expander")
 
  expander = Gtk.Expander(label="my expander")
   −
Combining the two points above, if you wish to call a construct-like function such as gtk_button_new_with_label(), you do have the option of calling Gtk.Button.new_with_label(), however if we check the [http://developer.gnome.org/gtk3/3.2/GtkButton.html#GtkButton.properties GtkButton Construct parameters] we see one called "label" which is equivalent. Therefore gtk_button_new_with_label("foo") should be called as:
+
Combining the two points above, if you wish to call a construct-like function such as gtk_button_new_with_label(), you do have the option of calling Gtk.Button.new_with_label(), however if we check the [http://developer.gnome.org/gtk3/3.2/GtkButton.html#GtkButton.properties GtkButton properties] we see one called "label" which is equivalent. Therefore gtk_button_new_with_label("foo") should be called as:
 
  button = Gtk.Button(label="foo")
 
  button = Gtk.Button(label="foo")
  
105

edits

Navigation menu