動作例:
eSample130.erlを実行すると、command Test画面が表示される。
show Windowボタンを押下すると、Target Display画面が表示される。
Target Display画面上の文字列上のテキストを左クリックすると、「Left Click! ~」が画面上に表示される。
下記にソースを表示する。
ダウンロードは以下から。
eSample130.erl:
https://docs.google.com/leaf?id=0B8Fi1kuQJgFrNmE1Yjc3MTYtYjMxOS00NzQyLWI0OTItMWM5NzAyNzU3NWJl&hl=ja
eSample130_1.erl(更新前):
https://docs.google.com/leaf?id=0B8Fi1kuQJgFrYzM4MGE4ZGUtMTU2NS00NzkzLWI4YjYtZGUyMTdlZmM1NTlj&hl=ja
eSample130_1.erl(更新後):
https://docs.google.com/leaf?id=0B8Fi1kuQJgFrYjJkYWI5NDgtNzBkMS00ZWUyLWI0M2YtYzA3ZWYzZjRlNGYx&hl=ja
ソース:
-module(eSample130).
-export([start/0]).
-include_lib("wx.hrl").
-define(wxIDButton, 10).
start()->
Wx = wx:new(),
{Frame, Pid} = wx:batch(fun()->create_window(Wx) end),
wxWindow:show(Frame),
loop(Pid),
ok.
%% 画面を表示
create_window(Wx)->
Option = [ { size, {310, 150 } } ],
Str = "command Test.",
Frame = wxFrame:new(Wx,
?wxID_ANY,
Str,
Option),
% Set Button On Frame
%PnlOp = [ {pos, {120, 10}}, {size, {50, 10}}],
BtnOp = [ {label, "show Window"} ],
Panel = wxPanel:new(Frame, 120, 10, 50, 10),
Button = wxButton:new(Panel, ?wxIDButton, BtnOp),
% Create Status Bar
wxFrame:createStatusBar(Frame, []),
wxFrame:setStatusText(Frame, Str),
%% Dialog生成
Pid = spawn_link(fun() -> eSample130_1:start() end),
%% イベントを登録
wxFrame:connect( Frame, close_window ),%% Closeボタン
wxButton:connect(Button, command_button_clicked),%% show Windowボタン
{Frame, Pid}.
loop(Pid)->
receive
%% Closeボタン押下時
#wx{obj = Obj, event = #wxClose{}}->
io:format("~p Closing window ~n", [self()]),
wxWindow:destroy(Obj);
%% ボタン押下時
#wx{ event = #wxCommand{} } ->
Pid ! {visible, self()},
io:format(" Clicked Button ~n"),
loop(Pid);
%% Dialogからのメッセージがあった時
{reply, ok}->
loop(Pid)
end.
===============================//================================
-module(eSample130_1).
-export([start/0]).
%%-export([new/2]). %% API
-include_lib("wx.hrl").
start()->
Wx = wx:new(),
Dialog = wx:batch(fun()->new(Wx, 100) end),
loop(Dialog).
new(Parent,Id)->
Option = [ { size, {210, 100} } ],
Head = "Target Display",
Dialog = wxDialog:new(Parent, Id, Head, Option),
%OPP = [{size,{100,50}}],
%Panel = wxPanel:new(Parent,OPP),
Str = "Push close Button.",
OPST1 = [{pos, {50,10}}],
ST = wxStaticText:new( Dialog, 1 , Str, OPST1),
%ST = wxStaticText:new( Panel, 1 , Str, OPST1),
wxDialog:connect(Dialog, close_window),
%wxStaticText:connect(ST, left_down),
wxDialog:connect(Dialog, left_down),
wxDialog:connect(Dialog, left_up),
wxDialog:connect(Dialog, middle_down),
wxDialog:connect(Dialog, middle_up),
wxDialog:connect(Dialog, right_down),
wxDialog:connect(Dialog, right_up),
wxDialog:connect(Dialog, motion),
wxDialog:connect(Dialog, enter_window),
wxDialog:connect(Dialog, leave_window),
wxDialog:connect(Dialog, left_dclick),
wxDialog:connect(Dialog, middle_dclick),
wxDialog:connect(Dialog, right_dclick),
wxDialog:connect(Dialog, mousewheel),
wxDialog:connect(Dialog, nc_left_down),
wxDialog:connect(Dialog, nc_left_up),
wxDialog:connect(Dialog, nc_middle_down),
wxDialog:connect(Dialog, nc_middle_up),
wxDialog:connect(Dialog, nc_right_down),
wxDialog:connect(Dialog, nc_right_up),
wxDialog:connect(Dialog, nc_motion),
wxDialog:connect(Dialog, nc_enter_window),
wxDialog:connect(Dialog, nc_leave_window),
wxDialog:connect(Dialog, nc_left_dclick),
wxDialog:connect(Dialog, nc_middle_dclick),
wxDialog:connect(Dialog, nc_right_dclick),
Dialog.
%% 閉じるボタン押下時の動作
loop(Dialog)->
receive
%% closeボタン押下時
#wx{event = #wxClose{ type = close_window }}->
wxDialog:show(Dialog, [{show, false}]),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = left_down}}->
wxDialog:setLabel(Obj, "left_down!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = left_up}}->
wxDialog:setLabel(Obj, "left_up!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = middle_down}}->
wxDialog:setLabel(Obj, "middle_down!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = middle_up}}->
wxDialog:setLabel(Obj, "middle_up!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = right_down}}->
wxDialog:setLabel(Obj, "right_down!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = right_up}}->
wxDialog:setLabel(Obj, "right_up!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = motion}}->
wxDialog:setLabel(Obj, "motion!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = enter_window}}->
wxDialog:setLabel(Obj, "enter_window!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = leave_window}}->
wxDialog:setLabel(Obj, "leave_window!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = left_dclick}}->
wxDialog:setLabel(Obj, "left_dclick!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = middle_dclick}}->
wxDialog:setLabel(Obj, "middle_dclick!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = right_dclick}}->
wxDialog:setLabel(Obj, "right_dclick!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = mousewheel}}->
wxDialog:setLabel(Obj, "mousewheel!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_left_down}}->
wxDialog:setLabel(Obj, "nc_left_down!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_left_up}}->
wxDialog:setLabel(Obj, "nc_left_up!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_middle_down}}->
wxDialog:setLabel(Obj, "nc_middle_down!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_middle_up}}->
wxDialog:setLabel(Obj, "nc_middle_up!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_right_down}}->
wxDialog:setLabel(Obj, "nc_right_down!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_right_up}}->
wxDialog:setLabel(Obj, "nc_right_up!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_motion}}->
wxDialog:setLabel(Obj, "nc_motion!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_enter_window}}->
wxDialog:setLabel(Obj, "nc_enter_window!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_leave_window}}->
wxDialog:setLabel(Obj, "nc_leave_window!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_left_dclick}}->
wxDialog:setLabel(Obj, "nc_left_dclick!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_middle_dclick}}->
wxDialog:setLabel(Obj, "nc_middle_dclick!"),
loop(Dialog);
#wx{obj = Obj, event = #wxMouse{ type = nc_right_dclick}}->
wxDialog:setLabel(Obj, "nc_right_dclick!"),
loop(Dialog);
%% 他ウィンドウのボタンが押下された時
{visible, _From} ->
%% Dialogを表示する
wxDialog:show(Dialog, [{show, true}]),
_From ! {reply, ok},
loop(Dialog)
end.
0 件のコメント:
コメントを投稿