wxErlang Mats-Ola Persson wxErlang • GUI library for Erlang • write GUI applications • cross platform • cross platform look and feel Example • • • A “stupid” tic-tac-toe application No intelligent behavior is implemented Just the (good) looks Creating a window create_window() -> wx:start(), % initialize wxErlang % create a frame (window) with no parent Frame = wx:frame(?NULL, ?wxID_ANY, “Hello World!”), wx:show(Frame). % make the frame visible Creating a window • Not very exciting: an empty window Event-driven programming • Things “react” to mouse clicks, mouse movements, etc. • Event-handlers, callback functions Events create_window() -> wx:start(), Frame = wx:frame(?NULL, ?wxID_ANY, “Hello World!”), % event-handler that reacts to close clicks wx:connect(Frame, ?wxEVT_CLOSE_WINDOW, fun(_,_) -> wx:quit() end), wx:show(Frame). Layouts • Platform independent layouts • Sizers • No fixed sized widgets, etc. • Arbitrary complex layouts • Let’s add the buttons! Sizers create_grid(Frame) -> Grid = wx:grid_sizer(3), % a grid sizer with 3 cols create_buttons(Grid, Frame, 9), % create 9 buttons Grid. create_buttons(_, _, 0) -> ok;create_buttons(Grid, Frame, N) -> Button = wx:button(Frame, N), %a button without label wx:add(Grid, Button), % add button to the sizer N - 1). create_buttons(Grid, Frame, The result • A “shell” of a tic-tac-toe application wxEtop • • Port of the old “etop” New features • • • context menues view running code ... From the programmers point of view • wxErlang is verbose - like most GUI libraries • Trial-and-error - like most GUI libraries • Interface designers • XRCed, DialogBlocks, etc. Design decisions • Binding to the C++ GUI library wxWidgets • Get a lot for free • “free” features from wxWidgets • reduced maintenance work • wxErlang interface resembles wxWidgets C++ interface • free documentation(!) Translation scheme • Easy • Functions • Multiple return values => tuples • ... • Constants Translation scheme • Not as easy • Classes • Overloading and overriding functions • Type system Safety • Checks arguments • Types • Primitive values • Objects • Sanity Implementational details • Most of the code is generated from wxWidgets headers • Implemented as a “port program” • Has a lot of bugs Wrap up • Current status - a prototyp • wxEtop • Perhaps 10% implemented • Future Questions?
© Copyright 2026 Paperzz