Hi! Today I felt like trying out writing a small GTK application, after close to 15 years of not touching anything related to user interfaces except maybe some occasional web stuff. I remember I used to design user interface in Glade and then load the UI in Python, which was mostly trouble-free. I googled a bit, and found some recommendations for gnome-builder, so I installed it through apt on my Debian Bookworm, and started playing, importing gitg from the wizard window—I use it, so thought it would be familiar. Yet the .ui files (I guess some equivalent to Glade?) do not open any UI designer, and the go to definition function doesn’t seem to work. So I guess I’m doing something wrong here.
How should I approach writing a small GTK application for personal use?
You should install GNOME Builder from Flathub in order to have the latest version, with all the needed dependencies and tooling.
There is no Glade any more; there is an experimental UI design tool made by the former Glade maintainer called Cambalache, also available on Flathub. In general, though, it’s not really necessary to use a UI design tool; you should use widget templates (also available in Python to create composite widgets.
I’ve fetched the flatpakref file, and trying to install it through LANG= flatpak install --user org.gnome.Builder.flatpakref, but I’m getting an error:
:~% LANG= flatpak install --user org.gnome.Builder.flatpakref
Note that the directories
'/var/lib/flatpak/exports/share'
'/home/liori/.local/share/flatpak/exports/share'
are not in the search path set by the XDG_DATA_DIRS environment variable, so
applications installed by Flatpak may not appear on your desktop until the
session is restarted.
The remote 'flathub', referred to by 'org.gnome.Builder' at location https://dl.flathub.org/repo/ contains additional applications.
Should the remote be kept for future installations? [Y/n]: n
The application org.gnome.Builder depends on runtimes from:
https://dl.flathub.org/repo/
Configure this as new remote 'flathub' [Y/n]: n
error: The application org.gnome.Builder/x86_64/stable requires the runtime org.gnome.Sdk/x86_64/45 which was not found
:~% LANG= flatpak install --user org.gnome.Builder.flatpakref
Note that the directories
'/var/lib/flatpak/exports/share'
'/home/liori/.local/share/flatpak/exports/share'
are not in the search path set by the XDG_DATA_DIRS environment variable, so
applications installed by Flatpak may not appear on your desktop until the
session is restarted.
The remote 'flathub', referred to by 'org.gnome.Builder' at location https://dl.flathub.org/repo/ contains additional applications.
Should the remote be kept for future installations? [Y/n]:
Required runtime for org.gnome.Builder/x86_64/stable (runtime/org.gnome.Sdk/x86_64/45) found in remote flathub
Do you want to install it? [Y/n]:
org.gnome.Builder permissions:
ipc network fallback-x11 session-bus ssh-auth system-bus wayland x11 dri devel file access [1] dbus access [2]
system dbus access [3]
[1] /var/lib/flatpak, host, xdg-data/meson, xdg-run/gvfsd, xdg-run/keyring, ~/.local/share/flatpak
[2] org.freedesktop.FileManager1, org.freedesktop.Flatpak, org.freedesktop.PackageKit, org.freedesktop.secrets, org.gtk.vfs.*
[3] org.freedesktop.Avahi, org.freedesktop.PolicyKit1, org.gnome.Sysprof3
ID Branch Op Remote Download
1. [?] org.freedesktop.Platform.GL.default 23.08 i flathub 8.1?kB / 162.2?MB
2. [?] org.freedesktop.Platform.GL.default 23.08-extra i flathub 8.2?kB / 162.2?MB
3. [?] org.freedesktop.Platform.openh264 2.2.0 i flathub 1.0?kB / 944.3?kB
4. [?] org.gnome.Builder.Locale stable i flathub 1.0?kB / 2.8?MB
5. [?] org.gnome.Sdk.Locale 45 i flathub 322.5?kB / 374.4?MB
6. [?] org.gnome.Sdk 45 i flathub 1.5?MB / 843.7?MB
7. [ ] org.gnome.Builder stable i flathub < 145.4?MB
Warning: While pulling runtime/org.freedesktop.Platform.GL.default/x86_64/23.08 from remote flathub: open(O_TMPFILE): Permission denied
Warning: While pulling runtime/org.freedesktop.Platform.GL.default/x86_64/23.08-extra from remote flathub: open(O_TMPFILE): Permission denied
Warning: While pulling runtime/org.freedesktop.Platform.openh264/x86_64/2.2.0 from remote flathub: open(O_TMPFILE): Permission denied
Warning: While pulling runtime/org.gnome.Builder.Locale/x86_64/stable from remote flathub: open(O_TMPFILE): Permission denied
Warning: While pulling runtime/org.gnome.Sdk.Locale/x86_64/45 from remote flathub: open(O_TMPFILE): Permission denied
Error: While pulling runtime/org.gnome.Sdk/x86_64/45 from remote flathub: open(O_TMPFILE): Permission denied
error: Failed to install org.gnome.Sdk: While pulling runtime/org.gnome.Sdk/x86_64/45 from remote flathub: open(O_TMPFILE): Permission denied
I’m starting to wonder if I’m in the target audience of gnome builder…
Hey Javos, have been in the same boat as you, getting great results with Vala so far.
I’d recommend looking at basic gui examples posted on various help forums (and Perplexity/Copilot) to see what you can get away with with regards to program structure, then the rest is just elaboration.
eg:
// one of several ways to structure a program I've seen
// some are in main, like this one, others are classes outside of it
int main (string[] args) {
Gtk.Application myapp = new Gtk.Application ("com.test.myapp", GLib.ApplicationFlags.FLAGS_NONE);
myapp.activate.connect(() => {
Gtk.ApplicationWindow win = new Gtk.ApplicationWindow(myapp);
Gtk.Box content = new Gtk.Box(VERTICAL,4)
// add stuff to content ...
// add signals ...
win.default_width = 360;
win.default_height = 720;
win.set_child(content);
win.present();
});
return myapp.run(args);
}
Also I suggest not using Builder or any other IDEs, just get used to raw code in one file, compile in the terminal with valac myapp.vala --pkg gtk4 and use the binary right-away. Its obviously not how the pros do it (you can always emulate later), but its a fast way to get small GUI programs made asap.