Making Sample Apps

Often when people have problems with figuring out how to do something, or to make things work the way they expect, they will ask about it on the mail list. The most common response to their initial question is something like, "Please create a small runnable app that shows the problem and send that to the list." This is a very useful tool for those giving help because:

How to make a sample

Just to be clear, the sample app you send to the list should not be a copy of the app you are having trouble with. Nobody wants to read through all the rest of the code of your app just to figure out one little problem with one widget 15 clicks away from the startup. It should also usually not be a copy of your app with lots of stuff ripped out. To have a chance of solving the problem yourself it is best to figure out how to make the mistake again, so you can then figure out what not to do. So here are some suggested steps about how to make a sample app to send to the list.

  1. Start from scratch with just a frame, a panel and the control(s) that you are having trouble with, and put it all in one module.
  2. Initialize the control with some typical values like what your app uses.
  3. If it's applicable to the problem hook up some event handlers that are the same or similar to what your app uses, if any of them need app-specific data or functionality then just stub it out with static or generated bogus data/functionality.
  4. Keep work needed for the previous steps as simple as possible. Do just enough work to show the problem. For even a novice programmer with basic wx familiarity these steps should take 15 minutes or less.
  5. Run your sample. If it misbehaves in the same way as your app then you can usually assume that it is a wxPython problem, or maybe that you are just using wxPython in the wrong way. Send your sample and questions about it to the wxPython-users list. If the sample doesn't misbehave then it is almost certainly a problem in your app and you can progressively add things to the sample until you duplicate the problem and then that can help you to figure out how to fix it in your app.
  6. When you send your sample app and questions to the wxPython-users list be sure to mention the version of wxPython you are using, and also the platform(s) you are using when the problem manifests itself.
  7. Unless you are absolutely sure that all the lines in your sample code are short enough to not be word-wrapped by mail software then DO NOT paste your code into the main body of your email message. Send your code as an attachment instead. Note that you can not make attachments when using the Google Groups Web interface to read and respond to messages, you will need to send an email message from your subscribed mail address instead. Update: Google has a new beta UI for the Groups application. If you switch to the new UI you will be able to attach files to messages posted via their browser interface.

Read the last item above once more. Repeat until it is burned into your memory!

Other helpful hints

  1. wxPython version: Since many of the typical helpers have multiple versions of wxPython installed on their systems, they will want to make sure that the version they test with is the same one that you reported the problem about. I've found it helpful to add the following line into the code just after the wx module is imported. If you do it for us before you send your sample then that will be another bit of time that you can save for the helper.

     print wx.version() 
  2. Widget Inspection Tool: Another thing that I almost always add into the samples that are sent to the list are statements for loading and activating the Widget Inspection Tool, especially if the problem has to do with layout issues. It gives a simple hierarchical overview of the widgets and sizers in the application, a way to view common properties of the widgets, sizers and sizer items, and also a PyCrust shell for interacting with selected widgets in an interactive Python interpreter. If you also make use of this tool it may help you to solve problems yourself before you give up and send the sample to the mail list. To activate and use the tool simply add these lines into the sample just before MainLoop is called:

     import wx.lib.inspection
     wx.lib.inspection.InspectionTool().Show() 

Comments

Franz Steinhaeusler 01/30/07

I'm very glad you created this page. It was also my opinion for a long time now, that people should always create a small as possible sample to show the difficulties with the code. And It saves time for everybody interested in it and we have a common base to discuss, trying out and find a possible solution.

MakingSampleApps (last edited 2011-06-16 16:05:10 by c-98-246-90-205)