我是二郎的新手,我正试图绕过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.
答案 0 :(得分:1)
您是否收到编译错误?
将include_lib行更改为
-include_lib("wx/include/wx.hrl").
通过该更改,它会编译并在运行时得到一个空白窗口(我在Mac OS X上使用erl 5.7.2)。那是你的期望吗?
如果您是Erlang的新手,可能更容易从更简单的事情开始。理解wx_object手册页并不是很难,但只有在你掌握了OTP之后才能理解,并且在我的拙见中首先编写了几个测试服务器。一旦你在那一点上覆盖wx的工作方式就更简单了。同时做两件事将会更具挑战性,但你的里程可能会有所不同......!
答案 1 :(得分:0)
我意识到这是一个老问题,但我注意到了
-behaviour(wx_object)。
拼错了。 (你有行为(wx_object)。