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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
return function(parent, dir)
local lgi = require 'lgi'
local GObject = lgi.GObject
local Gtk = lgi.Gtk
local Gdk = lgi.Gdk
local GdkPixbuf = lgi.GdkPixbuf
local window = Gtk.Window {
title = "Dialogs",
border_width = 8,
Gtk.Frame {
label = "Dialogs",
Gtk.Box {
orientation = 'VERTICAL',
border_width = 8,
spacing = 8,
Gtk.Box {
orientation = 'HORIZONTAL',
spacing = 8,
Gtk.Button {
id = 'message_button',
label = "_Message Dialog",
use_underline = true,
},
},
Gtk.Separator { orientation = 'HORIZONTAL' },
Gtk.Box {
orientation = 'HORIZONTAL',
spacing = 8,
Gtk.Box {
orientation = 'VERTICAL',
Gtk.Button {
id = 'interactive_button',
label = "_Interactive Dialog",
use_underline = true,
},
},
Gtk.Grid {
row_spacing = 4,
column_spacing = 4,
{
left_attach = 0, top_attach = 0,
Gtk.Label {
label = "_Entry 1",
use_underline = true,
},
},
{
left_attach = 1, top_attach = 0,
Gtk.Entry {
id = 'entry1',
},
},
{
left_attach = 0, top_attach = 1,
Gtk.Label {
label = "E_ntry 2",
use_underline = true,
},
},
{
left_attach = 1, top_attach = 1,
Gtk.Entry {
id = 'entry2',
},
},
},
},
},
},
}
local popup_count = 1
function window.child.message_button:on_clicked()
local dialog = Gtk.MessageDialog {
transient_for = window,
modal = true,
destroy_with_parent = true,
message_type = 'INFO',
buttons = 'OK',
text = "This message box has been popped up the following\n"
.. "number of times:",
secondary_text = ('%d'):format(popup_count),
}
dialog:run()
dialog:destroy()
popup_count = popup_count + 1
end
function window.child.interactive_button:on_clicked()
local dialog = Gtk.Dialog {
title = "Interactive Dialog",
transient_for = window,
modal = true,
destroy_with_parent = true,
buttons = {
{ Gtk.STOCK_OK, Gtk.ResponseType.OK },
{ "_Non-stock Button", Gtk.ResponseType.CANCEL },
},
}
local hbox = Gtk.Box {
orientation = 'HORIZONTAL',
spacing = 8,
border_width = 8,
Gtk.Image {
stock = Gtk.STOCK_DIALOG_QUESTION,
icon_size = Gtk.IconSize.DIALOG,
},
Gtk.Grid {
row_spacing = 4,
column_spacing = 4,
{
left_attach = 0, top_attach = 0,
Gtk.Label {
label = "_Entry 1",
use_underline = true,
},
},
{
left_attach = 1, top_attach = 0,
Gtk.Entry {
id = 'entry1',
text = window.child.entry1.text,
},
},
{
left_attach = 0, top_attach = 1,
Gtk.Label {
label = "E_ntry 2",
use_underline = true,
},
},
{
left_attach = 1, top_attach = 1,
Gtk.Entry {
id = 'entry2',
text = window.child.entry2.text,
},
},
}
}
dialog:get_content_area():add(hbox)
hbox:show_all()
if dialog:run() == Gtk.ResponseType.OK then
window.child.entry1.text = hbox.child.entry1.text
window.child.entry2.text = hbox.child.entry2.text
end
dialog:destroy()
end
window:show_all()
return window
end,
"Dialog and Message Boxes",
table.concat {
"Dialog widgets are used to pop up a transient window for user feedback.",
}
|