Yet Another GUI for Erlang Like a Fish needs a Bicycle. Why did I - - PowerPoint PPT Presentation

yet another gui for erlang
SMART_READER_LITE
LIVE PREVIEW

Yet Another GUI for Erlang Like a Fish needs a Bicycle. Why did I - - PowerPoint PPT Presentation

Yet Another GUI for Erlang Like a Fish needs a Bicycle. Why did I do it? GUI tools for testing and troubleshooting Wanted to write some C Why Yet Another? GS/Tcl is slow ugly bizarre no GUI builder ErlGTK no


slide-1
SLIDE 1

Yet Another GUI for Erlang

Like a Fish needs a Bicycle.

slide-2
SLIDE 2

Why did I do it?

  • GUI tools for testing and troubleshooting
  • Wanted to write some C
slide-3
SLIDE 3

Why Yet Another?

  • GS/Tcl is

– slow – ugly – bizarre – no GUI builder

  • ErlGTK

– no longer supported

slide-4
SLIDE 4

Why GTK2?

  • Elegant design
  • Open Source de facto standard (with Qt)
  • Runs on Unices and Windows, but not MacOS
  • Looks good
  • Excellent GUI builder (Glade)
  • Strangely familiar...

– Garbage collection – Runtime type checking – Introspection

slide-5
SLIDE 5

gtkNode

  • C-node
  • Each widget appears as a registered Erlang process
  • Behaviour is specified by the config file from Glade
  • Communicates with the Erlang node through messages
slide-6
SLIDE 6

Glade

  • Defines and names widgets
  • Specifies properties of widgets
  • Layout
  • Events

– Ignore – Handle by GTK callback – Send Erlang message

slide-7
SLIDE 7

OO

  • GTK is object oriented, but implemented in C
  • Each method is a C function call

gtk_class_method(widget,args...);

  • From Erlang, it looks like this (conceptually);

Widget ! {class_method, [Args]},

  • It is implemented thusly;

GtkNode ! {class_method, [Widget|Args]},

slide-8
SLIDE 8

Type safety

When gtkNode receives a message it checks;

– Widget exists – Method exists – Widget is of correct class for method – Right number of args – Right type of args

If one of these fails, gtkNode sends an error tuple. Otherwise it calls the method and sends the result to the Erlang node

slide-9
SLIDE 9

Typical

GTK's basic types are;

  • floats
  • integers
  • strings
  • widgets (boxed pointer)
  • structs (boxed pointer)
  • booleans
  • macros

Mapped to Erlang;

  • float
  • integer
  • list
  • atom
  • atom
  • true/false
  • atoms
slide-10
SLIDE 10

Code generator

  • The code generator decides which GTK functions

can be safely called from Erlang (about half)

  • For each safe function it generates C wrapper

code that does the type checking

  • The code generator works by analyzing the C

header files.

  • Written in Erlang and Python (stolen from

PyGtk)

slide-11
SLIDE 11

Odds and Ends

  • messages can be stacked for efficiency
  • recommended usage is through gtkNode.erl

available from jungerl: http://jungerl.sourceforge.net