wxPython Conventions

Magnus Lycka lycka at carmen.se
Wed Feb 1 03:07:52 EST 2006


Jared Russell wrote:
> My other question involved the proper location of specific functions.

Never mix business with plea^h^h^h^hGUI. I'd suggest that you write a
Python module with all your business logic that you can test from the
interactive interpreter. Roughly like this:

 >>> import gmailchecker
 >>> def show(text):
...     print text
...
 >>> gmailchecker.login('username', 'password')
 >>> gmailchecker.check(show, 10)

When you build a GUI, you will pass in some bound
method of one of your widgets that will alert the
user instead of the show function above.

This approach makes your code much more useful. You
can use it in other contexts than a small GUI app,
you can swap GUI when you want that, and you can
easily write unit tests for your logic.



More information about the Python-list mailing list