Posts Tagged ‘GUI’

The Beauty of pyQT

Thursday, October 22nd, 2009

image_thumbHere at Zoom Creates we (the Dev Team) mostly deal with online applications. We build custom sites, implement CMS solutions, build animations, create databases, and much, much more. One thing that you might not have know is that we also build standard desktop applications. One of my favorite toolkits to use for Gui applications is the QT4 toolkit. Of course, my favorite language to build these apps in is python. Here’s a quick rundown of the latest app that I built in about 30 mins, to help remove one annoyance from my daily routine.

I connect to our in office server via sshfs. I also use this protocol when connecting to my webserver, and it gets a little old doing the same thing over and over again in the console. So, to solve this I built a little app that runs the sshfs command with some paramaters and is much quicker to get me connected to different servers. Here’s how I did it.

First run QTDesigner (the awesome GUI builder that Trolltech, the makers of QT, give away) and draw out your new program’s interface. Then save it. My file is named server.ui. Now, if you run pyuic4 on this file, you can send the output to a file. I did this by running this:
pyuic4 server.ui > server.py

So now I have an automatically generated file called server.py that has a class in it. This class has all the references to my GUI that I created in QTDesigner. Now, lets make a new python file that will import that file (server.py) and extend it so that we can give it some functionality. I called this new file mountStuff.py.

We want to extend server.py because if we ever need to make changes to our GUI, then all our code will be lost when we run pyuic4 on our updated .ui file. Check out the attached .zip file to see how this neat little program works.

mountStuff.zip