Advertisement
Guest User

Code lablgtk image

a guest
Dec 8th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 2.07 KB | None | 0 0
  1. (* Initialisation de GTK *)
  2. let _ = GMain.init ()
  3.  
  4. exception IsNone
  5.  
  6. type 'a option =
  7.   | None      
  8.   | Some of 'a
  9.  
  10. (* Fenêtre principale de l'application. *)
  11. let window = GWindow.window
  12.   ~title:"Project"
  13.   ~height:700
  14.   ~width:1000 ()
  15.  
  16. (* Pack principal qui contient tous les widget *)
  17. let vboxall = GPack.vbox
  18.   ~packing:window#add ()
  19.  
  20. (* Pack dans lequel il y a la toolbar *)
  21.  
  22. let box = GPack.vbox
  23.     ~packing:vboxall#add ()
  24.  
  25. let toolbar = GButton.toolbar  
  26.   ~orientation:`HORIZONTAL  
  27.   ~style:`ICONS
  28.   ~packing:(box#pack ~expand:false) ()
  29.  
  30. let item = GButton.tool_item ~packing:toolbar#insert ()
  31.  
  32. (* Pack du milieu *)
  33. let mil = GPack.hbox
  34.   ~packing:vboxall#add ()
  35.  
  36. (* Pack de gauche *)
  37. let vbox = GPack.vbox
  38.     ~height: 600
  39.   ~packing:mil#add ()
  40.  
  41. let separator = GMisc.separator `HORIZONTAL
  42.     ~packing:(vbox#pack ~expand:false) ()
  43.  
  44. (* Boutons *)
  45. let say_hello = GButton.button
  46.   ~label:"Bonjour !"
  47.     ~packing:(vbox#pack ~expand:false) ()
  48.  
  49. (* Bouton pour up l'img *)
  50.  
  51. let affiche btn =
  52.     match btn with
  53.         |Some n -> ignore (GMisc.image
  54.         ~file: n
  55.         ~packing:(vbox#pack ~expand:false) ())
  56.         | _ -> raise IsNone
  57.  
  58. let button =
  59.   let btn = GFile.chooser_button
  60.         ~title:"Browse"
  61.     ~action:`OPEN
  62.     ~packing:(item#add) () in
  63.   btn#connect#selection_changed (affiche btn#filename);
  64.   btn
  65.  
  66. let button = GFile.chooser_button
  67.   ~title:"Browse"
  68.   ~action:`OPEN
  69.   ~packing:item#add ()
  70.  
  71.     let display = Gaux.may ~f:image#set_file
  72.  
  73.  
  74. (* Pack de droite *)
  75.  
  76. let vbox2 = GPack.vbox
  77.   ~spacing:10
  78.   ~border_width:10
  79.   ~packing:mil#add ()
  80.  
  81. let p2 = GButton.button
  82.   ~label:"Bonjour !"
  83.     ~packing:(vbox2#pack ~expand:false) ()
  84.  
  85. (* Fonctions tests *)
  86. let print_hello () =
  87.   let user = Glib.get_user_name () in
  88.   Printf.printf "Bonjour %s !\n%!" (String.capitalize user)
  89.  
  90. let _ =
  91.   window#connect#destroy ~callback:GMain.quit;
  92.   say_hello#connect#clicked ~callback:print_hello;
  93.   button#connect#selection_changed (fun () -> display button#filename);
  94.   p2#connect#clicked ~callback:print_hello;
  95.  
  96.  
  97.   window#show ();
  98.   GMain.main ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement