1

I'm having a problem getting the OnLoad event called from an IronPython script that uses WinForms, I've reduced the problem to the smallest possible reproduction case:

from clr import AddReference, accepts, returns, Self
AddReference("System.Windows.Forms")
AddReference("System.Drawing")

import System from System.Windows.Forms import * from System.ComponentModel import * from System.Drawing import *

class DCCForms: # namespace

class Form1(System.Windows.Forms.Form):
    def __init__(self):
        self.InitializeComponent()

    @returns(None)
    def InitializeComponent(self):           
        self.Name = 'Form1'
        self.Text = 'DCC'
        self.Load += self._Form1_Load
        self.ResumeLayout(False)
        self.PerformLayout()

    @accepts(Self(), System.Object, System.EventArgs)
    @returns(None)
    def _Form1_Load(self, sender, e):
        pass

class WindowsApplication10: # namespace
@staticmethod def RealEntryPoint(): Application.EnableVisualStyles() Application.Run(DCCForms.Form1())

WindowsApplication10.RealEntryPoint();

When run, I get the error 'TypeError: Object is not callable.' for the line self.Load += self._Form1_Load. I've also gotten the same error when trying to set a textboxchanged, however adding an OnClick handler to a button works. The code written above was modified from an IronPython 1.1.2 script generated from the IronPython studio sample from the Visual Studio 2008 SDK. However, I'm running it on Iron Python 2.6.1 from inside a PyDev instance.

If I remove the Load statement, the form is generated and responds to OnClick events if specified.

Doug-W
  • 1,318
  • 12
  • 14
  • I've narrowed it down that it's the decorator around the _Form1_Load, using either the accepts or returns decorator causes the issue. – Doug-W Aug 05 '10 at 18:50
  • Why do you need @accepts and @returns decorators? – Lukas Cenovsky Aug 05 '10 at 19:17
  • They were placed there by the IronPython Studio generated code, I assume that they are needed by the CLR to make sure that the WinForms can call into the function with the correct arguments, but I haven't found documentation as to how they work. Do you know where I can go to read up on them? – Doug-W Aug 05 '10 at 19:44
  • The decorators are just there so IronPython Studio can round trip the code. I would suggest using IronPython Tools instead but that would mean either designing the UI by hand or using WPF instead of WinForms. – Dino Viehland Aug 06 '10 at 01:37

0 Answers0