1return function(parent, dir) 2 3local lgi = require 'lgi' 4local GObject = lgi.GObject 5local Gtk = lgi.Gtk 6local Gdk = lgi.Gdk 7local GdkPixbuf = lgi.GdkPixbuf 8 9local window = Gtk.Window { 10 title = "Dialogs", 11 border_width = 8, 12 Gtk.Frame { 13 label = "Dialogs", 14 Gtk.Box { 15 orientation = 'VERTICAL', 16 border_width = 8, 17 spacing = 8, 18 Gtk.Box { 19 orientation = 'HORIZONTAL', 20 spacing = 8, 21 Gtk.Button { 22 id = 'message_button', 23 label = "_Message Dialog", 24 use_underline = true, 25 }, 26 }, 27 Gtk.Separator { orientation = 'HORIZONTAL' }, 28 Gtk.Box { 29 orientation = 'HORIZONTAL', 30 spacing = 8, 31 Gtk.Box { 32 orientation = 'VERTICAL', 33 Gtk.Button { 34 id = 'interactive_button', 35 label = "_Interactive Dialog", 36 use_underline = true, 37 }, 38 }, 39 Gtk.Grid { 40 row_spacing = 4, 41 column_spacing = 4, 42 { 43 left_attach = 0, top_attach = 0, 44 Gtk.Label { 45 label = "_Entry 1", 46 use_underline = true, 47 }, 48 }, 49 { 50 left_attach = 1, top_attach = 0, 51 Gtk.Entry { 52 id = 'entry1', 53 }, 54 }, 55 { 56 left_attach = 0, top_attach = 1, 57 Gtk.Label { 58 label = "E_ntry 2", 59 use_underline = true, 60 }, 61 }, 62 { 63 left_attach = 1, top_attach = 1, 64 Gtk.Entry { 65 id = 'entry2', 66 }, 67 }, 68 }, 69 }, 70 }, 71 }, 72} 73 74local popup_count = 1 75function window.child.message_button:on_clicked() 76 local dialog = Gtk.MessageDialog { 77 transient_for = window, 78 modal = true, 79 destroy_with_parent = true, 80 message_type = 'INFO', 81 buttons = 'OK', 82 text = "This message box has been popped up the following\n" 83 .. "number of times:", 84 secondary_text = ('%d'):format(popup_count), 85 } 86 dialog:run() 87 dialog:destroy() 88 popup_count = popup_count + 1 89end 90 91function window.child.interactive_button:on_clicked() 92 local dialog = Gtk.Dialog { 93 title = "Interactive Dialog", 94 transient_for = window, 95 modal = true, 96 destroy_with_parent = true, 97 buttons = { 98 { Gtk.STOCK_OK, Gtk.ResponseType.OK }, 99 { "_Non-stock Button", Gtk.ResponseType.CANCEL }, 100 }, 101 } 102 local hbox = Gtk.Box { 103 orientation = 'HORIZONTAL', 104 spacing = 8, 105 border_width = 8, 106 Gtk.Image { 107 stock = Gtk.STOCK_DIALOG_QUESTION, 108 icon_size = Gtk.IconSize.DIALOG, 109 }, 110 Gtk.Grid { 111 row_spacing = 4, 112 column_spacing = 4, 113 { 114 left_attach = 0, top_attach = 0, 115 Gtk.Label { 116 label = "_Entry 1", 117 use_underline = true, 118 }, 119 }, 120 { 121 left_attach = 1, top_attach = 0, 122 Gtk.Entry { 123 id = 'entry1', 124 text = window.child.entry1.text, 125 }, 126 }, 127 { 128 left_attach = 0, top_attach = 1, 129 Gtk.Label { 130 label = "E_ntry 2", 131 use_underline = true, 132 }, 133 }, 134 { 135 left_attach = 1, top_attach = 1, 136 Gtk.Entry { 137 id = 'entry2', 138 text = window.child.entry2.text, 139 }, 140 }, 141 } 142 } 143 dialog:get_content_area():add(hbox) 144 hbox:show_all() 145 146 if dialog:run() == Gtk.ResponseType.OK then 147 window.child.entry1.text = hbox.child.entry1.text 148 window.child.entry2.text = hbox.child.entry2.text 149 end 150 dialog:destroy() 151end 152 153window:show_all() 154return window 155end, 156 157"Dialog and Message Boxes", 158 159table.concat { 160 "Dialog widgets are used to pop up a transient window for user feedback.", 161} 162