demo-entry-completion.lua 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. return function(parent, dir)
  2. local lgi = require 'lgi'
  3. local GObject = lgi.GObject
  4. local Gtk = lgi.Gtk
  5. local window = Gtk.Dialog {
  6. title = "GtkEntryCompletion",
  7. resizable = false,
  8. on_response = Gtk.Widget.destroy,
  9. buttons = {
  10. { Gtk.STOCK_CLOSE, Gtk.ResponseType.NONE },
  11. },
  12. }
  13. local store = Gtk.ListStore.new { GObject.Type.STRING }
  14. for _, name in ipairs { "GNOME", "total", "totally" } do
  15. store:append { name }
  16. end
  17. local content = Gtk.Box {
  18. orientation = 'VERTICAL',
  19. spacing = 5,
  20. border_width = 5,
  21. Gtk.Label {
  22. label = "Completion demo, try writing <b>total</b> or <b>gnome</b> "
  23. .. "for example.",
  24. use_markup = true,
  25. },
  26. Gtk.Entry {
  27. id = 'entry',
  28. completion = Gtk.EntryCompletion {
  29. model = store,
  30. text_column = 0,
  31. },
  32. },
  33. }
  34. window:get_content_area():add(content)
  35. window:show_all()
  36. return window
  37. end,
  38. "Entry/Entry Completion",
  39. table.concat {
  40. "Gtk.EntryCompletion provides a mechanism for adding support for ",
  41. "completion in Gtk.Entry.",
  42. }