LablGtk
Example
(* delete event callback *)
let delete_event e =
print_endline "captured delete event";
(* retrurn false to destroy main window on delete event *)
false
(* destroy callback *)
let destroy () =
print_endline "captured destroy event";
GMain.Main.quit ()
(* main *)
let main () =
let window = GWindow.window
~title:"heh" ~position:`CENTER () ~width:400 ~height:440
~icon:(GdkPixbuf.from_file "icon.png")
in
ignore (window#event#connect#delete ~callback:delete_event);
ignore (window#connect#destroy ~callback:destroy);
GMain.Main.main ()
let _ = main ()
Build with "-I +lablgtk2 lablgtk.cmxa gtkInit.cmx" options.
Gtk+ threads
(* function called from within thread *)
let test_func button =
Unix.sleep 3;
button#set_label "done";;
(* native thread *)
let test_thread button () =
ignore (Thread.create test_func button);
button#set_label "waiting...";;
let main () =
let window = GWindow.window ~title:"Title" ~width:300 ~height:200 in
ignore (window#connect#destroy ~callback:GMain.Main.quit);
(* add widgets *)
let button = GButton.button ~packing:window#add () in
ignore (button#connect#clicked ~callback:(test_thread button));
(* show window *)
window#show ();
(* main gtk+ thread *)
GtkThread.main ();;
let _ = main ();;
Build with "-thread unix.cmxa threads.cmxa -I +lablgtk2 lablgtk.cmxa gtkInit.cmx gtkThread.cmx".
Taking screenshot of the region of the screen
let p = GdkPixbuf.create ~width:400 ~height:400 ~has_alpha:true () in
GdkPixbuf.get_from_drawable p (Gdk.Window.root_parent ());
GdkPixbuf.save "screen.png" "png" p;