[IronPython] Trying (unsuccessfully) to subclass Gtk.Widget class

Eric Larson ionrock at gmail.com
Mon Sep 18 20:56:19 CEST 2006


I think you might have to set your module your of your PythonEngine to
"__main__". For example:

PythonEngine myPyEngine = new PythonEngine(someEngineOptions);
EngineModule mainModule = myPyEngine.CreateModule("__main__", someVariables,
true);

myPyEngine.ExecuteFile(someScriptFile, mainModule);

There are some extra there such as the "someVariables" but hopefully that
might get you going in the right direction.

HTH

Eric

On 9/15/06, Michael Welch <michaelgwelch at gmail.com> wrote:
>
> Hello,
>
> I'm running IPython 1.0 on mono on Linux. I'm importing the gtk-sharp
> dll and I want to subclass the Gtk.Widget class
> (http://www.go-mono.com/docs/monodoc.ashx?tlink=5@ecma%3a1361%23Widget%2f
> ).
>
> Here is my script:
>
> clr.AddReference("gtk-sharp")
> clr.AddReference("gnome-sharp")
> from Gtk import *
> from Gnome import *
>
> Application.Init()
>
> class Table:
> pass
> class Sheet(Widget):
> def __init__(self, table):
>    Widget.__init__(self)
>
> Here is my ipy session where I try to use Sheet
>
> IronPython 1.0.2432 on .NET 2.0.50727.42
> Copyright (c) Microsoft Corporation. All rights reserved.
> >>> import sheet
> >>> from sheet import *
> >>> t = Table()
> >>> s = Sheet(t)
> Traceback (most recent call last):
> TypeError: no overloads of Sheet could match (type, Table)
>   Sheet(type, IntPtr)
>   Sheet(type, GType)
>
> >>>
>
> It tells me it can't find an appropriate overload for Sheet and then
> gives me what looks like the only two possible candidates. However,
> the candidates it lists looks like they are from the parent class
> Widget. Does IronPython hava a constraint that the __init__ method
> must take the same parameters as the parent class? Here is the list of
> constructors for Widget:
> http://www.go-mono.com/docs/monodoc.ashx?tlink=5@ecma%3a1361%23Widget%2fC
>
> If I remove the parameter from __init__ it works. I've tested this
> scenario with made up classes and it works. CPython documentation
> seems to indicate that a child class can have different parameters on
> its __init__method then the parent class. Any help? Is there something
> wrong with the gt-sharp library (I don't think so, as I could write a
> C# app that did this same thing and it worked).
>
> I'm convinced this must be user-error and I'm just not seeing the problem
>
> Thanks,
> Michael
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060918/baab5fa3/attachment.html>


More information about the Ironpython-users mailing list