I can add a custom widget to GTK, as shown here. Now I'd like to add properties to the custom widget and have them show up in glade. Is this possible?
I have added properties to the custom widget as shown here but the properties do not show up in glade.
Update
It appears that the glade catalogue supports a <parameter-spec>
element that can be used to define properties to be exposed within glade as shown below.
<glade-widget-class title="Awesome TextView" name="AwesomeTextView" generic-name="awesome_text_view">
<properties>
<property id="num_fidgets" name="Number of fidgets" default="4" save="False" custom-layout="True">
<parameter-spec>
<type>GParamInt</type>
<min>4</min>
</parameter-spec>
<tooltip>The number of fidgets</tooltip>
</property>
</properties>
</glade-widget-class>
I have defined one such property but it does not show in glade. Rather I get the error message:
GLib-GObject-CRITICAL **: 16:07:45.433: g_object_set_is_valid_property: object class 'AwesomeTextView' has no property named 'num-fidgets'
Where the custom widget AwesomeTextView
is essentially defined as:
class AwesomeTextView (Gtk.TextView):
__gtype_name__ = 'AwesomeTextView'
num_fidgets = GObject.Property(type=int, default='4', nick='num_Fidgets')
The <parameter-spec>
s appear to be undocumented. Thankfully though there are examples of the the supported <type>
s in the glade repo.
Correction: <parameter-spec>
s are documented. This documentation can be supplemented with examples of the supported <type>
s in the glade repo.
Update2
Found the cause of the error. The default argument has the wrong type -- str
instead of int
. The property should be:
num_fidgets = GObject.Property(type=int, default=4, nick='num_Fidgets')
Glade no longer emits an error. But the property does not show up in the UI.