`get-type-function` in catalog not propagated to `type-func` in UI definition
I've created a custom widget called GtkPanZoomArea
and it's get-type
function is gtk_panzoom_area_get_type()
. The widget is declared with:
G_DECLARE_DERIVABLE_TYPE(GtkPanZoomArea, gtk_panzoom_area, GTK, PANZOOM_AREA,
GtkDrawingArea);
As far as I can tell it looks like glade's heuristic for finding the get_type
function is to convert upper-camel to snake-case and then append _get_type()
. In my custom catalog that didn't work (failed to load) so I added a get-type-function
tag like this:
<glade-widget-class
name="GtkPanZoomArea" generic-name="panzoom" title="Pan Zoom Area"
get-type-function="gtk_panzoom_area_get_type"/>
And now my widget shows up correctly in glade (hurray!). However when I try to load a UI definition created with glade, using my custom widget, I get the following:
(gtk_panzoom_demo:24936): Gtk-ERROR **: 21:53:25.113: failed to add UI: tangent/gtkutil/panzoom.glade:46:1 Invalid object type 'GtkPanZoomArea'
Trace/breakpoint trap
I guess that gtk_builder
must use the same heuristic (though, it doesn't look like glade actually uses the gtk_builder function). The generated UI definition looks like this:
<object class="GtkPanZoomArea" id="panzoom">
<property name="name">panzoom</property>
<property name="width_request">500</property>
<property name="height_request">500</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="offset_x_adjustment">offset_x_adjustment</property>
<property name="offset_y_adjustment">offset_y_adjustment</property>
<property name="scale_adjustment">scale_adjustment</property>
<property name="scale_rate_adjustment">scale_rate_adjustment</property>
<property name="demo_draw_enabled">True</property>
</object>
I can manually edit the UI definition and add type-func="gtk_panzoom_area_get_type"
to the <object>
tag and the my using-program will work.
This seems odd to me. Since I had to tell glade the name of the get-type function, presumably I have done so because the heuristics aren't going to work to find it. And since GtkBuilder
presumably uses the same heuristics, it also wont be able to find it. So, we'll need to tell GtkBuilder
the name as well. My expectation is that glade would populate type-func
attribute in the UI definition if I have provided a get-type-function
.
This is not a huge problem for me. Evidently I can set name="GtkPanzoomArea"
in my glade catalog and then everything will work fine... but it does seem like a bit of an oversight. Feel free to correct me if I am wrong.
Also, maybe the UpperCamel -> lower_snake
is so common that I am an idiot for not following that convention. Or maybe everyone who writes custom widgets just provides an plugin-init function to enumerate the type ids for all their widgets. I'm not sure what the usual practice is here so maybe my expectation is off.
Edit 1: I forgot to add the following:
- Glade version 3.22.1
- Gtk version 3.22.30-1ubuntu3
Edit 2: After further experimentation, it seems that using name="GtkPanzoomArea"
only works if the widget is loaded via a shared object. If the library with the widget is linked statically, then GtkBuilder
fails out with:
failed to add UI: panzoom.ui:46:1 Invalid object type 'GtkPanzoomArea'