<type>how-to</type>
<domain>install</domain>
<id>plone</id>
<title>Using Wing with Plone</title>
<date>$Date$</date>
<product>per+</product>
<summary>Learn how Wing can be used to speed up development and debugging of Python code written for the Plone content management system.</summary>

.. note::
  **"The best solution for debugging Zope and Plone"**
  *-- Joel Burton, Member, Plone Team*

.. image:: /images/screenshots/wing7-screenshot-linen.png
  :alt: Wing Screen Shot
  :width: 574
  :height: 423
  :popup: 1

`Wing <https://wingware.com>`__ is a Python IDE that can be used to develop, test, and
debug Python code written for the `Plone <http://www.plone.org/>`__ content management
system. 

Two versions of Wing are appropriate for use with this document: Wing Pro is the
full-featured Python IDE for professional developers, and Wing Personal is a free
alternative with reduced feature set.

If you do not already have Wing installed, `download it now <https://wingware.com/downloads>`__.

This document describes how to configure Wing for Plone. To get started using Wing as your
Python IDE, please refer to the tutorial in Wing's ``Help`` menu or read the `Quickstart
Guide <ref:howtos/quickstart>`__.

**Note:**  This document is not being maintained and was last tested with Plone 4.

Introduction
------------

These instructions are for the Plone 4+ unified installer. If you are using an older
version of Plone or a source installation of Plone 4 that makes use of old style Products
name space merging, please refer instead to the instructions for `Using Wing with Zope
<ref:howtos/zope>`__.

Configuring your Project
------------------------

To create a new project, use ``New Project`` in Wing's ``Project`` menu. Select the
project type ``Plone`` and under ``Python Executable`` select ``Custom`` and then enter
the full path of the Python you plan to use with Plone. The full path can be found by
looking at the top of many of the scripts in ``zinstance/bin`` or ``zeocluster/bin``. You
can also determine the correct value to use by executing the following commands
interactively in Python. If you are using virtualenv, this will be the virtualenv's Python
executable::

  import sys
  sys.executable

Press ``OK`` and then add the directory with your source code to the new project with
``Add Existing Directory`` in the ``Project`` menu.

Next find and open the file ``zinstance/bin/instance`` and select ``Set Current as Main
Entry Point`` in ``Project`` menu. If you have a ZEO cluster, instead use
``zeocluster/bin/client1`` or whatever name is given in the ``.cfg`` file. Wing reads the
``sys.path`` updates from that file so that it can find your Plone modules.

For Plone 4+, do not use the Zope2 support in ``Project Properties`` under the
``Extensions`` tab. This is not needed unless your Plone installation still uses old-style
Product name space merging.

Debugging with WingDBG
----------------------

To get debugging working you must install WingDBG, the Wing debugger product, which is
located in zope/WingDBG-~~FULL_VERSION~~.tar in the ``Install Directory`` listed in Wing's
`About <script:about-application>`__ box. Unpack it into ``zinstance/products``, or
``zeocluster/products`` in a ZEO cluster.

Then edit your ``etc/zope.conf`` to change ``enable-product-installation off``
at the end to instead read ``enable-product-installation on``. In a ZEO cluster
this file is located at ``zeocluster/parts/client1/etc/zope.conf``. 

Finally, click on the bug icon in the lower left of Wing's window and turn on ``Accept
Debug Connections`` so the debugger listens for connections initiated from the outside.

Then start Plone and go into the Management Interface from `http://localhost:8080/
<http://localhost:8080/>`__ , click on ``Control Panel``, and then on ``Wing Debug
Service`` at the bottom. From here you can turn on debugging. The bug icon in lower left
of Wing's window should turn green. Subsequently, any page loads through
`http://localhost:50080/ <http://localhost:50080>`__ (port 50080) will be debugged and
will reach breakpoints and report exceptions.  This port and other debugger options are
configurable from the WingDBG control panel. Note that requests made through the regular
port (8080 by default) will run without debug.

Once you reach a breakpoint or exception, you can step through code and use the ``Stack
Data`` and other debug tools in the ``Tools`` menu to interact with the debug process.
In Wing Pro, the ``Debug Console`` provides an interactive shell that works in the context
of the current debug stack frame.

WingDBG in Buildout-based Plone 4 Installations
...............................................

In some new buildout-based Plone settings, WingDBG will not load until the
``buildout.cfg`` (generated by the template ``plone4_buildout``) is edited to add the
following just above ``[zopepy]``::

  products = ${buildout:directory}/products

Then rerun ``bin/buildout -N`` which will add a line like the following to your
``parts/instance/etc/zope.conf`` file::

  products /path/to/your/products
  
You will need to add the specified products directory manually, and then unpack WingDBG
into it.

Related Documents
-----------------

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

* `Plone home page <http://www.plone.org/>`__, which provides links to documentation.

* `Quickstart Guide <ref:howtos/quickstart>`__ contains additional basic information
  about getting started with Wing.
  
* `Tutorial <ref:intro/tutorial>`__ provides a gentler introduction to Wing's features.

* `Wing Reference Manual <ref:manual>`__ documents Wing in detail.

