wx Erlang MatsOla Persson wx Erlang GUI library
wx. Erlang Mats-Ola Persson
wx. Erlang • GUI library for Erlang • write GUI applications • 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 wx. Erlang % create a frame (window) with no parent Frame = wx: frame(? NULL, ? wx. ID_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, ? wx. ID_ANY, “Hello World!”), % event-handler that reacts to close clicks wx: connect(Frame, ? wx. EVT_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
wx. Etop • • Port of the old “etop” New features • • • context menues view running code. . .
From the programmers point of view • wx. Erlang is verbose - like most GUI libraries • Trial-and-error - like most GUI libraries • Interface designers • XRCed, Dialog. Blocks, etc.
Design decisions • Binding to the C++ GUI library wx. Widgets • Get a lot for free • “free” features from wx. Widgets • reduced maintenance work • wx. Erlang interface resembles wx. Widgets 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 wx. Widgets headers • Implemented as a “port program” • Has a lot of bugs
Wrap up • Current status - a prototyp • wx. Etop • Perhaps 10% implemented • Future
Questions?
- Slides: 19