Using Wing with PyQt
Wing is a Python IDE that can be used to develop, test, and debug Python code written for the PyQt cross-platform GUI development toolkit. Two versions of Wing are appropriate for use with this document: Wing Pro is the full-featured Python IDE for professional programmers, and Wing Personal is a free alternative with reduced feature set.
If you do not already have Wing installed, download it now.
To get started using Wing, refer to the tutorial in the Help menu in Wing or the Quickstart Guide.
PyQt is a commercial GUI development environment that runs with native look and feel on Windows, Linux/Unix, Mac OS, and mobile devices. While Wing does not include a GUI builder for PyQt, 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 for use with PyQt:
- Install Python, PyQt, and Wing. The Quickstart Guide provides installation instructions for Wing.
- Start Wing from the Start menu on Windows, the Finder on OS X, or by typing wing6.0 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 PyQt, then select Project Properties from the Project menu and use the Python Executable field to select the correct Python version.
- Open examples/demos/qtdemo/qtdemo.py into Wing (located within your Python installation) and select Add Current File from the Project menu.
- Set qtdemo.py as main entry point for debugging with Set Main Debug File 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. You can visit this dialog again later by right clicking on qtdemo.py in the Project view and selecting File Properties or by right clicking on the editor.
- 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.
- Next open menumanager.py from the examples/demos/qtdemo directory and set a breakpoint on the first line of the method itemSelection. Once set, this breakpoint should be reached whenever you click on a button in the qtdemo application.
- Use the Stack Data tool in the Tools menu to look around the stack and the locals and globals for the selected stack frame.
- 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 and also useful for writing new code in the context of the live runtime environment.
- Notice also that when the debugger is active, typing in code that is on the stack (such as in itemSelected) shows auto-completion in the editor and calltips and documentation in the Source Assistant tool that is sourced from the live runtime state of your application.
Test Driving the Source Browser
Don't forget to check out Wing Pro and Wing Personal's powerful source browser:
- Add package Lib/site-packages or site-packages (inside your Python installation) to your project with the Add Directory item in the Project menu. On OS X this is located inside your Python.framework/Versions/#.#/lib/python#.# directory.
- Next bring up the Source Browser from the Tools menu. You can select the view style at the top of the window, to browse by modules, by classes, or only the current file. The Options menu on the right will filter what types of symbols are being displayed in the browser.
- Double clicking on the browser will show the corresponding source code in the source editor area.
- Use the right-click menu on the Source Browser to zoom to base classes. In general, 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 PyQt source files and you will see the auto-completer appear. Tab completes the currently selected item, but you can set the Completion Keys preference to also complete when the Enter key is pressed. See the Quickstart Guide for information on this and other commonly used preferences.
- 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 doesn't currently include a GUI builder for PyQt but it can be used with an external GUI builder. Wing will automatically reload files that are written by the GUI builder, making for a fairly seamless integration.
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 model-driven GUIs also tend to be more maintainable, and the Qt widget set was designed specifically to make hand-coding easy.
Wing provides many other options and tools. For more information: