O'Caml - gtk bindings



[ O'Caml page: http://pauillac.inria.fr/ocaml
  ML-family functional language with imperative features, parameterized
  modules and objects.
]

I've started a gtk-O'Caml binding system.
The basics of the system, including callbacks, work fine.

The current development is in
http://www.ens-lyon.fr/~dmonniau/arcs/mlgtk_0.05.tgz

I've got tons of problems with the lack of documentation of widgets,
especially signals. It is difficult, in particular, to deal with
widgets passing pointers as arguments to signal handlers.

IMHO, a prerequisite for efficient work on this topic is that widgets
should be documented. :-)  I don't ask for tons of text; a terse
description of functions, the type and name of their arguments and some
remarks about caveats and nonintuitive behaviours should be sufficient.

[in particular: move_resize seems to be called only once, when the window
is created, and with first two args pointers on integers -1; isn't it
supposed to be called on each resizing? and what is the use of its boolean
return value?]

regards, David

To give you some hopeful feeling:
####################### THIS CODE COMPILES AND WORKS:
(and makes a nice dialog box)

open ObjGtk;;

let window = window_new Gtk.WINDOW_TOPLEVEL in
( let vbox = vbox_new false 0 in
List.iter (function widget, z ->
  vbox #pack_start widget false false z;
  widget #show () )
  [ (label_new "Dialog box" :> widget), 0;

    (let hbox = hbox_new true 0 in
    List.iter (function widget, z ->
      hbox #pack_start widget false false z;
      widget #show () )
      [ (let vbox = vbox_new false 1 in
      List.iter
        (function title,tip ->
          let button = check_button_new_with_label title in
          button #set_tip tip;
          button #show();
          vbox #pack_start (button :> widget) true false 0;
          ) ["foo", "Let's dance.";
              "bar", "There's a lady who's sure of it.";
              "moo", "May the force be with you !";
              "cow", "Summertime and the living is easy..."];
      (vbox :> widget), 0); 

        (vseparator_new () :> widget), 5;

        (let vbox = vbox_new false 1 and
            titles, tips = List.split
            ["ZOINX", "Let's dance.";
              "bird", "There's a lady who's sure of it.";
              "wolf", "May the force be with you !";
              "rabbit", "Summertime and the living is easy..."] in
        let buttons = radio_buttons_new_with_labels titles
        in radio_buttons_set_index buttons 1;
        List.iter2
          (fun button tip ->
            button #show();
            button #set_tip tip;
            vbox #pack_start (button :> widget) true false 0
              ) buttons tips;
        (vbox :> widget), 0) ];
    (hbox :> widget), 5);

    (hseparator_new () :> widget), 5;

    (let lst = list_new() in
      let zozo = (List.map list_item_new_with_label
        ["Abc";"DEF";"ghi";"01234"]) in
       List.iter (fun x-> x#show()) zozo;
       lst #append_items zozo;
      (lst :> widget), 5);

    (hseparator_new () :> widget), 5;

    (let ratio = ref 0.5 and pbar = progress_bar_new () in
    pbar #show();
    pbar #update !ratio;
    Gtk.timeout_add 200 (fun _ ->
      ratio := !ratio +. 0.04;
      if !ratio > 1.0 then ratio := 0.0;
      pbar #update !ratio; true); 
    (pbar :> widget), 5);

    (hseparator_new () :> widget), 5;

    (let quitbox = hbox_new false 0 in
    ( let quit = button_new_with_label "Quit" in
    quit #connect_enter (fun ()-> Printf.fprintf stderr "enter quit\n";
      flush stderr);
    quit #connect_clicked Gtk.main_quit; (* WATCH FOR THE CALLBACKS *)
    quit #show();
    quitbox #pack_start (quit :> widget) true false 0
      );
    (quitbox :> widget), 0 )];

vbox #show();
window #add (vbox :> widget);
);
window #border_width 10;
window #set_title "Test of O'Caml-gtk";
window #connect_delete_event (fun _ -> Gtk.main_quit (); false);
window #connect_move_resize (fun w h ->
     Printf.fprintf stderr "move_resize %d %d\n" w h;
     flush stderr;
     true );
window #show ();;




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]