Pages

2012-12-30

Gtk+'s application development pipeline mess

Look at this normal flow of things, in a normal day of work, in a normal programmer's life:
  1. Design a great UI in a UI designer
  2. Roll all the UI resources into a binary blob and link it to your code so that you dont have runtime dependencies (read as: you dont know where you'll be installed for example)
  3. Ask the UI framework to instantiate the view, wire it up to a controller and get going with your awesome business logic.
Now, I thought, we had this sort of thing sorted out a decade ago. But apparently not with Gtk+. Glade works perfectly fine with external image resources. i.e. you can actually see how your UI will look with all the external images (non stock icons) loaded. And Gtk::Builder crunches that file perfectly fine too.

The problem comes when you want to roll them into a blob using GResource and link it to your binary. Glade does not understand GResources. Glade generates Gtk::Builder understandable xml files. This xml refers to your image files directly. But, GResource wants you to refer to every resource by its own 'resource:///' URI. Gtk::Builder can load an xml from a GResource URI. But the xml itself refers to other resources on the filesystem which sort of
defeats the purpose.

After that brick on my face, I started thinking about workarounds:
  1. Manually fetch the external images from the GResource bundle and link them to the UI built by the Gtk::Builder. This means I cannot see my awesome icons in Glade when I am designing the UI.
  2. Manually edit the xml and change the external resource references to GResource URI. I dont know whether this even works. Even if it works, I do know that the 'cannot see in Glade' problem exists.
This really sucks. Lets get the obvious things out of the way:
  1. Moving to another 'oh so awesome' UI toolkit is not a solution for me. Coz, in the end of the day, I love Gtk+.
  2. Design all your UI in code is not the way forward either. I know I can do it. I HAVE done it a dozen times before. And I know that its a productivity killer. You disagree? Imagine iterating through your UI design 20 times a day, and a build taking 15+ minutes each. That is the biggest deterrent to refactoring your UI.
So, what could be an ideal solution:
  1. Glade should generate the GResource xml definition also. Currently Glade is centered over a 'Gtk::Builder xml file'. Instead Glade should center on the 'GResource definition'. Glade should allow you to add multiple Gtk::Builder xml files into a 'GResource definition'.
  2. Gtk::Builder should understand GResource URI in the xml (if it does not already)
After all that frustration, I resorted back to teaching my build system to tell the executable where the resources were. Now we know why old tricks dont die easy. Arghh.

2 comments:

Nerd Progre said...

two years later, has the situation improved?

FC

Joe Steeve said...

@FC: I am still sleeping with my build system tricks :) Havent checked the new girl yet. Will post once I meet her ;)