-- Temperature.sa: TkKit example: a temperature converter
-- edit one entry and hit return to get the corresponding temperature
-- Author: Matthias Ernst <mernst@desy.de>
-------------------------------------------------------------------
class TEMPERATURE is
   attr celsius, fahrenheit: TK_ENTRY;

   c2f is
      c ::= #FLT(celsius.get);
      fahrenheit.set((c*1.8 + 32.0).str);
   end;

   f2c is
      f ::= #FLT(fahrenheit.get);
      celsius.set(((f-32.0)/1.8).str);
   end;

   main is
      app ::= #TK_APP("temperature", "Temperature", "/home/x4u/mernst/sources/sather/TkKit/library/");

      caption ::= #TK_LABEL("caption", app.root).relief_raised;
      caption.text := "Temperature converter";

      f ::= #TK_FRAME("f", app.root).relief_raised;

      f1 ::= #TK_FRAME("f1", f).configure("bd", 2).relief_ridge;

      cl ::= #TK_BUTTON("cl", f1);
      cl.text := "Celsius degree: ";
      cl.pack_info := "-side left";

      celsius := #TK_ENTRY("ce", f1).relief_sunken;
      celsius.pack_info := "-side left";

      f2 ::= #TK_FRAME("f2", f).configure("bd", 2).relief_ridge;

      fl ::= #TK_BUTTON("fl", f2);
      fl.text := "Fahrenheit degree: ";
      fl.pack_info := "-side left";

      fahrenheit := #TK_ENTRY("fe", f2).relief_sunken;
      fahrenheit.pack_info := "-side left";

      f2c_cb ::= #TKKIT_CB("f2c", #ROUT(f2c));
      c2f_cb ::= #TKKIT_CB("c2f", #ROUT(c2f));

      cl.callback := c2f_cb;
      celsius.bind("<Return>", c2f_cb, void); -- no args

      fl.callback := f2c_cb;
      fahrenheit.bind("<Return>", f2c_cb, void);

      app.root.show_all;
      app.tcl_tk.main_loop;
   end;
end; -- class TEMPERATURE

-------------------------------------------------------------------
