Loading Glade file in Gnome Builder

1.2k Views Asked by At

Simply putting the ui file together with the main py file and telling gtk.builder to load it using self.builder.add_from_file('ui.glade') obviously isn't cutting it.

It's telling me GLib.Error: g-file-error-quark: Failed to open file 'ui.glade': No such file or directory (4)

I'm assuming this is due to Builder running the project from another temporary directory, hence why it's unable to find the glade file.

My question is, how can I tell Builder to load the glade file together with the rest of the project? Or do I have to put the glade file somewhere "permanent" and then hard-code the path to it?

1

There are 1 best solutions below

0
On

You should never use relative paths to files, so you need to figure out an absolute path at runtime usually by defining an install prefix at build time. Also ideally you use GResources to simplify the process and improve performance.

An example would be something like this:

See also: https://developer.gnome.org/gio/stable/GResource.html

You can get more help if you stop by #newcomers on ircs://irc.gimp.net or https://riot.im/app/#/room/#gimpnet#newcomers:matrix.org