Using Wing IDE with wxPython
Wing IDE is an integrated development environment that can be used to write, test, and debug Python code that is written for the powerful wxPython cross-platform GUI development toolkit. Wing provides auto-completion, call tips, a powerful debugger, and many other features that help you write, navigate, and understand Python code.
To get started using Wing, refer to the tutorial in the Help menu in Wing and/or the Wing IDE Quickstart Guide.
wxPython is a good choice for GUI developers. It currently available for MS Windows, Linux, Unix, and Mac OS X and provides native look and feel on each of these platforms.
While Wing IDE does not provide a GUI builder for wxPython, it does provide the most advanced capabilities available for the Python programming language, and it can be used with other available GUI builders, as described below.
Installation and Configuration
Take the following steps to set up and configure Wing IDE for use with wxPython:
- Install Python and Wing. You will need a specific version of Python depending on the version of wxPython you plan to use. Check the wxPython Getting Started Wiki when in doubt. See the generic Wing IDE Quickstart Guide for installation instructions.
- Install wxPython. See the wxPython's website Getting Started Wiki for installation instructions. Note that you need to install the version of wxPython to match your Python version, as indicated on the download page.
- Start Wing from the Start menu on Windows, the Finder or OS X, or by typing wing5.1 on the command line on Linux other Posix systems. Once Wing has started, you may want to switch to reading this How-To from the Help menu. This will add links to the functionality of the application.
- Select Show Python Environment from the Source menu and if the Python version reported there doesn't match the one you're using with wxPython, then select Project Properties from the Project menu and use the Python Executable field to select the correct Python version.
- Open the wxPython demo into Wing IDE. This may be located within your Python installation at site-packages/wx/demo/demo.py, or Lib/site-packages/wx/demo/demo.py, or c:\Program Files\wxPython2.6 Docs and Demos\demo, or similar location. On Linux it may be part of a separate wx examples package, for example on Ubuntu 6.06 LTS the demo is in the package wx2.6-examples, is installed in /usr/share/doc/wx2.6-examples/examples/wxPython, and some files in this directory need to be gunzip``ed before the demo will work. Once you've opened ``demo.py, select Add Current File from the Project menu. If you can't find demo.py but have other wxPython code that works, you can also just use that. However, the rest of this document assumes you're using demo.py so you will have to adapt the instructions.
- Set demo.py as main entry point for debugging using the Set Main Debug File item in the Debug menu.
- Save your project to disk. Use a name ending in .wpr.
Test Driving the Debugger
Now you're ready to try out the debugger. To do this:
Start debugging with the Start / Continue item in the Debug menu. Uncheck the Show this dialog before each run checkbox at the bottom of the dialog that appears and select OK.
The demo application will start up. If its main window doesn't come to front, bring it to front from your task bar or window manager. Try out the various demos from the tree on the left of the wxPython demo app.
Important: In earlier wxPython 2.6 versions, a change to the demo code breaks all debuggers by not setting the co_filename attribute on code objects correctly. To fix this, change the line that reads description = self.modules[modID] around line 804 in demo\main.py to instead read description = self.modules[modID] -- Wing will not stop at breakpoints until this is done.
Next open ImageBrowser.py (located in the same directory as demo.py) into Wing IDE. Set a breakpoint on the first line of runTest() by clicking on the dark grey left margin. Go into the running demo app and select More Dialogs / ImageBrowser. Wing will stop on your breakpoint.
Select Stack Data from the Tools menu. Look around the stack in the popup at the top of the window and the locals and globals shown below that for the selected stack frame. You may see some sluggishness (a few seconds) in displaying values because of the widespread use of from wx import * in wxPython code, which imports a huge number of symbols into the globals name space. This depends on the speed of your machine.
Select Debug Probe (Wing Pro only) from the Tools menu. This is an interactive command prompt that lets you type expressions or even change values in the context of the stack frame that is selected on the Debugger window when your program is paused or stopped at an exception. It is a very powerful debugging tool.
Also take a look at these tools available from the Tools menu:
- I/O -- displays debug process output and processes keyboard input to the debug process, if any
- Exceptions -- displays exceptions that occur in the debug process
- Modules (Wing Pro only) -- browses data for all modules in sys.modules
- Watch (Wing Pro only) -- watches values selected from other value views (by right-clicking and selecting one of the Watch items) and allows entering expressions to evaluate in the current stack frame
Test Driving the Source Browser
Don't forget to check out Wing's powerful source browser:
- Add package Lib/site-packages/wx or site-packages/wx inside your Python installation to your project file with the Add Directory item in the Project menu.
- After doing so, Wing may consume significant CPU for some time, depending on the speed of your machine. As it does this, you can already bring up the Source Browser from the Tools menu. Just be patient if things are a bit sluggish at first; there is an awful lot of Python code that Wing needs to analyse. Once the initial analysis is done, Wing will return to being responsive since the results are cached (a similar but shorter effect is seen when Wing is restarted, as it reads the analysis disk cache).
- Select Browse Project Classes mode at the top of the source browser. This is generally the best view to use for wxPython. If you duse the Browse Project Modules view, it helps to select Hide Inherited Classes from the Options menu in the browser.
- Use the right-click menu to zoom to base classes. In general in Wing, right-clicking will bring up menus specific to the tool being clicked on.
- Related to the Source Browser is the auto-completion capability in Wing's source editor. Try typing in one of the wxPython source files and you will see the auto-completer appear. Tab completes the currently selected item, but you can add Enter to the Completion Keys preference to also complete when the Enter key is pressed. See the Wing IDE Quickstart Guide for information on other commonly used preferences. Note: Depending on the speed of your machine, the auto-completer may be sluggish at first, once again due to the large number of symbols imported into most wxPython files with from wx import *. However, this should only happen once per Wing IDE session.
- See also the Source Assistant tool in the Tools menu. This provides additional information about source constructs in the active source editor as the insertion cursor or selection is moved around. Note that this tool is also integrated with the source browser, and with the auto-completer in the editor, Python Shell, and Debug Probe (in Wing Pro).
Using a GUI Builder
Wing IDE doesn't currently include a GUI builder for wxPython but it can be used with other tools, such as Boa Constructor, which does provide a GUI builder but doesn't have the raw power of Wing IDE's debugger and source browser.
To use an external GUI builder, configure Wing to automatically reload files that are altered by the GUI builder. This is done in Preferences in the Files Reloading area.
Then you can run Wing IDE and your GUI builder at the same time, working with both in an almost seamless manner.
A Caveat: Because Python lends itself so well to writing data-driven code, you may want to reconsider using a GUI builder for some tasks. In many cases, Python's introspection features make it possible to write generic GUI code that you can use to build user interfaces on the fly based on models of your data and your application. This can be much more efficient than using a GUI builder to craft individual menus and dialogs by hand. In general hand-coded GUIs also tend to be more maintainable.
Wing IDE provides many other options and tools. For more information: