Home » Support » Index of All Documentation » How-Tos » How-Tos for GUI Development »
4.2. Using Wing IDE with PyQt
Wing IDE is an integrated development environment for the Python programming language. Wing can be used to speed up the process of writing and debugging code that is written for the PyQt cross-platform GUI development toolkit.
PyQt is a commercial GUI development environment that runs with native look and feel on Windows, Linux/Unix, Mac OS, and the Sharp Zaurus. Commercial licensing is per developer, with no cost for each deployed product. It is also available for free for non-commercial users under the GPL license.
While Wing IDE does not currently provide a GUI builder for PyQt, it does provide the most advanced debugger and source browser 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 PyQt:
- Install Python and Wing. Check the PyQt download page to make sure you install a version of Python that will work with the version of PyQt that you use. For example, PyQt 3.5 worked with any version of Python between 1.5.2 and 2.2.x. The generic Wing IDE Quickstart Guide provides installation instructions for Wing.
- Install Qt from Trolltech. You will either need to purchase a developer's licence or download the non-commercial package.
- Install PyQt from the Riverbank PyQt download area.
- Start Wing from the Start menu on Windows, the Finder or OS X, or by typing wing3.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 Analysis Stats 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/tools/qtdemo/qtdemo.py into Wing IDE (located within your Python installation) and select Add Current File from the Project menu.
- Set qtdemo.py as main entry point for debugging by right clicking on it in the project panel and selecting Set As Main Debug File.
- 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.
- Next open the source for one of the demos in Wing IDE and set a breakpoint in code that will be reached when you work with that demo. Exercise the demo so that the breakpoint is reached.
- 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.
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 -- browses data for all modules in sys.modules
- Watch -- 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
As you try out the various demos for PyQt, you may sometimes see Wing IDE pause and report exceptions in the debugger's Exceptions tool. There are a few bugs in some versions of PyQt's demos, so Wing will catch those when the occur.
Test Driving the Source Browser
Don't forget to check out Wing's powerful source browser:
- Add package Lib/site-packages or site-packages (inside your Python installation) to your project with the Add Diretory item in the Project menu. Also add directory tree PyQt (also inside your Python installation) to your project file with the Add Directory item in the Project menu.
- 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. Note that files are automatically closed when you browse elsewhere unless they were already open, edits are made, or you click on the stick pin icon in the upper right of the editor area to specify that the editor should remain open until closed explicitly.
- 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 Wing IDE 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 IDE doesn't currently include a GUI builder for PyQt but it can be used with other tools, such as Black Adder, which does provide a GUI builder but doesn't have the raw power of Wing IDE's debugger and source browser. Another GUI builder for PyQt is Qt Designer, which outputs language-independent UI files that can be converted into Python using PyQt's pyuic utility.<P>
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, and the Qt widget set was designed specifically to make hand-coding easy.
Tips for Keeping the Debug Process Responsive
Because of bugs in some versions of PyQt, there is no code inside the debugger to ensure that PyQt debug processes remains responsive to the debugger while free-running. This means that you may not always be able to Pause PyQt debug processes, and the debugger may time out if you try to add breakpoints or execute certain other debugger operations while the GUI application is free-running and no Python code is being reached.
This problem occurs only when no Python code is reached at all, so it is easy to work around with the following after your QApplication has been created and before you call exec_loop():
# Hack to burn some Python bytecode periodically so Wing's
# debugger can remain responsive while free-running
import os
if os.environ.has_key('WINGDB_ACTIVE'):
timer = QtCore.QTimer()
def donothing(*args):
x = 0
for i in range(0, 100):
x += i
timer.connect(timer, QtCore.SIGNAL("timeout()"), donothing)
timer.start(200)
Related Documents
Wing IDE provides many other options and tools. For more information:
- Wing IDE Reference Manual, which describes Wing IDE in detail.
- PyQt home page, which provides links to documentation.
- Wing IDE Quickstart Guide which contains additional basic information about getting started with Wing IDE.
| « 4.1. Using Wing IDE with PyGTK | Table of Contents | 5. How-Tos for Other Libraries » |
