Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] lablgtk newbie question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] lablgtk newbie question
Thanks everyone. I'm now using:

ocaml -w s -I +lablgtk lablgtk.cma gtkInit.cmo editor.ml

I notice that I can't put

#!/usr/bin/ocaml -w s -I +lablgtk lablgtk.cma gtkInit.cmo

at the beginning of my program. It complains of:

Couldnt get a file descriptor referring to the console
Could not get a file descriptor referring to the console
Couldnt get a file descriptor referring to the console
Could not get a file descriptor referring to the console
Couldnt get a file descriptor referring to the console
Could not get a file descriptor referring to the console
./editor.ml: line 8: let: =: syntax error: operand expected (error token is "=")
./editor.ml: line 9: syntax error near unexpected token `"Unimplemented: "'
./editor.ml: line 9: `  prerr_endline ("Unimplemented: " ^ msg);;'

Strange, but not a show-stopper.

I've also rewritten the program and worked out what the problem was
with ;; and ;. I'm assuming that ';' on its own is just a sequence
point, kind of like the monad stuff in Haskell (?)

And I'm using let ... in  as a short-hand for a local variable (except,
of course, I'm aware that it's not _really_ "variable").

My program looks like this now. Comments on style are welcome.

Rich.

open GMain
open GWindow
open GdkKeysyms

let unimplemented msg =
  prerr_endline ("Unimplemented: " ^ msg);;

let menu_new_blank_page () =
  unimplemented "New blank page function selected";;

let menu_search () =
  unimplemented "Search function selected";;

let menu_cut () =
  unimplemented "Cut function selected";;

let menu_copy () =
  unimplemented "Copy function selected";;

let menu_paste () =
  unimplemented "Paste function selected";;

let main () =
  (* Main window *)
  let window = GWindow.window ~width:500 ~height:300 ~title:"Editor" () in
  let vbox = GPack.vbox ~packing:window#add () in
  window#connect#destroy ~callback: Main.quit;

  (* Menu bar *)
  let menubar = GMenu.menu_bar ~packing:vbox#pack () in
  let factory = new GMenu.factory menubar in
  let accel_group = factory#accel_group in
  let pages_menu = factory#add_submenu "Pages" in
  let edit_menu = factory#add_submenu "Edit" in

  (* Pages menu *)
  let factory = new GMenu.factory pages_menu ~accel_group in
  factory#add_item "New blank page" ~key:_N ~callback: menu_new_blank_page;
  factory#add_item "Search ..." ~key:_S ~callback: menu_search;

  (* Edit menu *)
  let factory = new GMenu.factory edit_menu ~accel_group in
  factory#add_item "Cut" ~key:_X ~callback: menu_cut;
  factory#add_item "Copy" ~key:_C ~callback: menu_copy;
  factory#add_item "Paste" ~key:_V ~callback: menu_paste;

  (* Display the windows and enter Gtk+ main loop *)
  window#show ();
  Main.main ();;

(* Run the main program *)
main ();;


-- 
Richard Jones, Red Hat Inc. (London) and Merjis Ltd. http://www.merjis.com/
http://www.annexia.org/ Freshmeat projects: http://freshmeat.net/users/rwmj
MONOLITH is an advanced framework for writing web applications in C, easier
than using Perl & Java, much faster and smaller, reusable widget-based arch,
database-backed, discussion, chat, calendaring:
http://www.annexia.org/freeware/monolith/

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners