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.
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)
(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.
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.
./glade4lua example.glade >example.lua
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()
./demo.lua
Goto step 1 or 3 until you are satisfied
I am no longer working on this. See this material as a proof of concept, but not as a usable product.**