1999-12-16 04:25:11 -08:00
|
|
|
(*************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml LablTk library *)
|
|
|
|
(* *)
|
|
|
|
(* Jun Furuse, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* Jacques Garrigue, Kyoto University RIMS *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1999 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique and Kyoto University. All rights reserved. *)
|
|
|
|
(* This file is distributed under the terms of the GNU Library *)
|
|
|
|
(* General Public License. *)
|
|
|
|
(* *)
|
|
|
|
(*************************************************************************)
|
|
|
|
|
1999-12-17 01:59:13 -08:00
|
|
|
(* $Id$ *)
|
|
|
|
|
1999-11-30 06:59:39 -08:00
|
|
|
(* Some CamlTk4 Demonstration by JPF *)
|
|
|
|
|
|
|
|
(* First, open these modules for convenience *)
|
|
|
|
open Tk
|
|
|
|
|
|
|
|
(* Dummy let *)
|
|
|
|
let _ =
|
|
|
|
|
|
|
|
(* Initialize Tk *)
|
|
|
|
let top = openTk () in
|
|
|
|
(* Title setting *)
|
2000-04-14 02:46:08 -07:00
|
|
|
Wm.title_set top "LablTk demo";
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Base frame *)
|
|
|
|
let base = Frame.create top in
|
|
|
|
pack [base];
|
|
|
|
|
|
|
|
(* Menu bar *)
|
2000-04-12 02:53:09 -07:00
|
|
|
let bar = Frame.create base ~borderwidth: 2 ~relief: `Raised in
|
|
|
|
pack [bar] ~fill: `X;
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Menu and Menubutton *)
|
2000-04-12 02:53:09 -07:00
|
|
|
let meb = Menubutton.create bar ~text: "Menu" in
|
1999-11-30 06:59:39 -08:00
|
|
|
let men = Menu.create meb in
|
2000-04-12 02:53:09 -07:00
|
|
|
Menu.add_command men ~label: "Quit" ~command: (fun () -> closeTk (); exit 0);
|
|
|
|
Menubutton.configure meb ~menu: men;
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Frames *)
|
|
|
|
let base2 = Frame.create base in
|
|
|
|
let left = Frame.create base2 in
|
|
|
|
let right = Frame.create base2 in
|
|
|
|
pack [base2];
|
2000-04-12 02:53:09 -07:00
|
|
|
pack [left; right] ~side: `Left;
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Widgets on left and right *)
|
|
|
|
|
|
|
|
(* Button *)
|
2000-04-12 02:53:09 -07:00
|
|
|
let but = Button.create left ~text: "Welcome to LablTk" in
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Canvas *)
|
2000-04-12 02:53:09 -07:00
|
|
|
let can = Canvas.create left ~width: 100
|
|
|
|
~height: 100 ~borderwidth: 1 ~relief: `Sunken
|
1999-11-30 06:59:39 -08:00
|
|
|
in
|
2000-04-12 02:53:09 -07:00
|
|
|
Canvas.create_oval can ~x1: 10 ~y1: 10
|
|
|
|
~x2: 90 ~y2: 90
|
|
|
|
~fill:`Red;
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Check button *)
|
2000-04-12 02:53:09 -07:00
|
|
|
let che = Checkbutton.create left ~text: "Check" in
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Entry *)
|
2000-04-12 02:53:09 -07:00
|
|
|
let ent = Entry.create left ~width: 10 in
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Label *)
|
2000-04-12 02:53:09 -07:00
|
|
|
let lab = Label.create left ~text: "Welcome to LablTk" in
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Listbox *)
|
|
|
|
let lis = Listbox.create left in
|
2000-04-12 02:53:09 -07:00
|
|
|
Listbox.insert lis ~index: `End ~texts: ["This"; "is"; "Listbox"];
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Message *)
|
|
|
|
let mes = Message.create left
|
2000-04-12 02:53:09 -07:00
|
|
|
~text: "Hello this is a message widget with very long text, but ..." in
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Radio buttons *)
|
|
|
|
let tv = Textvariable.create () in
|
2000-04-03 00:57:36 -07:00
|
|
|
Textvariable.set tv "One";
|
1999-11-30 06:59:39 -08:00
|
|
|
let radf = Frame.create right in
|
|
|
|
let rads = List.map
|
2000-04-12 02:53:09 -07:00
|
|
|
~f:(fun t -> Radiobutton.create radf ~text: t ~value: t ~variable: tv)
|
1999-11-30 06:59:39 -08:00
|
|
|
["One"; "Two"; "Three"] in
|
|
|
|
|
|
|
|
(* Scale *)
|
2000-04-12 02:53:09 -07:00
|
|
|
let sca = Scale.create right ~label: "Scale" ~length: 100
|
|
|
|
~showvalue: true in
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Text and scrollbar *)
|
|
|
|
let texf = Frame.create right in
|
|
|
|
|
|
|
|
(* Text *)
|
2000-04-12 02:53:09 -07:00
|
|
|
let tex = Text.create texf ~width: 20 ~height: 8 in
|
|
|
|
Text.insert tex ~text: "This is a text widget." ~index: (`End,[])
|
|
|
|
~tags: [];
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Scrollbar *)
|
|
|
|
let scr = Scrollbar.create texf in
|
|
|
|
|
|
|
|
(* Text and Scrollbar widget link *)
|
|
|
|
let scroll_link sb tx =
|
2000-04-12 02:53:09 -07:00
|
|
|
Text.configure tx ~yscrollcommand: (Scrollbar.set sb);
|
|
|
|
Scrollbar.configure sb ~command: (Text.yview tx) in
|
1999-11-30 06:59:39 -08:00
|
|
|
scroll_link scr tex;
|
|
|
|
|
2000-04-12 02:53:09 -07:00
|
|
|
pack [scr] ~side: `Right ~fill: `Y;
|
|
|
|
pack [tex] ~side: `Left ~fill: `Both ~expand: true;
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Pack them *)
|
2000-04-12 02:53:09 -07:00
|
|
|
pack [meb] ~side: `Left;
|
1999-11-30 06:59:39 -08:00
|
|
|
pack [coe but; coe can; coe che; coe ent; coe lab; coe lis; coe mes];
|
|
|
|
pack [coe radf; coe sca; coe texf];
|
|
|
|
pack rads;
|
|
|
|
|
|
|
|
(* Toplevel *)
|
|
|
|
let top2 = Toplevel.create top in
|
2000-04-14 02:46:08 -07:00
|
|
|
Wm.title_set top2 "LablTk demo control";
|
1999-11-30 06:59:39 -08:00
|
|
|
let defcol = `Color "#dfdfdf" in
|
|
|
|
let selcol = `Color "#ffdfdf" in
|
|
|
|
let buttons =
|
2000-04-12 02:53:09 -07:00
|
|
|
List.map ~f:(fun (w, t, c, a) ->
|
|
|
|
let b = Button.create top2 ~text:t ~command:c in
|
|
|
|
bind b ~events: [`Enter] ~action:(fun _ -> a selcol);
|
|
|
|
bind b ~events: [`Leave] ~action:(fun _ -> a defcol);
|
1999-11-30 06:59:39 -08:00
|
|
|
b)
|
|
|
|
[coe bar, "Frame", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Frame.configure bar ~background);
|
1999-11-30 06:59:39 -08:00
|
|
|
coe meb, "Menubutton", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Menubutton.configure meb ~background);
|
1999-11-30 06:59:39 -08:00
|
|
|
coe but, "Button", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Button.configure but ~background);
|
1999-11-30 06:59:39 -08:00
|
|
|
coe can, "Canvas", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Canvas.configure can ~background);
|
1999-11-30 06:59:39 -08:00
|
|
|
coe che, "CheckButton", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Checkbutton.configure che ~background);
|
1999-11-30 06:59:39 -08:00
|
|
|
coe ent, "Entry", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Entry.configure ent ~background);
|
1999-11-30 06:59:39 -08:00
|
|
|
coe lab, "Label", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Label.configure lab ~background);
|
1999-11-30 06:59:39 -08:00
|
|
|
coe lis, "Listbox", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Listbox.configure lis ~background);
|
1999-11-30 06:59:39 -08:00
|
|
|
coe mes, "Message", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Message.configure mes ~background);
|
1999-11-30 06:59:39 -08:00
|
|
|
coe radf, "Radiobox", (fun () -> ()),
|
|
|
|
(fun background ->
|
2000-04-12 02:53:09 -07:00
|
|
|
List.iter rads ~f:(fun b -> Radiobutton.configure b ~background));
|
1999-11-30 06:59:39 -08:00
|
|
|
coe sca, "Scale", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Scale.configure sca ~background);
|
1999-11-30 06:59:39 -08:00
|
|
|
coe tex, "Text", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Text.configure tex ~background);
|
1999-11-30 06:59:39 -08:00
|
|
|
coe scr, "Scrollbar", (fun () -> ()),
|
2000-04-12 02:53:09 -07:00
|
|
|
(fun background -> Scrollbar.configure scr ~background)
|
1999-11-30 06:59:39 -08:00
|
|
|
]
|
|
|
|
in
|
2000-04-12 02:53:09 -07:00
|
|
|
pack buttons ~fill: `X;
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
(* Main Loop *)
|
|
|
|
Printexc.print mainLoop ()
|
|
|
|
|