Rapid Prototyping of Native Windows Applications with Python
TL;DR: Build native Windows applications quickly with Python using our newly released boilerplate.
Python is a great choice for creating a rapid prototype of an application. It’s sufficiently powerful, it’s terse, there are a great number of built-ins, there is a huge standard library, and there are hundreds or thousands of useful community-created packages.
At MiserWare, we have been using Python for all of our native Windows application development, including both Granola and FatBatt. Invariably, these applications all begin with a simple dialog-driven prototype. Having gone through the process several times, I thought it would be beneficial to explain how we do it.
- Create wireframes in the Visual Studio dialog editor. For all it’s flaws (and goodness, aren’t there quite a few), the Visual Studio dialog editor is a half-decent way to very quickly create wireframes using easily recognizable elements. As a bonus, the end result is already all bundled up as a REAL DIALOG you can then use within an application.
- Load the dialog wireframes with
pywin32package revolutionized the way I do Windows programming, in that it allowed me to do it in Python. One really handy tool within its impressive arsenal is the
win32rcparsermodule, which allows you to load up the .rc files you generated in the last step. It then drops a whole lot of Pythonic awesome (relatively speaking… it’s certainly no requests) in your lap.
- Plug up your application logic with Python. Using your newly loaded wireframes and some
pywin32glue, it’s easy to get something that will put up your dialog and let you start interacting with it. In my experience, the level of indirection and ease you get out of creating message-loop-driven applications with
pywin32is roughly the same as using the MFC framework, but without the language cruft.
- Build into native executables with py2exe. The
py2exepackage, though it appears to not really be maintained any longer, does the trick for me when it comes to bundling Python applications as native executables. With a bit of magic and usually a decent amount of work, it transforms your lonely, environment-less .py files into strong, independent executables.
- Package as MSI files for distribution with WiX. WiX, though technically it has nothing at all to do with Python, is a free and CLI-friendly way to create native Windows MSI files, which are a must if you are trying to reach a broad audience. There are a number of good WiX tutorials and templates floating around, but in the end you’ll probably need a decent understanding of how the MSI subsystem works in order to build something complex. For the purpose of rapid prototyping, though, a bit of copy-paste-edit should do the trick.
We have bundled all of those steps up into a boilerplate with an example application. The application does little more than load the dialog and process the message loop, but it should serve as a great starting point for a single-dialog application prototype. You can find instructions on how to customize the boilerplate when you’re ready to grow your own application in the README file in the repo.
Let us know what you think in the comments, or holler at me personally on Twitter: I’m @josephturnip.