Glade4lua: Design with Glade, implement in Lua

WARNING: I am no longer working on this. See this material as a proof of concept, but not as a usable product.

Glade4lua is a Lua script which reads a Glade GUI design (XML file), and generates a Lua function than constructs the whole widget tree. The generated code uses Lgob, an elegant an compact Lua binding for GTK+, GDK, Pango and more.

Status

For now, Glade4lua is just a 'proof of concept' project. I'll extend it as time allows… I intend to use it to build simple applications for my Iliad (E-book). A first example is MiniPad: a simple text editor (see http://www.mobileread.com/forums/showthread.php?p=639598)

  • 05 okt 2009: initial version
  • 14 okt 2009: added hash with all widgets, optimised (shorter) output
  • 28 okt 2009: allow or more top windows, switch to 'libglade' format, better attribute handling

Download

(including the described example and the generated code) can be downloaded here: glade4lua.tgz. I keep my files in svn at https://dev.mobileread.com/svn/luailiad/trunk/glade4lua/

Glade4lua depends on Lgob.

Workfow

1: Design a GUI

Design with glade-3 (choose the Libglade mode, this works best with all GTK versions), save it as 'example': this results in an XML file 'example.glade'

Note for Iliad: The Iliad has a very old version of GTK: 2.6. Select the GTK 2.8 option, it's the oldest version supported by Glade-3.

2: Convert to Lua

./glade4lua example.glade >example.lua

3: Write an application

example:

#!/usr/bin/env lua
require("lgob.gtk")             -- Binding for GTK+
require("lgob.gdk")             -- Binding for GDK
require 'print_r'               -- debug 
 
builder = require 'example'     -- This is the generated GUI implementation
 
-- Callback table: these function are called by GUI events
local CB_mt = {}
function CB_mt.__index(t, key)
  return function(a,b,c)
    print ("undefined callback: "..key, a, b, c)
  end
end
 
CB = {
  quit = gtk.main_quit,
  hello = function()
    print('Hello World!')
  end,
}
setmetatable(CB, CB_mt)
 
gtk.rc_parse('myrc')            
 
local tree = builder(CB)         -- Contruct the GUI
pr(tree)
--tree['window1.quit']:set_label('Bye!')
tree['window1']:show_all()
gtk.main()

4: Run it!

  ./demo.lua 

5: Iterate

Goto step 1 or 3 until you are satisfied 8-)

WARNING:

I am no longer working on this. See this material as a proof of concept, but not as a usable product.**

   
Last modified: 2010/11/30 07:41 Mijn Fijne Site hosting en design