[IronPython] Blocker: ProcessDialogKey on TextBox subclass

Dave Fugate dfugate at microsoft.com
Thu Dec 4 02:12:13 CET 2008


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: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20081203/b73585c2/attachment.html>


More information about the Ironpython-users mailing list