1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#! /usr/bin/env lua
--
-- Sample GTK Hello program
--
-- Based on test from LuiGI code. Thanks Adrian!
--
local lgi = require 'lgi'
local Gtk = lgi.require('Gtk')
-- Create top level window with some properties and connect its 'destroy'
-- signal to the event loop termination.
local window = Gtk.Window {
title = 'window',
default_width = 400,
default_height = 300,
on_destroy = Gtk.main_quit
}
if tonumber(Gtk._version) >= 3 then
window.has_resize_grip = true
end
-- Create some more widgets for the window.
local status_bar = Gtk.Statusbar()
local toolbar = Gtk.Toolbar()
local ctx = status_bar:get_context_id('default')
status_bar:push(ctx, 'This is statusbar message.')
-- When clicking at the toolbar 'quit' button, destroy the main window.
toolbar:insert(Gtk.ToolButton {
stock_id = 'gtk-quit',
on_clicked = function() window:destroy() end,
}, -1)
-- About button in toolbar and its handling.
local about_button = Gtk.ToolButton { stock_id = 'gtk-about' }
function about_button:on_clicked()
local dlg = Gtk.AboutDialog {
program_name = 'LGI Demo',
title = 'About...',
name = 'LGI Hello',
copyright = '(C) Copyright 2010, 2011 Pavel Holejšovský',
authors = { 'Adrian Perez de Castro', 'Pavel Holejšovský', },
}
if tonumber(Gtk._version) >= 3 then
dlg.license_type = Gtk.License.MIT_X11
end
dlg:run()
dlg:hide()
end
toolbar:insert(about_button, -1)
-- Pack everything into the window.
local vbox = Gtk.VBox()
vbox:pack_start(toolbar, false, false, 0)
vbox:pack_start(Gtk.Label { label = 'Contents' }, true, true, 0)
vbox:pack_end(status_bar, false, false, 0)
window:add(vbox)
-- Show window and start the loop.
window:show_all()
Gtk.main()
|