Skip to content

Instantly share code, notes, and snippets.

@schuster-rainer
Created February 24, 2012 10:27
Show Gist options
  • Save schuster-rainer/1900009 to your computer and use it in GitHub Desktop.
Save schuster-rainer/1900009 to your computer and use it in GitHub Desktop.
Script to reference GTK# assemblies and create an fsi event loop for dispatching the commands
// Script from Tomas Petricek
// http://stackoverflow.com/questions/4174852/how-to-force-f-interactive-to-reference-gtk-by-default
[<AutoOpen>]
module GtkSharp
// Load some common Gtk# assemblies (from /usr/lib/mono/2.0/../gtk-sharp-2.0)
#r "../gtk-sharp-2.0/gtk-sharp.dll"
#r "../gtk-sharp-2.0/gdk-sharp.dll"
#r "../gtk-sharp-2.0/glib-sharp.dll"
#r "../gtk-sharp-2.0/atk-sharp.dll"
open Gtk
Application.Init()
fsi.EventLoop <-
{ new Microsoft.FSharp.Compiler.Interactive.IEventLoop with
member x.Run() = Application.Run() |> ignore; false
member x.Invoke f =
let res = ref None
let evt = new System.Threading.AutoResetEvent(false)
Application.Invoke(new System.EventHandler(fun _ _ ->
res := Some(f())
evt.Set() |> ignore ))
evt.WaitOne() |> ignore
res.Value.Value
member x.ScheduleRestart() = () }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment