~ubuntu-branches/debian/squeeze/erlang/squeeze

« back to all changes in this revision

Viewing changes to lib/wx/examples/simple/hello2.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-05-07 15:07:37 UTC
  • mfrom: (1.2.1 upstream) (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090507150737-i4yb5elwinm7r0hc
Tags: 1:13.b-dfsg1-1
* Removed another bunch of non-free RFCs from original tarball
  (closes: #527053).
* Fixed build-dependencies list by adding missing comma. This requires
  libsctp-dev again. Also, added libsctp1 dependency to erlang-base and
  erlang-base-hipe packages because the shared library is loaded via
  dlopen now and cannot be added using dh_slibdeps (closes: #526682).
* Weakened dependency of erlang-webtool on erlang-observer to recommends
  to avoid circular dependencies (closes: #526627).
* Added solaris-i386 to HiPE enabled architectures.
* Made script sources in /usr/lib/erlang/erts-*/bin directory executable,
  which is more convenient if a user wants to create a target Erlang system.
* Shortened extended description line for erlang-dev package to make it
  fit 80x25 terminals.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%
 
2
%% %CopyrightBegin%
 
3
%% 
 
4
%% Copyright Ericsson AB 2009. All Rights Reserved.
 
5
%% 
 
6
%% The contents of this file are subject to the Erlang Public License,
 
7
%% Version 1.1, (the "License"); you may not use this file except in
 
8
%% compliance with the License. You should have received a copy of the
 
9
%% Erlang Public License along with this software. If not, it can be
 
10
%% retrieved online at http://www.erlang.org/.
 
11
%% 
 
12
%% Software distributed under the License is distributed on an "AS IS"
 
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
%% the License for the specific language governing rights and limitations
 
15
%% under the License.
 
16
%% 
 
17
%% %CopyrightEnd%
 
18
%%
 
19
%%%-------------------------------------------------------------------
 
20
%%% File    : hello.erl
 
21
%%% Author  : Matthew Harrison <harryhuk at users.sourceforge.net>
 
22
%%% Description : _really_ minimal example of a wxerlang app
 
23
%%%               implemented with wx_object behaviour
 
24
%%%
 
25
%%% Created :  18 Sep 2008 by  Matthew Harrison <harryhuk at users.sourceforge.net>
 
26
%%%            Dan rewrote it to show wx_object behaviour
 
27
%%%-------------------------------------------------------------------
 
28
-module(hello2).
 
29
-include_lib("wx/include/wx.hrl").
 
30
 
 
31
-export([start/0]).
 
32
-compile(export_all).
 
33
 
 
34
-behavoiur(wx_object).
 
35
 
 
36
-record(state, {win}).
 
37
 
 
38
start() ->
 
39
    wx_object:start_link(?MODULE, [], []).
 
40
 
 
41
%% Init is called in the new process.
 
42
init([]) ->
 
43
    wx:new(),
 
44
    Frame = wxFrame:new(wx:null(), 
 
45
                        -1, % window id
 
46
                        "Hello World", % window title
 
47
                        [{size, {600,400}}]),
 
48
    
 
49
    wxFrame:createStatusBar(Frame,[]),
 
50
 
 
51
    %% if we don't handle this ourselves, wxwidgets will close the window
 
52
    %% when the user clicks the frame's close button, but the event loop still runs
 
53
    wxFrame:connect(Frame, close_window),
 
54
    
 
55
    ok = wxFrame:setStatusText(Frame, "Hello World!",[]),
 
56
    wxWindow:show(Frame),
 
57
    {Frame, #state{win=Frame}}.
 
58
 
 
59
 
 
60
%% Handled as in normal gen_server callbacks
 
61
handle_info(Msg, State) ->
 
62
    io:format("Got Info ~p~n",[Msg]),
 
63
    {noreply,State}.
 
64
 
 
65
handle_call(Msg, _From, State) ->
 
66
    io:format("Got Call ~p~n",[Msg]),
 
67
    {reply,ok,State}.
 
68
 
 
69
%% Async Events are handled in handle_event as in handle_info
 
70
handle_event(#wx{event=#wxClose{}}, State = #state{win=Frame}) ->
 
71
    io:format("~p Closing window ~n",[self()]),
 
72
    ok = wxFrame:setStatusText(Frame, "Closing...",[]),
 
73
    wxWindow:destroy(Frame),
 
74
    {stop, normal, State}.
 
75
 
 
76
code_change(_, _, State) ->
 
77
    {stop, not_yet_implemented, State}.
 
78
 
 
79
terminate(_Reason, _State) ->
 
80
    ok.
 
81