demo-infobar.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. return function(parent, dir)
  2. local lgi = require 'lgi'
  3. local GLib = lgi.GLib
  4. local Gtk = lgi.Gtk
  5. local window = Gtk.Window {
  6. title = 'Info Bars',
  7. border_width = 8,
  8. Gtk.Box {
  9. orientation = 'VERTICAL',
  10. Gtk.InfoBar {
  11. id = 'info',
  12. message_type = 'INFO',
  13. },
  14. Gtk.InfoBar {
  15. id = 'warning',
  16. message_type = 'WARNING',
  17. },
  18. Gtk.InfoBar {
  19. id = 'question',
  20. buttons = {
  21. { Gtk.STOCK_OK, Gtk.ResponseType.OK },
  22. },
  23. message_type = 'QUESTION',
  24. },
  25. Gtk.InfoBar {
  26. id = 'error',
  27. message_type = 'ERROR',
  28. },
  29. Gtk.InfoBar {
  30. id = 'other',
  31. message_type = 'OTHER',
  32. },
  33. Gtk.Frame {
  34. label = "Info Bars",
  35. Gtk.Box {
  36. orientation = 'VERTICAL',
  37. spacing = 8,
  38. border_width = 8,
  39. {
  40. padding = 8,
  41. Gtk.Label {
  42. label = "An example of different info bars",
  43. },
  44. }
  45. },
  46. },
  47. },
  48. }
  49. -- Create contents for the infobars.
  50. for _, id in ipairs { 'info', 'warning', 'question', 'error', 'other' } do
  51. window.child[id]:get_content_area():add(
  52. Gtk.Label {
  53. label = ("This is an info bar with "
  54. .. "message type Gtk.MessageType.%s"):format(
  55. GLib.ascii_strup(id, -1)),
  56. })
  57. end
  58. function window.child.question:on_response(response_id)
  59. local dialog = Gtk.MessageDialog {
  60. transient_for = window,
  61. modal = true,
  62. destroy_with_parent = true,
  63. message_type = 'INFO',
  64. buttons = 'OK',
  65. text = "You clicked a button on an info bar",
  66. secondary_text = ("Your response has id %d"):format(response_id)
  67. }
  68. dialog:run()
  69. dialog:destroy()
  70. end
  71. window:show_all()
  72. return window
  73. end,
  74. "Info bar",
  75. table.concat {
  76. [[Info bar widgets are used to report important messages to the user.]],
  77. }