wxerlang workups

Optional: use wxFormBuilder

An Optional Tool 

Here's something to look into, if you feel comfortable with C++.  There is a free program called wxFormBuilder (available for both Windows and Linux) at http://wxformbuilder.org/ .   You can use it to design the layout of your window.  It will allow you to place widgets  in the window exactly where you want them and automatically generate C++ code for you.  The trick is converting the C++ code into wxErlang equivalents.  It is possible to convert almost C++ code into Erlang.  

Hint 1: First thing, figure out which Erlang function should be used .  For example, does C++ 'new'  turn into Erlang new/1, new/2, etc.

Hint 2:  Many Erlang functions use import to simulate C++ 'inheritance'.  Look at the beginning of the module documentation for information about 'inherited'  functions.  If you can't find a function listed directly for a wx module, look up the tree, so to speak, to a branch closer to the root. 

For comparison, I am posting the code which was generated automatically by wxFormBuilder to create a window which looks nearly identical to the one which is hand-written in this tutorial.  (I set the ID numbers and variable names when designing it, so they would correspond to the tutorial version).  

I added equivalent Erlang code below the C++ code.   The Erlang code lines start with //.  There is a one-to-one match for most lines.

For example:

If the C++ code generated by wxFormBuilder looks like this:  

     OuterSizer = new wxBoxSizer( wxHORIZONTAL );

Then the Erlang code which you would write, would look like this:
 
    //  OuterSizer = wxBoxSizer:new(?wxHORIZONTAL)
 

 

///////////////////////////////////////////////////////////////////////////

// C++ code generated with wxFormBuilder (version Apr 16 2008)
// http://www.wxformbuilder.org/
// WITH SOME ERLANG EQUIVALENTS FOLLOWING 
#include "noname.h"
///////////////////////////////////////////////////////////////////////////
 
Frame::Frame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
//    wxFrame:SetSizeHints/3
//    wxFrame:setSizeHints(Frame, ?wxDefaultSize, ?wxDefaultSize)
 
wxBoxSizer* OuterSizer;
OuterSizer = new wxBoxSizer( wxHORIZONTAL );
//  wxBoxSizer:new/1
//  OuterSizer = wxBoxSizer:new(?wxHORIZONTAL)
 
 
Panel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
//  wxPanel:new/2
//  Panel = wxPanel:new(Frame, [{winid, ?wxID_ANY}, {pos, ?wxDefaultPosition}, {size, ?wxDefaultSize}, {style, ?wxTAB_TRAVERSAL}])
 
wxBoxSizer* MainSizer;
MainSizer = new wxBoxSizer( wxVERTICAL );
//  MainSizer = wxBoxSizer:new(?wxVERTICAL)
 
 
wxStaticBoxSizer* InputSizer;
InputSizer = new wxStaticBoxSizer( new wxStaticBox( Panel, wxID_ANY, wxT("Enter an integer") ), wxHORIZONTAL );
 
//  wxStaticBoxSizer:new/2
//     new(Box::wxStaticBox:wxStaticBox(), Orient::integer())
//  and inside, using wxStaticBox/3
// InputSizer = wxStaticBoxSizer:new(wxStaticBox:new( Panel,
//                                                    ?wxID_ANY,
//                                                    "Enter an integer") ,
//                                    ?wxHORIZONTAL );
 
T1001 = new wxTextCtrl( Panel, 1001, wxT("10"), wxDefaultPosition, wxDefaultSize, 0 );
//  T1001 = wxTextCtrl(Panel, 1001, [{value, "10"},
//                                   {pos, ?wxDefaultPosition},
//                                   {size, ?wxDefaultSize},
//                                   {style, 0} ])
 
InputSizer->Add( T1001, 0, wxALIGN_CENTER_VERTICAL, 5 );
    wxStaticBoxSizer:add/3
//  wxStaticBoxSizer:add(InputSizer, T1001, [{proportion,0},
//                                           {flag,?wxALIGN_CENTER_VERTICAL},
//                                           {border, 5} ])
 
 
MainSizer->Add( InputSizer, 1, wxEXPAND, 5 );
//  wxBoxSizer:add/3
//  wxBoxSizer:add(MainSizer,InputSizer, [{proportion,1},
//                                        {flag,?wxEXPAND},
//                                        {border, 5} ])
 
 
ST2001 = new wxStaticText( Panel, 2001, wxT("Output Area"), wxPoint( -1,-1 ), wxDefaultSize, 0 );
//  wxStaticText:new/4
//  ST2001 = wxStaticText:new(Panel, 2001, "Output Area",
//                [{pos, {-1,-1},
//                 {size,?wxDefaultSize},
//                 {style, 0 }],
 
ST2001->Wrap( -1 );
//    wxStaticText:wrap(ST2001, -1)
 
ST2001->SetFont( wxFont( 15, 70, 90, 90, false, wxEmptyString ) );
//  inheriting wxWindow:SetFont/2
//  wxFont:new/5 (Size::integer(), Family::WxFontFamily, Style::WxFontStyle, Weight::integer(), Options::[Option])
//  wxStaticText:SetFont(ST2001, wxFont(
                            15, %size
                            70, %family
                            90, %style
                            90, %weight
                            [{ underlined , false}, {face ,?wxEmptyString}]
 
 
MainSizer->Add( ST2001, 0, wxALL, 5 );
//  see above
 
wxBoxSizer* ButtonSizer;
ButtonSizer = new wxBoxSizer( wxHORIZONTAL );
//  wxBoxSizer:new(ButtonSizer, ?wxHORIZONTAL)
 
 
B101 = new wxButton( Panel, 101, wxT("&Countdown"), wxDefaultPosition, wxDefaultSize, 0 );
//  B101 = wxButton:new(Panel, 101, "&Countdown",
//                 [{pos, ?wxDefaultPosition},
//                  {size, ?wxDefaultSize},
//                  {style, 0}]
B101->SetDefault();
//  wxButton:setDefault(B101)
 
ButtonSizer->Add( B101, 0, wxALIGN_BOTTOM|wxALL, 5 );
//  wxBoxSider:add(ButtonSizer, B101,
//                [{proportion, 0},
//                 {flags, {?wxALIGHT_BOTTOM bor?wxALL},
//                 {border, 5}]
 
B102 = new wxButton( Panel, ?wxID_EXIT, wxT("E&xit"), wxDefaultPosition, wxDefaultSize, 0 );
//  B102 = wxButton:new(Panel, ?wxID_EXIT, "E&xit",
//                 [{pos, ?wxDefaultPosition},
//                  {size, ?wxDefaultSize},
//                  {style, 0}]
 
ButtonSizer->Add( B102, 0, wxEXPAND|wxTOP|wxBOTTOM|wxRIGHT, 5 );
//see above
 
MainSizer->Add( ButtonSizer, 0, 0, 5 );
 
Panel->SetSizer( MainSizer );
Panel->Layout();
MainSizer->Fit( Panel );
OuterSizer->Add( Panel, 1, wxEXPAND | wxALL, 0 );
 
this->SetSizer( OuterSizer );
//    wxFrame:SetSizer(Frame, OuterSizer)
this->Layout();
//  wxFrame:Layout(Frame)
 
// Connect Events
B101->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( Frame::countdown() ), NULL, this );
B102->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( Frame::exit() ), NULL, this );
}
 
Frame::~Frame()
{
// Disconnect Events
B101->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( Frame::countdown() ), NULL, this );
B102->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( Frame::exit() ), NULL, this );
}

Main Menu

Login Form