Using Wing IDE with PyQt


Home » Support » Index of All Documentation » How-Tos » How-Tos for GUI Development »

Wing IDE is an integrated development environment that can be used to write, test, and debug Python code that is written for the PyQt 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.

For more information on Wing IDE see the product overview. If you do not already have Wing IDE installed, download a free trial now.

To get started using Wing, refer to the tutorial in the Help menu in Wing and/or the Wing IDE Quickstart Guide.

Introduction

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 IDE 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 IDE for use with PyQt:

  • Install Python, PyQt, and Wing. The Wing IDE Quickstart Guide provides installation instructions for Wing.
  • Start Wing from the Start menu on Windows, the Finder on OS X, or by typing wing5.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 IDE (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.

See the Wing IDE Tutorial and Quick start for more information.

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 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 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 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.

Related Documents

Wing IDE provides many other options and tools. For more information:

« 3.0. Using Wing IDE with wxPythonTable of Contents3.2. Using Wing IDE with GTK and PyGObject »