Monday, 13 June 2011

Making PyQt experimentation easier

Over the past few months, I've encountered the same issue. namely, I want to do *SOMETHING* with the openmolar project be it:
  1. document with sphinx
  2. write unittests (I know... I should have written them 1st..)
  3. make a deb or rpm
  4. make a windows executable
  5. convert to python 3 with 2to3 etc..

Rather than risk breaking my main codebase however, I believe it always helps to attempt this stuff with a smaller application first I think. So I've written one. It is trivial enough to keep the codebase simple, but complex enough to be realistic.

It raises dialogs, stores data, etc.

I've tried to follow a lot of my coding style choices (which you may hate), but on checking the modules with pylint, most get a 10/10, only decreasing when PyQt4 own naming conventions dictate.

anyways, to cut to the chase.. the code is here is anyone wants a play. This is in the public domain, so do with it as you wish.
download it from my dropbox account http://dl.dropbox.com/u/1989100/example_pyqt_app.tar.bz2

My current focus is writing unittests (something I am ashamed to admit I have never done before), and it is proving VERY interesting.

for example. dialogs are interesting, in that the exec_ function needs to be called to ensure correct code coverage. Calling that during a test run causes a pause in the procedings.. not good.

So what is the best way to call accept() or reject() on such a dialog?
I am experimenting with installEventFilter into QApplication itself, and accepting the dialog when the focus event is encountered seems to be working really well.

2 comments:

Ben said...

Dogtail? I might be misunderstanding what you're trying to do, though.

Neil said...

Dogtail looks very interesting, and I hadn't heard of it, so thanks!

gui testing is but part of my experimentation here though.

Neil.