mxwidgets.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #! /usr/bin/env lua
  2. --
  3. -- Basic MX sample, adapted from Vala code from
  4. -- http://live.gnome.org/Vala/MxSample
  5. --
  6. local lgi = require('lgi')
  7. local GObject = lgi.GObject
  8. local Mx = lgi.require('Mx', '1.0')
  9. local Clutter = lgi.require('Clutter', '1.0')
  10. local app = Mx.Application { application_name = "MX Widget Factory" }
  11. local window = app:create_window()
  12. window.clutter_stage:set_size(500, 300)
  13. local hbox = Mx.BoxLayout()
  14. window.toolbar:add_actor(hbox)
  15. local button = Mx.Button {
  16. label = "Click me",
  17. tooltip_text = "Please click this button!",
  18. on_clicked = function(self) self.label = "Thank you!" end
  19. }
  20. local combo = Mx.ComboBox()
  21. for _, name in ipairs { "Africa", "Antarctica", "Asia", "Australia", "Europe",
  22. "North America", "South America" } do
  23. combo:append_text(name)
  24. end
  25. combo.index = 0
  26. function combo.on_notify:index()
  27. print(("Selected continent: %s"):format(self.active_text))
  28. end
  29. hbox:add(button, combo)
  30. local table = Mx.Table { column_spacing = 24, row_spacing = 24 }
  31. local button = Mx.Button { label = "Button" }
  32. table:add_actor(button, 0, 0)
  33. table.meta[button].y_fill = false
  34. local entry = Mx.Entry { text = "Entry" }
  35. table:add_actor(entry, 0, 1)
  36. table.meta[entry].y_fill = false
  37. local combo = Mx.ComboBox { active_text = "Combo Box" }
  38. combo:append_text("Hello")
  39. combo:append_text("Dave")
  40. table:add_actor(combo, 0, 2)
  41. table.meta[entry].y_fill = false
  42. local scrollbar = Mx.ScrollBar {
  43. adjustment = Mx.Adjustment {
  44. lower = 0, upper = 10,
  45. page_increment = 1, page_size = 1
  46. },
  47. height = 22
  48. }
  49. table:add_actor(scrollbar, 1, 0)
  50. table.meta[entry].y_fill = false
  51. local progressbar = Mx.ProgressBar { progress = 0.7 }
  52. table:add_actor(progressbar, 1, 1)
  53. table.meta[progressbar].y_fill = false
  54. local slider = Mx.Slider()
  55. table:add_actor(slider, 1, 2)
  56. table.meta[slider].y_fill = false
  57. function slider.on_notify:value()
  58. progressbar.progress = slider.value
  59. end
  60. local pathbar = Mx.PathBar()
  61. for _, path in ipairs { "", "Path", "Bar" } do pathbar:push(path) end
  62. table:add_actor(pathbar, 2, 0)
  63. local expander = Mx.Expander { label = "Expander" }
  64. table:add_actor(expander, 2, 1)
  65. table.meta[expander].y_fill = false
  66. expander:add_actor(Mx.Label { text = "Hello" })
  67. local toggle = Mx.Toggle()
  68. table:add_actor(toggle, 2, 2)
  69. table.meta[toggle].y_fill = false
  70. local togglebutton = Mx.Button { label = "Toggle", is_toggle = true }
  71. table:add_actor(togglebutton, 3, 0)
  72. table.meta[togglebutton].y_fill = false
  73. local checkbutton = Mx.Button { is_toggle = true }
  74. checkbutton:set_style_class('check-box')
  75. table:add_actor(checkbutton, 3, 1)
  76. table.meta[checkbutton].y_fill = false
  77. table.meta[checkbutton].x_fill = false
  78. -- Just for fun, create binding between both kinds of toggles.
  79. togglebutton:bind_property('toggled', checkbutton, 'toggled',
  80. GObject.BindingFlags.BIDIRECTIONAL)
  81. scrollbar = Mx.ScrollBar {
  82. adjustment = Mx.Adjustment {
  83. lower = 0, upper = 10,
  84. page_increment = 1, page_size = 1,
  85. },
  86. orientation = Mx.Orientation.VERTICAL,
  87. width = 22
  88. }
  89. table:add_actor(scrollbar, 0, 3)
  90. table.meta[scrollbar].row_span = 3
  91. window.child = Mx.Frame { child = table }
  92. window.clutter_stage:show()
  93. app:run()