~ubuntu-branches/ubuntu/hardy/ocaml-doc/hardy

« back to all changes in this revision

Viewing changes to examples/camltk/convertion_euro.ml

  • Committer: Bazaar Package Importer
  • Author(s): Samuel Mimram
  • Date: 2007-09-08 01:49:22 UTC
  • mfrom: (0.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070908014922-lvihyehz0ndq7suu
Tags: 3.10-1
* New upstream release.
* Removed camlp4 documentation since it is not up-to-date.
* Updated to standards version 3.7.2, no changes needed.
* Updated my email address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
(***********************************************************************)
2
 
(*                                                                     *)
3
 
(*                           Objective Caml                            *)
4
 
(*                                                                     *)
5
 
(*               Pierre Weis, projet Cristal, INRIA Rocquencourt       *)
6
 
(*                                                                     *)
7
 
(*  Copyright 2001 Institut National de Recherche en Informatique et   *)
8
 
(*  en Automatique.  All rights reserved.  This file is distributed    *)
9
 
(*  under the terms of the Q Public License version 1.0.               *)
10
 
(*                                                                     *)
11
 
(***********************************************************************)
12
 
 
13
 
open Camltk;;
14
 
 
15
 
let synchronise_zones source dest taux_source taux_dest =
16
 
  function infos ->
17
 
    try
18
 
      let montant_source = float_of_string (Entry.get source) in
19
 
      let montant_dest =
20
 
        montant_source *. !taux_source /. !taux_dest in
21
 
      Entry.delete_range dest (At 0) End;
22
 
      Entry.insert dest (At 0)
23
 
                         (Printf.sprintf "%.2f" montant_dest)
24
 
    with Failure _ ->
25
 
      Entry.delete_range dest (At 0) End;
26
 
      Entry.insert dest (At 0) "erreur";;
27
 
 
28
 
let convertion_en_francs () =
29
 
  let fp = openTk () in
30
 
 
31
 
  let ligne1 = Frame.create fp []
32
 
  and ligne2 = Frame.create fp [] in
33
 
 
34
 
  let �tiq1 = Label.create ligne1 [Text "Francs:"]
35
 
  and entr�e1 = Entry.create ligne1 [TextWidth 10; Relief Sunken]
36
 
 
37
 
  and �tiq2 = Label.create ligne2 [Text "Euros:"]
38
 
  and entr�e2 = Entry.create ligne2 [TextWidth 10; Relief Sunken] in
39
 
 
40
 
  let quit = Button.create fp [Text "Quit"; Command closeTk] in
41
 
 
42
 
  let taux1 = ref 1.0     (* francs pour 1 franc *)
43
 
  and taux2 = ref 6.55957 (* francs pour 1 euro *) in
44
 
 
45
 
  bind entr�e1 [[], KeyRelease]
46
 
       (BindSet([], synchronise_zones entr�e1 entr�e2 taux1 taux2));
47
 
  bind entr�e2 [[], KeyRelease]
48
 
       (BindSet([], synchronise_zones entr�e2 entr�e1 taux2 taux1));
49
 
 
50
 
  pack [�tiq1] [Side Side_Left]; pack [entr�e1] [Side Side_Right];
51
 
  pack [�tiq2] [Side Side_Left]; pack [entr�e2] [Side Side_Right];
52
 
  pack [ligne1; ligne2] [Side Side_Top; Fill Fill_X];
53
 
  pack [quit] [Side Side_Bottom; Fill Fill_X]; 
54
 
  mainLoop ();;
55
 
 
56
 
if !Sys.interactive then () else begin convertion_en_francs (); exit 0 end;;