What's this about?
- Details
-
Category: Erlang
-
Published on Monday, 10 May 2010 08:10
-
Written by Doug Edmunds
-
Hits: 4513
In a hurry?: Download wxcd08.erl (or wxcd08a.erl) and look at the code.
Note (Sept 2015): The final step of the tutorial (wxcd08.erl) has been successfully tested on OTP 18 on Windows 10ProX64. (Erlang/OTP 18 [erts-7.0] [64-bit] [smp:4:4] [async-threads:10])
Note (Nov 2014): The final step of the tutorial (wxcd08.erl) has been successfully tested on OTP 17.3 Rev2 on Crunchbang Linux (Debian) (https://www.erlang-solutions.com/downloads/download-erlang-otp). Open erlang with smp switch (erl -smp)
Note (April 2014): I have added a Bonus code page. (Registration not required).
Note (Sept 2013): The 'next' and 'prev' links at the bottom of pages don't work correctly, so don't use them. Instead, use the blue menu area (top right) for navigation through the tutorial. -- DAE
Let's get started: Here's the finished project.
The First Window tutorial demonstrates how to build a graphical front end for Erlang code, using the wxErlang interface. Start with the First Window tutorial if you are new to wx. For basic controls of your program, this is probably all you will need to know. Try the code for yourself as the window is developed. At each step, make little changes to see what happens.
For Registered Users:
The second group shows how to build some non-widget graphics using 'device contexts'. The last example in that group draws an angle (in degrees) in a circle, based on the number entered by the user in the text box.
The third group demonstrates a way to use the wx_object 'behaviour' model to connect to the wx server. I've isolated the radio buttons module from wx:demo() as a stand alone module and documented the key aspects of that approach.
Registration is free. I know it's a pain. The only reason for asking for registration info, is so that if there are changes to the site, I can let you know about them.
Can't get wx to work on your OS? Read this section, and if you still have problems, sign up for the erlang-questions mailing list (sign up info on the Erlang site) and post your problem there.
First: Find out if if wx is working on your system, type wx:demo() in the shell.
If you receive an error message like this:
WX ERROR: SMP emulator required{error,{not_smp,[{wxe_server,start,0},
{wx,new,1},
{demo,init,1},
{wx_object,init_it,6},
{proc_lib,init_p_do_apply,3}]}}
you need to turn smp on. One way to turn on smp is to start erl / werl with the switch -smp (In windows, create a shortcut for "werl -smp"). Another way is to set an environmental variable ERL_FLAGS=-smp, through system settings.
Running on Ubuntu Linux (Linux Mint):
1) get the source code tar.gz file from erlang.org:
2) Read the install.md file
3) try sudo ./install
if it works with no error messages, then make, make install
4) if there are issues, look at this site:
http://boris.muehmer.de/2011/05/07/installing-erlangotp-r14b02-on-ubuntu-11-04-from-source-tarball/
5) run this code to add missing pieces:
sudo
apt-get -y
install
\
build-essential m4 libncurses-dev \
libssh-dev unixodbc-dev libgmp3-dev \
libwxgtk2.8-dev libglu-dev \
fop xsltproc default-jdk
6) Get coffee because this next part takes a while:
sudo ./install
sudo make
sudo make install
7) looking good, now run erl in a terminal
(your_shell_id)>> erl
Erlang R15B (erts-5.9) [source] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.9 (abort with ^G)
1> wx:demo().
It works for me!!
(May or may still be valid) The Erlang rpm packages available for Fedora include the files needed for wx. I suggest you contact the erlang-questions mailing list if you have a problem getting wx to work with your installation.
To contact me by email use this address: dougedmunds @@ gmail DOT com
-- Doug Edmunds
You may distribute this tutorial for learning purposes, but may not include it in a commercial publication unless permission has been granted. If you copy this, please give credit where credit's due.