GNOME Bugzilla – Bug 447969
Add a simpler API to create, parse and fetch objects
Last modified: 2015-03-07 23:44:51 UTC
As suggested by Havoc on gtk-devel: This makes sense to me, since pretty much every app would tend to have the builder_new()/add_from_file() sequence, so why not save some typing there. new_from_file() is also a common GTK convention. Adding multiple files seems like a relatively unusual thing to do. For the other stuff: - set_translation_domain - is for libraries mostly right? (if it's for apps it seems a gtk-wide or glib-wide way to do this could make sense, vs. gtkbuilder-specific) - connect_signals - for apps who will use this feature, they're going to type this line every time... new_from_file_and_connect()? kinda clunky. But it sucks to have a boilerplate line everyone has to type. - get_object - getting multiple objects seems like the normal case, so piling one object name it into the convenience function seems wrong A possible convenience API could be to have a global singleton builder or a hash of per-file builders and then something like: GtkWindow *window; GtkWindow *other_window; if (!gtk_builder_load_objects (DATADIR "/filename.glade", GTK_BUILDER_FLAGS_CONNECT_SIGNALS, "main-window", &window, "other-window", &other_window, NULL)) g_error("My files are missing!");
Created attachment 90584 [details] [review] patch This patch adds an initial implementation of the suggested API. It also converts the demo to use it and some of the tests in buildertest.
Comment on attachment 90584 [details] [review] patch <snip> >+ * "fnobricator", Should be frobnicator I believe.
Gossip has such helper functions internally and it's really useful!
This seems a really useful addition. Any change of getting the patch in SVN?
Ping. Johan is there something keeping you from committing this patch. It seems really useful to me
(In reply to comment #5) > Ping. Johan is there something keeping you from committing this patch. It seems > really useful to me Yes, a couple of things are missing, these are on top of my head: - refcounting needs to be figured, It's complicated since the factory function will return no references to a builder object, mainly documentation - what about the use case of connecting signals with arguments? perhaps split into load_objects() and load_objects_and_connect() - use it in the tests and write unittests specific for the load_objects() function.
Johan, In your current patch you try to do everything in gtk_builder_load_objects. In the current implementation I think most of the pain is in having to call gtk_builder_get_object for every single widget. Why not just implement a gtk_builder_get_objects function which calls gtk_builder_get_object over all the widgets you list in the arguments gtk_builder_get_objects. Most of the time the use of gtk_builder is something like this builder = gtk_builder_new (); gtk_builder_add_from_file (builder, "blah.ui, &err); gtk_builder_get_objects (builder, &err, "window1", &window, "button1", &button, NULL); connecting signals and setting translation domain people can do in the functions which they are used to use. I think this solves the first two issues you mention and gtk_builder_get_objects would be really easy to cover with unit tests because it's a pretty simple function. What do you think?
I think this has been superseded by template functionality, which is a more organized way to get objects out of ui files.