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