Cover by Francesco Cesarini, Simon Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

The MiniBlog Example

This example extends the preceding example to give a basic implementation of a “mini blog”; this forms the basis for a series of suggested extensions that will give you a chance to program in wxErlang for yourself.

The mini blog is a list of dated entries, each occupying a single line, much like a Facebook status message or a Twitter Tweet. As well as the About and Exit options, the GUI provides these operations on the blog:

New

Creates a new, empty mini blog.

Open

Opens the blog saved in the BLOG file.

Save

Saves the current blog in the BLOG file, overwriting its contents if it already exists.

Add entry

Adds an entry at the end of the blog. The entry is automatically dated.

Undo latest

Undoes the latest “add entry”; this can be done recursively.

Figure 14-4 shows a screenshot of the system.

To describe the Erlang code for MiniBlog we’ll explain how the MicroBlog code is modified. The head of the miniblog.erl module extends microblog.erl with a number of identifier macro definitions, to give a unique identifier to each menu command:

-define(APPEND,131).
-define(UNDO,132).
-define(OPEN,133).
-define(SAVE,134).
-define(NEW,135).
The mini blog application

Figure 14-4. The mini blog application

The main function, miniblog:start/0, extends the previous function by adding a text control (wxTextCtrl) that contains the entries; this Text object is then passed to the setup and loop functions:

start() -> wx:new(), ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required