(* Compile with
ocamlc -o okey_example.x -I +lablgtk2 -I +cameleon2 lablgtk.cma okey.cmo <this_file> *)
let _ = GMain.Main.init ()
let w = GWindow.window
~title: "Okey example" ~width: 300 ~height: 300 ()
let message s () =
GToolbox.message_box "Okey example message" s
let callbacks =
[
GdkKeysyms._k, [`MOD1], "Alt-k", "Hello", message "Hello" ;
GdkKeysyms._w, [], "w", "World", message "World" ;
GdkKeysyms._q, [`CONTROL], "Ctrl-q", "Quit", GMain.Main.quit ;
]
let txt = "Available shortcuts:\n"^
(String.concat "\n"
(List.map (fun (_,_,s,l,_) -> Printf.sprintf "%s: %s" s l) callbacks)
)
let wl = GMisc.label ~text: txt ~packing: w#add ()
(* Here we add the handlers for some key press events *)
let _ = List.iter
(fun (k,mods,_,_,f) -> Okey.add w ~mods k f)
callbacks
let _ = w#show ()
let _ = GMain.Main.main ()
