我对erlang非常陌生,正在尝试了解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 05:51:55
你得到一个编译错误吗?
将include_lib行更改为
-include_lib("wx/include/wx.hrl").有了这样的更改,它就会进行编译,并且在运行时会得到一个空白窗口(我在Mac上使用的是erl 5.7.2 )。这是你想要的吗?
如果您是Erlang的新手,那么从更简单的东西开始可能更容易。理解wx_object手册页并不是很难,但只有在您掌握了动态口令并首先编写了几个测试服务器之后,我才会这么认为。在这一点上,覆盖wx是如何工作的是一个更简单的步骤。同时做这两件事将是一个更大的挑战,但您的里程当然可能会有所不同…!
发布于 2010-05-13 08:03:26
我知道这是个老问题,但我注意到
-behaviour(wx_object)。
拼写错误。(你有行为(Wx_object)。
https://stackoverflow.com/questions/1365208
复制相似问题