LuaGnome Gnome库的Lua完整封装 项目简介
LuaGnome(原名Lua-GTK)是Gnome库的Lua语言完整封装,包括glib 2.x, gdk, gtk 2.x等。 目前大约有7600个函数700个结构体、联合体和约5800个常量(枚举, 宏定义)可以使用。这个库非常小,编译后只有350KB左右(加上一些很小的、额外的Lua文件). 支持Linux、Windows(MinGW)。 示例代码:http://lua-gtk.luaforge.net/en/examples.html function MainWin.new()
local self = {}
setmetatable(self, MainWin)
self.w = gtk.window_new(gtk.WINDOW_TOPLEVEL)
self.w:connect('destroy', gtk.main_quit)
self.w:set_default_size(200, 250)
self.w:set_title("Icon View Demo")
local sw = gtk.scrolled_window_new(nil, nil)
sw:set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.w:add(sw)
self.icon_view = gtk.icon_view_new()
sw:add(self.icon_view)
-- create store
self.store = gtk.list_store_new(3, glib.TYPE_INT, glib.TYPE_STRING,
gdk.pixbuf_get_type())
self.icon_view:set_model(self.store)
self.icon_view:set_text_column(1)
self.icon_view:set_pixbuf_column(2)
-- insert some items. see .../gtk/gtkstock.h
local iter = gtk.new "GtkTreeIter"
local pix
local names = { 'quit', 'open', 'redo', 'refresh', 'stop', 'save',
'save-as', 'select-color', 'yes', 'no', 'zoom-fit' }
for i, name in ipairs(names) do
self.store:append(iter)
pix = self.icon_view:render_icon('gtk-' .. name,
gtk.ICON_SIZE_DIALOG, "")
self.store:set(iter, 0, i, 1, name, 2, pix, -1)
end
self.w:show_all()
return self
end 效果:
local self = {}
setmetatable(self, MainWin)
self.w = gtk.window_new(gtk.WINDOW_TOPLEVEL)
self.w:connect('destroy', gtk.main_quit)
self.w:set_default_size(200, 250)
self.w:set_title("Icon View Demo")
local sw = gtk.scrolled_window_new(nil, nil)
sw:set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.w:add(sw)
self.icon_view = gtk.icon_view_new()
sw:add(self.icon_view)
-- create store
self.store = gtk.list_store_new(3, glib.TYPE_INT, glib.TYPE_STRING,
gdk.pixbuf_get_type())
self.icon_view:set_model(self.store)
self.icon_view:set_text_column(1)
self.icon_view:set_pixbuf_column(2)
-- insert some items. see .../gtk/gtkstock.h
local iter = gtk.new "GtkTreeIter"
local pix
local names = { 'quit', 'open', 'redo', 'refresh', 'stop', 'save',
'save-as', 'select-color', 'yes', 'no', 'zoom-fit' }
for i, name in ipairs(names) do
self.store:append(iter)
pix = self.icon_view:render_icon('gtk-' .. name,
gtk.ICON_SIZE_DIALOG, "")
self.store:set(iter, 0, i, 1, name, 2, pix, -1)
end
self.w:show_all()
return self
end 效果: