Delivered-To: garrigue at math.nagoya-u.ac.jp Delivered-To: lablgtk-list at smtp.ocamlcore.org From: Philippe Strauss Date: Fri, 18 Mar 2011 17:11:21 +0100 Message-Id: <29125906-5A7B-4D0C-9450-9D3B677D7C82 at philou.ch> To: lablgtk-list at lists.forge.ocamlcore.org Mime-Version: 1.0 (Apple Message framework v1082) Subject: [Lablgtk-list] alternative to the gtk main loop (for a simple use of React) Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello Lablgtk users, I'm looking to an alternative mainloop for running React in the following simple way (code attached). I've read about lablgtk-react but didn't fully understand how it should be used, and I'm looking at a simpler React usage. Regards. - - --8<-- open React type domain_t = Time | Frequency class gui_t = let wtop = GWindow.window ~title:"Room acoustic deconvolution" (* ~width:800 ~height:600 *) () in let vbox = GPack.vbox ~packing:wtop #add () in let menubar = GMenu.menu_bar ~packing: vbox #pack () in let toolbar = GButton.toolbar ~packing:(vbox #pack ~expand:false) () in let _ = toolbar #set_orientation `HORIZONTAL in (* * menu *) let menu_action = GMenu.menu_item ~label:"Action" ~packing: menubar #append () in let menu_act = GMenu.menu () in let menu_act_quit = GMenu.image_menu_item ~stock:`QUIT ~packing:menu_act #append () in let _ = menu_action #set_submenu menu_act in let menu_help = GMenu.menu_item ~label:"Help" ~packing: menubar #append ~right_justified:true () in let menu_h = GMenu.menu () in let menu_h_about = GMenu.image_menu_item ~stock:`ABOUT ~packing:menu_h #append () in let _ = menu_help #set_submenu menu_h in (* now in the toolbar *) let hbox_tbar = GPack.hbox ~packing:toolbar #add () in (* radio buttons in the toolbar *) let frame_chan = GBin.frame ~label:"Channel" ~packing:hbox_tbar #add () in let hbox_radio = GPack.hbox ~packing:frame_chan #add () in (* Reactive (frp) things *) let pprint_domain dom = match dom with | Time -> Printf.printf "domain: time\n%!" | Frequency -> Printf.printf "domain: frequency\n%!" in let pprint_channel ch = Printf.printf "channel: %d\n%!" ch in let rdomain, set_domain = S.create Time in let rchannel, set_channel = S.create 0 in let p_dom = S.map pprint_domain rdomain in let p_chan = S.map pprint_channel rchannel in (* channels buttons *) let btn_array = Array.create 4 (GButton.radio_button ~label:"1" ~packing: hbox_radio #add () ~active:true) in let _ = btn_array.(0) #connect #clicked ~callback:(fun () -> set_channel 0) in let _ = begin for i = 1 to 3 do btn_array.(i) <- GButton.radio_button ~label:(string_of_int (i+1)) ~group: (btn_array.(0) #group) ~packing: hbox_radio #add () ; ignore(btn_array.(i) #connect #clicked ~callback:(fun () -> set_channel i)) done end in let frame_tf = GBin.frame ~label:"Domain" ~packing:hbox_tbar #add () in let hbox_tf = GPack.hbox ~packing:frame_tf #add () in let btn_t = GButton.radio_button ~label:"Time" ~packing: hbox_tf #add () ~active:true in let btn_f = GButton.radio_button ~label:"Frequency" ~group: (btn_t #group) ~packing: hbox_tf #add () in (* statusbar *) let _ = GMisc.statusbar ~packing:(vbox #pack ~expand:false) () in object(self) method window_toplevel_show = wtop #show () method on_quit () = GMain.Main.quit () method on_about () = let dialog = GWindow.about_dialog ~name:"react gtk demo" ~authors:["Philippe Strauss\nphilou@philou.ch"] ~license:"N/A" ~website:"http://www.philou.ch" ~version:"v0.0.1" () in ignore (dialog #connect #response ~callback:( fun _ -> try dialog #coerce #destroy () with Not_found -> ())) ; try ignore (dialog #run ()) with Not_found | Failure "dialog destroyed" -> () initializer ignore (wtop #connect #destroy ~callback:(self #on_quit)) ; ignore (menu_act_quit #connect #activate ~callback:(self #on_quit)) ; ignore (menu_h_about #connect #activate ~callback:(self #on_about)) ; ignore (btn_t #connect #clicked ~callback:(fun () -> set_domain Time)) ; ignore (btn_f #connect #clicked ~callback:(fun () -> set_domain Frequency)) ; end let () = let gui = new gui_t in gui #window_toplevel_show ; GMain.Main.main () -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org iQIcBAEBAgAGBQJNg4QwAAoJEL7LWSaUbNDidpkP/jc98xdgxSnpHxMBfpNgJuFb mO97OpPCK3xHwe/x65s81t5c/DHf3hIk2tzOSyIMFDg1wNvFWfK2blGJmat93/Zi Dllb8DVqvwloTObieDuT8GECS8+vu4pJGyFiNLPV12HIYbrE7sg9cGrq2PzQzhlz G4qNjeiOpPllkxMryRbW/7asGPG+JUeLuQ7Lf2UzZXq8APqpFa1Fhz55rjafarzO nfzl+vtulkNKbhaqom/z6dNhOYFp3L819eyex9H780Wqncz4rms2O/JVIGUVArdu C0m6ot9jrP5GahMufYVROa2Bcs8Nt8GkVrw0XsRnlsZqStkPrHhwuGATNFxpyUyy si/05ogYWza7X9pIh8gjoFsj0AYx8PN9NWDsghHigLPW7r8l6xo4w+e1UUMyyE1R 6QokM0yDsarmsR2XxVhvZa9A3KbsgEuyuGgFEjE34YFm0UDM3gz/EtLqYq9tjvF9 UrJ3JpSEe6cPAdOrhHTGXtOGLMnUysxl1MEatj4vITBGZOeKTz5MBm4Nd8bxBEA7 2xB309ccXZ81LeiJzzL4MThN93uFvK1fedTvIUsBjPnn/LqFYlegk5+p1ZkJXcwW /0hqXJUMGMr2VBMfxHCNwCWmhH0iKzN98a1iQ/47kshtRkdnEXinosdL6kjg3edz FLkJZdepQ9APAjaYQ0Jk =g0tc -----END PGP SIGNATURE----- _______________________________________________ Lablgtk-list mailing list Lablgtk-list@lists.forge.ocamlcore.org https://lists.ocamlcore.org/cgi-bin/listinfo/lablgtk-list