[IronPython] overriding methods from C# classes

Dino Viehland dinov at microsoft.com
Fri Jul 9 19:50:49 CEST 2010

Marcin wrote:
> Dino Viehland wrote:
> >> Is there some way of simply overriding methods in Python so that they do
> >> get called by form events?
> >
> > In both of these cases there are no methods to be overridden.  You're just
> > defining methods which you want to use for the event handlers.  You need
> > to connect those methods to the event handlers somewhere.
> OK hang on a second - WHICH methods do you mean precisely - In the base
> class or the overriden class?
> Bc when I changed declaration of the method to "protected virtual" in
> the Form1.cs, the inherited class calls my Ipython method all right -
> that looks like overriding to me, at least when looking at it from the
> outside and not looking "under covers" what's happening.

Sorry I was confused...  I was thinking the C# code was a comparison not
what you were inheriting from.  

> > Your C# code is
> > working probably because the connection of the event handlers is in the
> > generated code in InitializeComponent().
> It is there all right:
> public void InitializeComponent()
> {
> ..
>      this.comboBox1.SelectedIndexChanged += new
> System.EventHandler(this.comboBox1_SelectedIndexChanged);
> }
> > This is one of the reasons why I suggest WPF over WinForms.  In WPF you can
> > declare the event handlers in the XAML and we can wire them up to you.  In
> > our IronPython 2.7 source code I recently added a clr.LoadComponent method
> which
> > does this.
> Well that certainly makes WPF worth considering. Questions:
> 1. when IPY 2.7 is to be released?

Our current plan is around the end of this year.

> 2. Documentation. This sort of worries me: where do I get the detailed
> info how to use this stuff? So far I have developed only in CPython/Linux...

Most of the documentation for WPF will apply here.  We'll need to document our
LoadComponent but I actually think you won't need to know much about it.  And
for what it's worth is basically mirrors what C#/VB.NET are doing with XAML it's
just more dynamic.

Of course if you want to continue to deploy to Linux w/ IronPython then I think 
WinForms is actually your best bet and you're on the right path.  I say that 
because Mono has WinForms support but not WPF support.

More information about the Ironpython-users mailing list