[IronPython] IronPython+Gtk#+.NET?

Dino Viehland dinov at microsoft.com
Sat Jul 18 21:00:24 CEST 2009


>From the stack trace this looks like it's Gtk# not interacting well
w/ dynamic defined subclasses on .NET.

My guess here is it's because IronPython defines a subclass of Gtk.Window
which lives in an AssemblyBuilder instance.  This is an in-memory only
assembly and therefore .NET throws NotSupportedException when you try
and get the location.  Mono probably returns some value - that value
may or may not make sense instead but at least it lets other code
muddle along.  Given that this works on Mono my guess is the location
isn't all that important to Gtk here or they're handling the odd value
Mono returns already.

So the correct thing would be either for Mono to throw the same exception
and Gtk# to deal w/ that, for Gtk# to deal w/ both, or for .NET to
not throw the exception and return a value like Mono does.  I'm not
sure which one of those it is but the good news is it should be easy to work
around in the latest IronPython.  That's because we have a pre-compiled
types feature that's new in IronPython 2.6.  It's primarily there for
startup perf but it should work for this too.

You can probably just do:

import clr
clr.AddReference('gtk-sharp')
import Gtk
class MyWindow(Gtk.Window): pass

clr.CompileSubclassTypes('mytypes', *clr.GetSubclassedTypes())

Then just copy mytypes.dll to the DLLs directory or clr.AddReference
it at the start of your app.  You'll then get an on-disk version
of the subclass for Gtk.Window and the call to Location should now
be fine.


> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of Brian Parma
> Sent: Friday, July 17, 2009 9:35 PM
> To: users at lists.ironpython.com
> Subject: [IronPython] IronPython+Gtk#+.NET?
>
> I've been trying to make a simple IronPython+Gtk# app that draws an
> image to the screen, and I'm having trouble getting it to run in
> windows
> (.NET).  It's pretty simple so I attached it at the end.
>
> It runs fine in Mono on Ubuntu and Windows, but when I try to run it on
> windows using .NET I get the following error followed by a really long
> calltrace:
>
> Marshaling expose_event signal
> Exception in Gtk# callback delegate
>   Note: Applications can use GLib.ExceptionManager.UnhandledException
> to
> handle
> the exception.
> System.Reflection.TargetInvocationException: Exception has been thrown
> by the ta
> rget of an invocation. ---> System.NotSupportedException: The invoked
> member is
> not supported in a dynamic assembly.
>    at System.Reflection.Emit.AssemblyBuilder.get_Location()
>    at GLib.GType.LookupType(IntPtr typeid)
>    at ...
>
>
> I have the latest 'Gtk# for .NET' package from the Mono site, and I've
> tried with IP 2.0.1 and IP 2.6 Beta, they give the same results.
>
> I rewrote the program in C# and it works fine in .NET (without Mono),
> using #Develop IDE.
>
> Is this possible?
>
> code:
>
> import clr
> clr.AddReference('gtk-sharp')
> clr.AddReference('gdk-sharp')
> import Gtk
> import Gdk
>
>
> class MyWindow(Gtk.Window):
>     def __init__(self, title='Main Window'):
>         Gtk.Window.__init__(self, title)
>
>         self.pb = Gdk.Pixbuf('image.jpg').ScaleSimple(600,436,
> Gdk.InterpType.Bilinear )
>         self.da = Gtk.DrawingArea()
>         self.da.SetSizeRequest(self.pb.Width, self.pb.Height)
>         self.Add(self.da)
>         self.Decorated = False
>
>         self.DeleteEvent += self.delete_event
>         self.da.ExposeEvent += self.expose_event
>
>     def expose_event(self, *args):
>         self.da.GdkWindow.DrawPixbuf(
> self.Style.BackgroundGC(self.State), self.pb, 0, 0, 0, 0,-1, -1,
> Gdk.RgbDither.None, 0, 0)
>
>     def delete_event(self, *args):
>         Gtk.Application.Quit()
>
>
> if __name__ in ['__main__','Program']:
>     Gtk.Application.Init()
>     mw = MyWindow('Test')
>     mw.ShowAll()
>     Gtk.Application.Run()
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list