kennethkam.com

A Simple Python GUI App

A big part of my internship at Airbus was to do with creating an application that would run on Windows. I remember dabbling in wxPython and matplotlib, and the end product was something that resembled a traditional desktop application. Whether it went to production or not, however, is a question that I probably will never be able to answer, but I diverge. I discovered that I can claim a bonus 5% in my design project if I did something ‘extra’. That something extra is a simple application that takes in a few inputs and outputs a graph.

qatool is a simple app that takes in a set of ‘concepts’ and criteria to judge each concept on. Combinations of concepts are compared for each criterion and a simple algorithm generates a graph to see which concept is the best. The lecturer calls it ‘quantitative analysis’ but there’s nothing quantitative about it nor is it really an analysis; searching on google doesn’t even return anything remotely similar to what we were doing. The best way is to download it to see for yourself.

The data that it anticipates is minimal but are related to each other. I thought of using xml to store the data but decided that it was easier to use something like SQLAlchemy to handle the relationships. SQLAlchemy is truly an excellent SQL layer for Python, and has a lot of room for customisation. I only scratched the very surface by opting to use simple features, such as the mapper to relate database rows to Python objects.

The backend was relatively easy to build. Once I had the objects and their relationships working, I devised a simple test case with data created in a spreadsheet application. The development code passed the test case after a day’s work. The difficult part was the GUI, because it meant revisiting my good old friend wxPython. I had to remember what a Frame, Window, or a Panel was (a Panel in a Frame in a Window). Then I had to figure out how I could redraw a Panel coupled with a Frame. The menu was the only way for users to jump from screen to screen, and each menu item was hooked up to a callback to redraw the Panel. Thus I had a lot of repeated code that could benefit from refactoring. I never got round to doing that.

Once I had a firm grip on wxPython, I had to learn matplotlib and its APIs. Fitting it into the panel wasn’t hard work because the internet is always here to help. At the end, I got the app working the way it was intended to. This app is aimed at users that do not have Python installed on their system, so I was hoping that I could either a) package the entire Python installation and its packages or b) use py2exe. a) was not feasible because, gzipped, the file was over 100 MB; b) was difficult because of all the packages I had.

So the last thing to do was to learn how to do b). The py2exe has a page dedicated to teach you how to go around solving these error messages during the wrapping process. I did a simple copy and paste of their setup script, added my own data file entries, ran py2exe with the new script and out came a completely usable application that weighed in at just over 10 MB gzipped.

Overall, I learnt to make a simple GUI app using open sourced tools. I opted not to share my code here because it is so embarrassingly bad but instead I wanted to share my experience. I am certain there must be a good pattern to writing code for GUI apps, and that’s just one more question to ask during my Computer Science course next year.

Comments

  • There are no comments.

Add a Comment