I think the following might be a workaround for this:
import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('IronPython')

from System.Windows.Forms import Form, Application, TextBox

class MyTextBox(TextBox):
    ProcessDialogKeyCopy = TextBox.ProcessDialogKey

def ProcessDialogKey(s, key):
    print key
    return MyTextBox.ProcessDialogKeyCopy(s, key)

MyTextBox.ProcessDialogKey = ProcessDialogKey

class ThisApp(Form):
    def __init__(self):
        Form.__init__(self)
        tb = MyTextBox()
        self.Controls.Add(tb)
        Application.Run(self)


def main():
    f = ThisApp()


if __name__ == '__main__':
    main()

From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Glenn Jones
Sent: Friday, November 28, 2008 5:01 AM
To: Discussion of IronPython
Subject: [IronPython] Blocker: ProcessDialogKey on TextBox subclass

Hi All,

Here is a little app that illustrates an issue that we've just discovered:
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('IronPython')

from System.Windows.Forms import Form, Application, TextBox

class MyTextBox(TextBox):
    def ProcessDialogKey(self, key):
        print key
        #super(MyTextBox, self).ProcessDialogKey(key) # Fails with a stack 
overflow
        #TextBox.ProcessDialogKey(self, key) # Fails with: 
Microsoft.Scripting.ArgumentTypeException: cannot access protected member 
ProcessDialogKey without a python subclass of TextBoxBase

class ThisApp(Form):

    def __init__(self):
        Form.__init__(self)
        tb = MyTextBox()
        self.Controls.Add(tb)
        Application.Run(self)


def main():
    f = ThisApp()


if __name__ == '__main__':
    main()
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------

Uncommenting either of the two commented lines produces the results on that 
line when a key is pressed in the text box. The second method of calling 
ProcessDialogKey worked in IPy 1.

This is likely to block our progress on porting Resolver One to IPy2 unless 
there is a different way of accomplishing the same thing.

Thanks
Glenn & Will
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to