GTK development notes
Short Circuit development
You can find the code over at gitlab Short Circuit repo!
So one of my friends and I teamed up to do an developer tool to improve our workflows. Heavily inspired by Boop on
mac. Since unfortunately it is not on linux and nothing like that exists on linux, we thought
we will learn GTK dev and do it for ourselves and in turn for the community. This is the first time my friend got
introduced to the GTK dev space. Although I have some experience, I do not have enough knowledge to give him any kind of
- Got some skeleton up and running, one thing I noticed is that there is no go to article which tells how to set up a
proper GTK application. We are using [python] and the source of knowledge for us was other [python] projects. Specifically
Notorious by GabMus. This is something [todo], write an article about
basic project setup and a collection of links to the documentation for GTK and how to traverse this world.
- The more I work on this, I personally feel [python] GTK libs need to have proper auto complete and type support for gtk
libraries. I think they are very well designed, but for a beginner like me who has no knowledge of what a method’s
arguments are, or which arguments exist for a class. I am blind while developing. Like a lot of people, I use
PyCharm for development. PyCharm did suggest to install stubs for PyObject,
which I did. But there was little to no improvement in terms of IntelliSense. It looks like there is an active
discussion going on to add types, this will be a huge boon if
it lands! (Although this was opened two years ago 😢)
- Added Flatpak support to the application today, which involves setting up meson build system. But fortunately gnome
builder has gives a ready made template which sets up Flatpak and meson for you. So, I took all the code and sort of
migrated it into the gnome builder [python] template. Although it did work, it was not an easy task. I think there
should be one tutorial which takes you through zero to a meson and flatpak supported GTK app, explaining what each
file does and how it is important. This is also something I have [todo].
- Gnome builder is a fantastic tool, but it lacks strong [python] autocomplete. I am not sure if there is something wrong
with my setup, but there is no linting or error detection. Which means if I make a simple stupid mistake (like missing
a bracket) the editor does not show something is wrong. This is also a pain because we hit play and wait for a while
only to realize there is a missing bracket. I also need to research how to debug [python] applications using gnome
builder. This is a must for me since I want to strongly type my code and a debugger will help me do it much faster.
Pycharm does it really well, I hope we get something similar for gnome builder.
- There are two (untold?) patterns which I find are strongly used (at least in the [python] GTK dev world). One is the
idea that all the widgets are usually singleton. And from everywhere you get the singleton and mutate the widget based
on class methods. One more principle is that, the complete GTK application should be a [python] package. Install the
application as a [python] package and make a bin file which just calls the main file of this package.
- Once the package idea clicks, it is very easy to run the app just using pycharm. Set your package folder as
root. It essentially adds the folder in
PYTHONPATH which makes it to be considered as a [python] package. Create a
dev [python] file which calls the main method of your package and you will have all the conveniences of PyCharm debugger
- There should be an FAQ which shares recipes for problems like this in different GTK libraries. Since these are not
language specific but GNOME specific.
- Should we have a App Showcase? I think this makes sense. A new comer would love to see what applications are written
in [python] and dive into the source code if stuck. Interesting idea though.
- There is a gnome design channel, I tried submitting my icon but did not receive much feedback (maybe mine was a bad
time to post). But the idea of having a gnome design is fantastic. I would like to also submit my UI for a design
review and take feedback. I will post it when I see the group has got active (right now it seems silent).
- Setting up the complete build system, resource files, schema files etc is a pain, It is very hard to debug issues
I feel. I have spent almost two nights to figure out why the icon of the app is not showing up. It would be
absolutely awesome if there is a cookiecutter template which has a
dummy icon setup, all the build system configured and flatpak working out of the box. That would mean developers can
just start working on their apps instead of setting up build systems.
- There were some more problems I faced which took longer than I expected/did now work out
- I was not able to get GTK info-bar working in python. I think it would be awesome if a demo app existed with GTK
[python] sample code. Currently the GTK demo only shows up C code. I should formally put this suggestion forward and
see what people have to say.
- Although meson is fantastic, some guidance/explanation would help beginners greatly. This is in my [todo], I will
write about this in the series I plan on publishing.
- There should also be a series/tutorial which explains how to package a GTK app, what GResource means, what a desktop
file is/what it should contain etc.. ([todo])
- The icon is blurry, not sure why. I asked for help and am waiting for a reply. Still WIP. If this is a common
- After a while, The Authenticator dev (Bilal) helped me out on the icon issue. Apparently it only happens in dev. Once
the flatpak is installed. The icon shows up normally. But during development, it does not show up. A very weird
behavior in my opinion. He asked me to raise the issue over at gnome discourse. I will do that sometime soon.
- It is on flathub now!
GNOME developer handbook
You can read the book here!
There are two things which I think GNOME needs to do work on relating to smoothing the [python] GTK app dev cycle asap.
- Documentation which does more “Hand Holding”
- Proper autocomplete support for [python] GTK libraries
I am trying to solve the first problem here. I want to make a tutorial so straight forward that someone who just knows
[python] and has no idea how GTK / Linux Application Development and get them to a position where they are able to develop
small GTK applications. We build one GTK application which set’s the wallpaper of desktop randomly from
unsplash. Although it looks simple, there is scope to cover a bunch of basic concepts which are crucial
for GTK application development.
One thing I sorely miss when I moved from mac OS is a solid PostgreSQL native GUI. I used table
plus and Postico. Both of them are fantastically solid and
native mac OS desktop applications. I wanted something similar for GNOME.
So, I started my work on Post Master. It is a [python] GTK
application which helps us connect / edit / explore databases. In the background, it uses SQLAlchemy, which means our
application will support all the database types SQLAlchemy will support.
Features being worked on
- UI for connecting to database
- UI for connecting to database using SSH tunneling
- Pagination of data in table
- Edit data in rows of table
- Delete rows of table
- UI for writing queries
- Export query results to CSV
- Show DDL for tables
- Delete table
- Truncate table
- View data in table
- Switch table and view corresponding table
- Never hard code user directory paths in code. Always use
GLib for this.
- To use a widget as a template, make sure the
composite checkbox is checked in the UI designer.