2011年7月8日金曜日

wxErlang wxTreeCtlr Sample サンプル

ツリーのサンプル。

ソース:

-module(wxTreeCtrlTest).
-include_lib("wx.hrl").

-export([start/0]).

start()->
    Wx = wx:new(),
    Frame = wx:batch(fun() -> create_window(Wx) end),
    wxWindow:show(Frame),
    loop(Frame),
    wx:destroy(),
    ok.

create_window(Wx)->  
    %% Create Frame
    Frame = wxFrame:new(Wx,
 -1,
 "TreeCtrl Example",
 %%[{size,{300,200}}]),
 [{size,{-1,-1}}]),

    %% Create Panel
    %%Panel1 = wxPanel:new(Frame),
    Panel = wxPanel:new(Frame, []),

    %% Setup sizers
    MainSizer = wxBoxSizer:new(?wxVERTICAL),
    Sizer = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
[{label, "wxTreeCtrl"}]),

    %% Setup treeCtrl
    TreeCtrl = wxTreeCtrl:new(Panel, []),
    RootId = wxTreeCtrl:addRoot(TreeCtrl, "Root"),
    %% Name the first items
    Items = ["item "++integer_to_list(Int)||
Int <- lists:seq(1,10)],
    %% Create the first items in the treeCtrl
    SubItems = [{wxTreeCtrl:appendItem(TreeCtrl, RootId, Item), Item}||
  Item <- Items],
    %% Create sub items
    [wxTreeCtrl:appendItem(TreeCtrl, ItemId, Item++" sub item "++integer_to_list(Int))||
{ItemId, Item} <- SubItems, Int <- lists:seq(1,10)],
    wxTreeCtrl:expand(TreeCtrl, RootId),

    %% Add to sizers
    Options = [{flag, ?wxEXPAND}, {proportion, 1}],
    wxSizer:add(Sizer, TreeCtrl, Options),
    wxSizer:add(MainSizer, Sizer, Options),

    wxTreeCtrl:connect(TreeCtrl, command_tree_item_collapsed),
    wxTreeCtrl:connect(TreeCtrl, command_tree_item_expanded),
    wxTreeCtrl:connect(TreeCtrl, command_tree_sel_changed),
    wxPanel:setSizer(Panel, MainSizer),
        %% Set Connect Close
    wxFrame:connect(Frame, close_window),

    Frame.

loop(Frame) ->
    receive
% Window Close Event
#wx{event=#wxClose{}} ->
   io:format("~p Closing window ~n",[self()]),
   wxWindow:destroy(Frame),
   ok
    end.

0 件のコメント:

コメントを投稿