~statik/ubuntu/maverick/erlang/erlang-merge-testing

« back to all changes in this revision

Viewing changes to lib/gs/doc/src/examples/ex9.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-05-01 10:14:38 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090501101438-6qlr6rsdxgyzrg2z
Tags: 1:13.b-dfsg-2
* Cleaned up patches: removed unneeded patch which helped to support
  different SCTP library versions, made sure that changes for m68k
  architecture applied only when building on this architecture.
* Removed duplicated information from binary packages descriptions.
* Don't require libsctp-dev build-dependency on solaris-i386 architecture
  which allows to build Erlang on Nexenta (thanks to Tim Spriggs for
  the suggestion).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-module(ex9).
 
2
-copyright('Copyright (c) 1991-97 Ericsson Telecom AB').
 
3
-vsn('$Revision: /main/release/2 $ ').
 
4
 
 
5
-export([start/0,init/1]).
 
6
 
 
7
start() ->
 
8
    spawn(ex9, init, [self()]),
 
9
    receive
 
10
        {entry_reply, Reply} -> Reply
 
11
    end.
 
12
 
 
13
init(Pid) ->
 
14
    S = gs:start(),
 
15
    Win = gs:create(window,S,[{title,"Entry Demo"},
 
16
                              {width,150},{height,100}]),
 
17
    gs:create(label,Win,[{label,{text,"What's your name?"}},
 
18
                         {width,150}]),
 
19
    gs:create(entry,entry,Win,[{x,10},{y,30},{width,130},
 
20
                               {keypress,true}]),
 
21
    gs:create(button,ok,Win,[{width,45},{y,60},{x,10},
 
22
                             {label,{text,"Ok"}}]),
 
23
    gs:create(button,cancel,Win,[{width,60},{y,60},{x,80},
 
24
                                 {label,{text,"Cancel"}}]),
 
25
    gs:config(Win,{map,true}),
 
26
    loop(Pid).
 
27
 
 
28
loop(Pid) ->
 
29
    receive
 
30
        {gs,entry,keypress,_,['Return'|_]} ->
 
31
            Text=gs:read(entry,text),
 
32
            Pid ! {entry_reply,{name,Text}};
 
33
        {gs,entry,keypress,_,_} -> % all other keypresses
 
34
            loop(Pid);
 
35
        {gs,ok,click,_,_} ->
 
36
            Text=gs:read(entry,text),
 
37
            Pid ! {entry_reply,{name,Text}};
 
38
        {gs,cancel,click,_,_} ->
 
39
            Pid ! {entry_reply,cancel};
 
40
        X ->
 
41
            io:format("Got X=~w~n",[X]),
 
42
            loop(Pid)
 
43
    end.