SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

Matt Ward

IronPython 2.0 Forms Designer

Support for designing Windows Forms in IronPython is now available in SharpDevelop 3.1. The original IronPython forms designer was removed when SharpDevelop 3.0 began supporting IronPython 2.0 which had removed support for generating IronPython code from Microsoft's CodeDOM. The forms designer has now been re-implemented to use the IronPython abstract syntax tree (AST) and no longer relies on the CodeDOM.

Creating a Windows Application

To create a Windows Application open up the new project dialog by selecting New then Solution from the File menu. Select the Python category to show the available project templates. Select the Windows Application project template, enter a name and location and click the Create button.

New Python Project Dialog

Designing Windows Forms

The Windows Forms designer is not yet complete so be warned that it could generate form code that will no longer compile.

The designer can be opened by opening a form in the text editor and selecting the Design tab at the bottom of the editor.

Python main form before opening the designer

Once open in the designer you can add controls to the form by dragging the controls from the Tools window. In the screenshot below a label, text box and a button have been added.

Main form designed in designer

Click the Source tab at the bottom of the editor to view the generated code in the InitializeComponents method.

Generated form code

Limitations

The IronPython forms designer is not yet complete and the following are some of the known limitations.

  1. No support for project or local form resources.
  2. No support for icons.
  3. Incomplete support for ToolStripItems and menu strips.
  4. Incomplete support for ListViewItems.
  5. No support for TreeViewItems.
  6. Incomplete support for non-visual components (e.g. Timers).
  7. Controls needed to be fully namespace qualified.

Forms Designer Internals

For those interested in how the forms designer actually works at a high level we will now look at what the IronPython forms designer does when loading and then generating code for a form.

To show the form in the designer the following steps are executed.

  1. The form's code is parsed and an IronPython AST (PythonAst object) is created.
  2. The AST is then visited and each control is added to the forms designer and the control's properties are set.
  3. The form's properties are set in the designer and the form is displayed.

To generate the code after the form has been designed the following steps are executed.

  1. The form is obtained from the forms designer.
  2. Each of the child components of the form have their properties checked to see if they need to be serialized. This can be done by getting all the property descriptors and then checking the ShouldSerializeValue method. If they do need to be serialized then code is generated for them and added to a StringBuilder.
  3. After all the child components are added the code for the form is generated.
  4. Finally the generated code is inserted into the text editor inside the InitializeComponent method, replacing any existing code.
Published May 12 2009, 08:50 PM by MattWard
Filed under: ,

Comments

No Comments
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.