From Old To New Python GTK

by | Tue 24 Jan 2012

I am a pretty terrible programmer. Anyone who has read my code can see that. Unfortunately, I tend to have lots of ideas about how we can use technology in different ways, hence why I write some code. Examples of this have included Lernid, Acire, RaccoonShow, and Jokosher.

Fortunately (or unfortunately, depending on your view), I have had Python and GTK to serve my needs here. Python, with it’s awesome batteries-included range of facilities and GTK as a simple yet flexible toolkit has allowed me to create implementations of the ideas that I have dreamed of. I started using these tools many years ago, and they have always provided a simple and effective toolset for me.

My preferred toolset of choice. One day…

Having not written any code for a while, I got the itch this weekend to start writing the trophy helper app that I wrote about as part of the accomplishments system spec that I created with Stuart Langridge and Daniel Holbach. I thought this would be a good opportunity to brush up on my skills, given that PyGTK is dead and the new world is instead the GIR approach to GTK. In a nutshell, this is where the language bindings basically match the C API for GTK thus reducing the need for people to maintain different language bindings.

Of course, this is a good thing: less work for volunteers in maintaining multiple-language support for GTK and a consistent API is good. Unfortunately, I found getting started with this new world a little more complex than I imagined.

From reading the documentation it suggested that all I needed to do was to import Gtk from gi.repository and instead of creating widgets with gtk.<foo> that they would be Gtk.<foo>. The docs suggested a few other lexical adjustments, but not much more than that. There is even a pygi-convert.sh script that can convert older PyGTK code over to the new PyGI way. Unfortunately the script didn’t work for me, so I instead used it as a cheat-sheet for things that needed changing. Sadly, it seemed like some things were not covered in the script.

An example of this included when I was creating a ListStore. In PyGTK code I could add a gtk.gdk.Pixbuf to the ListStore for an icon, but I had a difficult time trying to figure out the new way to describe this. I tried Gtk.gdk.Pixbuf and Gtk.Gdk.Pixbuf but had no luck. Fortunately the awesome Ryan Lortie informed me that it needed to be GdkPixbuf.Pixbuf. Another example of this was gtk.SORT_ASCENDING in my original code and the new Gtk.SortType.ASCENDING in the new code. It seems like various functionality in GTK has been moved around and re-factored.

Unfortunately I could not find any documentation to help me with this. Sure, the C docs are available online, but I am not a C programmer; I am (in the most generous and understanding way) a Python programmer and where I previously had a pretty decent tutorial and reference guide to PyGTK, as a desktop app developer I no longer have these resources to help me. Even though I am not a fantastic programmer, I have written enough Python and GTK code to fumble my way through writing various apps, and if it stumped me as a relatively old hand, I wonder how a brand new developer would get on.

Pictured: old hand.

Now, this may sound a little critical, but it is not mean’t to be. I have tremendous respect for the GTK team, and I am hugely thankful to them for all their hard work. I am also thankful for the team that has worked on the GIR support so that multiple language support can be more efficiently provided. Thanks to all you folks for providing great tools that let a programming numpty such as myself be able to write Free Software.

I just wanted to share this because I feel like these tools are missing the final component: if we had a good solid set of reference documentation generated for each language (naturally, Python is the language I mainly care about), this would help novice and established developers use GTK more effectively. From my personal experience, my patience started wearing pretty thin when I felt like I didn’t have anywhere to find help as I navigated C documentation to try and figure out how the API fitted into my Python application. A good solid Python reference manual would have resolved this issue, and from what I understand, this could potentially be generated from the GIR files. Unfortunately, I don’t think I have the skills to help solve this problem, so I figured the best I could do was to share my story and see if anyone would be interested in helping to solve this problem.

If so, thanks in advance, and thanks again to the GTK team for all your hard work!


I found this excellent documentation after publishing this entry. This provides exactly the kind of documentation I was looking for. Thanks to anyone who helped contribute to this!


Unlock the potential of your audience with world-class tutorials, guidance, training, and other content delivered FREE directly to your inbox.

No spam. No selling of your information. No BS.

Want to read some more?

Slack vs. Forums: How to Choose

Slack vs. Forums: How to Choose

In 1934, American essayist Christopher Morley founded a literary society devoted entirely to Sir Arthur Conan Doyle’s Sherlock Holmes novels. The inaugural meeting occurred at the Christ Cella restaurant in New York City, as members gathered to discuss the character,...

Nine Critical Best Practices for YouTube Success

Nine Critical Best Practices for YouTube Success

Looking for more YouTube channel success? If so, read on, I'll be giving you 9 tips to make sure you can get there. But First.. Why YouTube? With over 2 billion monthly active users, and over one billion hours of video watched every single day, YouTube’s power and...

Jillian Hufnagel on Building Culture and Growth in Teams

Jillian Hufnagel on Building Culture and Growth in Teams

Jillian Hufnagel is a successful business coach working with companies on topics like emotional agility and harmony in the workplace. Once a teacher and executive assistant, she subsequently became a leader in companies driving healthy emotional cultures. One such...

How to Spot Trends in Blog Content That Boost Traffic

How to Spot Trends in Blog Content That Boost Traffic

Do you need to know how to spot trends in blog content? An estimated 600 million websites on the internet today have blogs, with almost 2 billion blog posts being published every year. That translates into 4,000 blog posts appearing online every minute. That’s a...

How to Have an Executive Session With Yourself

How to Have an Executive Session With Yourself

Are you feeling confused, stressed, or have some issues about your business/career that you need to resolve? If so, you're in the right place. This video covers how to have an executive session with yourself so you can keep growing as a person and business. Having an...

How to Design an Effective Audience for Your Content

How to Design an Effective Audience for Your Content

Pop quiz! Who is your target audience? It should be an easy question to answer, but how specific can you be? When you’re creating content, do you have a well-defined avatar in mind? An honest answer for a lot of content creators would be, “Eh…sort of.” Indeed,...

Pin It on Pinterest

Share This