Main Content

wxPython - simple example to add GUI to a server log file analysis

Archive - Originally posted on "The Horse's Mouth" - 2010-12-08 23:22:57 - Graham Ellis

On our Python courses, we briefly introduce the various GUIs (Graphic User Interfaces), and where we have delegate(s) with an interest in one particular GUI, we'll spend a little longer on examples within a GUI. If delegates need to go deeper into GUI programming, we can provide an extra one day course on request - typically, we'll run that at a later date to ensure that the folks have good chance to practice the basics.

A GUI application (whether using TkInter, wxPython, or PyQt ...) is structured to run as follows:
  a) Define the component parts of the GUI ("the widgets")
  b) Define how they are laid out ("the geometry")
  c) Define what's to be done when the user does something ("the event handlers")
  d) Display the GUI
  e) Enter a loop where the code waits for an event, and when it gets one it processes it

In wxPython, the widgets, geometry and event handlers are defined within a wx.Panel, which in built into a wx.Frame for display. The event handlers then call user defined methods to process events, which in turn call methods which are loaded from other modules / files / classes to perform the business logic (i.e. "real work") behind the GUI.

There's a complete example, written to illustrate this linkage to business logic, [here]; in this particular case it's all in the one single file so that it's easy for you to cut and paste and run the whole example. You'll need some web server log files, and in the example they're named to start ac_201... , to try the code out. If you run your own web server, you should have plenty of data ... either "common" or "combined" Apache log file format will work in this program; if you don't, there's a sample log file on our server at http://www.wellho.net/data/ac_20100322.xyz