I recently decided to get back into desktop applications. Since about 2000 I’ve focused on developing for the web using Perl and PHP (mostly PHP). But sometimes it is nice to write a desktop app, instead of having to write a web app for everything. I’ve written some applications using the PHP CLI option, but that isn’t quite the same as a gui. My motivation was to write a GUI that controlled ffmpeg and would allow me to capture screen casts for tutorials I needed to make.
I started my adventure looking at a GUI frontend for PHP. And ran across PHP-GTK+. I installed it, and looked at some tutorials on it, but the more I looked, the more it looked like the community was inactive and stale. I also couldn’t find any way to package my application to share with others. They would need to install PHP, compile GTK+ (which wasn’t all that easy), reconfigure PHP and then run my application. Although most of the programs would be for my eyes only, it would be nice to have the option to share from time to time. So that was the end of the road for my PHP adventure.
I then decided to look at other languages for developing the application. I considered some of the options out there, Java, C, Ruby, Python, but decided to give Python a try. I’ve coded Java before, and I wasn’t a fan. Always seemed like overkill for everything I wanted to do. I’ve heard lots of good stuff about Python, and it is usually installed with most Linux installations, so this was my language of choice.
I then began looking for a good IDE for Python. Being a big fan of Eclipse, I ran across pydev for Ecplise. A simple install into the software manager in Eclipse, and I was off to the races. You will need to configure the location to your python binary, which for me (Ubuntu 9.10) was in /usr/bin/python2.6 Enabling this, gives you all the fancy code completion which I love so much. If you need to set it up, you need to visit (In Eclipse) Window -> Preferences -> Pydev -> Interpreter – Python -> New… and browse to your python binary. (If you do not have python available, you may need to install it first using apt-get or Synaptic Package Manager. Just search for python, and it should install everything you need to get started.) Here are some tutorials for getting started with Python:
I’ve used Glade once before, very briefly just to figure out what it was. It is a GUI drawer. Similar to the GUI drawer in Visual Basic, it allows you to layout your interface without using code. It creates XML files which can be imported by your application (and it has bindings for many languages) that create your interface. You just need to connect your code to the signals in the GUI, and you can make magic happen. You will need to install Glade via Synaptic Package Manager. The current version is the 3.6 series. Here are some great tutorials to get you started with Glade:
- GTK+ and Glade3 GUI Programming Tutorial
- Writing a GUI app with Python & Glade
- A Beginner’s Guide to Using pyGTK and Glade (older, but still useful)
So, my first dabble in GUI desktop programming in a decade, and my first taste of python. About 5 hours later I had written the application I wanted. It is an 84 line python script binding to one glade file for the interface. It allows me to select a window, and using a pre-set configuration, launch ffmpeg and record a screencast. Still a lot of work to do before it is ready to be shared, but it is a great start. Using pydev via Eclipse for the Python coding, and Glade for the interface design, you should be able to turn out some simple desktop apps in a matter of hours.
This is probably just the beginning of my python coding, so you may see more here on that in the future.