There's an app for this too?!?

While the goal of this project was simply to test the feasibility of using the pressure plate with dogs, but it was clear to me from the start that I needed to make an application out of it. There’s just one little problem... I couldn’t program one bit. Sure I was dangerous enough to do some data processing with Matlab, enough to earn a Masters degree even, but that hardly makes me a programmer. Stack Overflow reminds me of this of this fact every day.

But I was determined to make sure all the other researchers out there, don’t have to go through the same pain every single project. So I started learning Python in August 2010 and with the help of several Stack Overflow questions, I worked my way through several books, tutorials and other available resources to get closer to my goal. Now that I had managed to learn enough of the syntax to be even more dangerous than I had ever been in Matlab and got some very promising results, I got at a imaginary crossroad:

Get more projects and just stick to data processing, basically maintaining the status quo or dive into Python even deeper and finish what I started. Choosing the latter means that I won’t have any new projects until I’ve learned enough to create an app that’s good enough that new projects won’t need me around to do the processing.

Now I can already see some more seasoned programmers starting to look worried: here’s someone with no programming experience whatsoever wanting to learn programming in what? A matter of months? Well, true with the one difference that I’m working on it full-time and don’t have any other projects distracting me. So the first task I set my self: learn how to make a GUI!

With some help of my Super User (Fake-Programmer) buddies, I looked at several possible Python frameworks I could use for my GUI. My first goal was to set out and see if I could make the pressure plate ‘roll off’ on the screen. Pretty simple I would say: just draw a window, draw an image inside it and update that with every frame of the plate right? Well yes, but that doesn’t mean there’s a dozen of ways of doing things of which probably 90% is wrong and pretty darn slow!

I tried looking at Qt, but after Nokia decided to collaborate with Microsoft, that’s probably not going anywhere. Besides Qt is heavily C++ oriented, so I couldn’t make any sense of the documentation and any decent documentation for Python seemed to be lacking. I tried some PyGTK tutorials, only to not get the installation of the GTK part not worki... I guess the Linux guys really don’t like Windows all that much! (Note: I did manage to get it working 2 weeks later). I settled on wxPython, because first of all they have an awesome book, filled with ‘working’ examples and these are also all for download, so if something’s not working in your code, you can compare them to figure out your mistakes (and hopefully learn from them!)

wxPython in Action book cover

While the book is $35 and already from 2006, I can definitely recommend it. It really takes you by the hand to explain the syntax and has clearly written examples. One of the things I appreciated the most is that their syntax is very, very consistent and doesn’t use any ‘fancy’ Python features that obfuscate what the code is supposed to do. Furthermore, it automatically uses the systems native theme, so while your app might look generic, at least it doesn’t look like it originated from Windows 95!

The only complaints I had were some typo’s in the code, which were pretty nasty to locate if you don’t know what the code is supposed to do exactly and the fact that multimedia + graphics were completely under highlighted. Yes, there are code examples that draw bitmaps, yes I can find working examples of an image viewer, but you know what the problem is with those? They’re all static! I want to show off my plate data at 60 fps. I have a fast pc, so the only reason I can’t animate this any faster is because the code I wrote sucks and the book didn’t help me solve that part!

It took me about two weeks to get through the book, because I literally typed out every code example in it and got sidetracked a couple of times when I learned something new and wanted to try that out on my own data. After reading this book, I do feel more comfortable of making a GUI around my code. Now my only worry is the object-oriented part and making sure I design my framework right, so I don’t realize I have to rewrite my code half way through...

To make sure I know what I’m doing, I’m now rereading the chapters on Classes in Learning Python. I can already say that everything makes a lot more sense after having actually used classes in practice. Depending on how confident I am after reading this, I might also read the relevant chapters from Dive into Python or another ‘beginners’ book.

I think knowing classes is vital for developing my app, because though I refactored my code halfway through, I still ended up with one long script that would process all my data at once and stores nothing. You’d almost think I learned nothing... So now I’m planning to properly dissect my code, so I can process the data in a reliable fashion (no crashing half way!) and hopefully also more persistent. Ideally, if all the code is correct, the data would be loaded, processed and the results stored in a database. Every time you’d want to view or analyze the results, you’d simply call the results you needed, without the need of processing every trial of every dog in the process...

So as you can see I, still have a long way ahead of me, but I feel I’ve gotten at least a step closer to my goal!

links

social