[IronPython] Experience installing IP with the new WPF CTP

Iain Mackay imm at iain-mackay.org
Wed Dec 28 01:25:18 CET 2005

I ran into several problems running the first Avalon example from the
tutorial, using IP 0.9.6

I should mention that at this time I was running .net Framework 2.0 and the
Dec 2005 CTP preview of WPF x64 versions without the Framework SDK;
installing the SDK subsequently did not change the behaviour.

I noticed three problems:

- I couldn't set the Text attribute on a Window object
- I couldn't set the TextContent attribute on a TextBlock object
- the class RepeatBehaviour seems not to be imported.

Another strange aspect is that I get this far when I enter the script
interactively to the console, but when I put the script in a file and
execute it from the command line I get the exception:
"System.InvalidOperationException: The calling thread must be STA, as many
UI components require this." on calling the Show method of the Window
object. I think I might need to rebuild the console to sort this out - C#
and .net threading models are rather a steep learning curve for this
evening, so I've stuck to interactive experiments for now.

Here's my console experience following the tutorial:

IronPython 0.9.6 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> from avalon import *
>>> w=Window ()
>>> w.Show ()
>>> w.Text="Avalon app"
Traceback (most recent call last):
   at <shell>
TypeError: can't set arbitrary attributes on built-in type

This is quite right, because Windows do not have a Text attribute. However,
if you set Title, all is well.

>>> w.Content = TextBlock ()
>>> w.Content.TextContent = "Hello IronPython!"
Traceback (most recent call last):
   at <shell>
TypeError: can't set arbitrary attributes on built-in type

Similarly, w.Content.Text = "Hello IronPython", works just fine. You can
discover the attributes of w of course just by:

for (key, value) in w.__dict__.items (): print key, value

(Iron)Python is so cool like that.

>>> w.Content.FontSize = 50
>>> a=DoubleAnimation(0.0,Duration(TimeSpan.FromSeconds(3)))
>>> a.RepeatBehaviour = RepeatBehaviour.Forever
Traceback (most recent call last):
   at <shell>
NameError: name 'RepeatBehaviour' is not defined
>>> ^Z

I didn't persist beyond here just yet. I suppose there have been some
substantial changes in object properties during the evolution of WPF as seen
in this latest preview, not yet reflected in the tutorial source - a life on
the bleeding edge thing.

>>> import sys
>>> sys.path

Anyway, a whole lot of wonderful things are working straight out of the box,
including the XAML calculator. This is going to be a lot of fun. Thanks to
everyone for getting things this far. Am I doing something silly to get the
threading problem?

Iain MacKay

More information about the Ironpython-users mailing list