我對erlang非常陌生,並且試圖讓我的腦袋圍繞wxerlang,但是碰到了牆壁。有人可以看看這段代碼,告訴我什麼是錯的。我認爲這是非常明顯的,但我無法解決。wxErlang - 這段代碼有什麼問題?
-module(main).
-include_lib("include/wx.hrl").
-behavoiur(wx_object).
-export([start/0]). %% API
-export([init/1, handle_call/3, handle_event/2, handle_info/2, terminate/2]). %% Call Backs
-record(state, {win, action}).
-define(NEW_APP, 101).
start() ->
wx_object:start(?MODULE, [], []).
init(Options) ->
wx:new(Options),
Frame = wxFrame:new(wx:null(), ?wxID_ANY, "Rails IDE", [{size,{1000,500}}]),
MB = wxMenuBar:new(),
wxFrame:setMenuBar(Frame,MB),
File = wxMenu:new([]),
wxMenu:append(File, ?NEW_APP, "&New"),
wxMenu:append(File, ?wxID_EXIT, "&Quit"),
wxMenuBar:append(MB, File, "&File"),
wxFrame:connect(Frame, command_menu_selected),
_SB = wxFrame:createStatusBar(Frame,[]),
MainSplitter = wxSplitterWindow:new(Frame, []),
LeftSplitter = wxSplitterWindow:new(MainSplitter, []),
CenterSplitter = wxSplitterWindow:new(MainSplitter, []),
RightSplitter = wxSplitterWindow:new(MainSplitter, []),
BottomSplitter = wxSplitterWindow:new(MainSplitter, []),
wxSplitterWindow:setMinimumPaneSize(MainSplitter, 1),
wxSplitterWindow:setMinimumPaneSize(LeftSplitter, 1),
wxSplitterWindow:setMinimumPaneSize(CenterSplitter, 1),
wxSplitterWindow:setMinimumPaneSize(RightSplitter, 1),
wxSplitterWindow:setMinimumPaneSize(BottomSplitter, 1),
wxFrame:show(Frame),
State = #state{win=Frame},
{Frame, State}.
handle_info(Msg, State) ->
io:format("Got Info ~p~n",[Msg]),
{noreply,State}.
handle_call(Msg, _From, State) ->
io:format("Got Call ~p~n",[Msg]),
{reply,ok,State}.
handle_event(#wx{id = Id,
event = #wxCommand{type = command_menu_selected}},
State = #state{}) ->
case Id of
?NEW_APP ->
Panel = newAppDialog(State#state.win),
{noreply, State#state{action=Panel}};
?wxID_EXIT ->
{stop, normal, State};
_ ->
{noreply, State}
end;
handle_event(Ev,State) ->
io:format("~p Got event ~p ~n",[?MODULE, Ev]),
{noreply, State}.
terminate(_Reason, _State) ->
wx:destroy().
newAppDialog(Frame) ->
Panel = wxPanel:new(Frame, []),
%% Setup sizers
MainSizer = wxBoxSizer:new(?wxVERTICAL),
SubSizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel, [{label, "Create a new Rails app."}]),
Label1 = wxStaticText:new(Panel, 1, "App root"),
DirPicker = wxDirPickerCtrl:new(Panel, 2,
[{path, "/"},
{style, ?wxDIRP_USE_TEXTCTRL},
{message, "Select app root"}]),
Label2 = wxStaticText:new(Panel, 3, "App name"),
TextCtrl = wxTextCtrl:new(Panel, 4),
Button = wxButton:new(Panel, ?wxID_OK),
%% Add to sizers
PickerOptions = [{border, 4},{flag, ?wxALL bor ?wxEXPAND}],
wxSizer:add(SubSizer, Label1, PickerOptions),
wxSizer:add(SubSizer, DirPicker, PickerOptions),
wxSizer:add(SubSizer, Label2, PickerOptions),
wxSizer:add(SubSizer, TextCtrl, PickerOptions),
wxSizer:add(SubSizer, Button, PickerOptions),
SizerOptions = [{flag, ?wxEXPAND}],
wxSizer:add(MainSizer, SubSizer, SizerOptions),
wxWindow:connect(Panel, command_button_clicked),
wxPanel:setSizer(Panel, MainSizer),
wxSizer:layout(MainSizer),
Panel.
這可能有助於你得到實際的錯誤 – 2009-09-02 01:08:36
你也可以嘗試將代碼縮減爲一個較小的例子,它表現出同樣的問題除了使其他人更容易回答你,這是一個很好的調試自己的技巧;一旦你消除了一切無關,其餘代碼中的問題可能會變得更加明顯 – 2009-09-02 01:30:42
我的問題在於handle_event/3的情況NEW_APP newAppDialog運行爲一個新的進程並退出,但沒有任何顯示在框架中,主進程仍在運行,但將退回到命令行。 我很困惑,也許我已經跳到遠處,並將採取在OTP的東西 – Damian 2009-09-02 08:21:44