icon_view_example.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/lua
  2. lgi = require 'lgi'
  3. gtk = lgi.Gtk
  4. glib = lgi.GLib
  5. gdk = lgi.Gdk
  6. gobject = lgi.GObject
  7. pixbuf = lgi.GdkPixbuf
  8. w = gtk.Window {
  9. title = 'window', default_width = 400, default_height = 300,
  10. on_destroy = gtk.main_quit
  11. }
  12. w:connect ('destroy', gtk.Main_quit)
  13. w:connect('destroy', gtk.main_quit)
  14. w:set_default_size(200, 250)
  15. w:set_title("Icon View Demo")
  16. local sw = gtk.scrolled_window_new(nil, nil)
  17. sw:set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
  18. w:add(sw)
  19. icon_view = gtk.icon_view_new()
  20. sw:add(icon_view)
  21. -- create store
  22. store = gtk.list_store_new(3, glib.TYPE_INT, glib.TYPE_STRING, gdk.pixbuf_get_type())
  23. icon_view:set_model(self.store)
  24. icon_view:set_text_column(1)
  25. icon_view:set_pixbuf_column(2)
  26. -- insert some items. see .../gtk/gtkstock.h
  27. local iter = gtk.new "GtkTreeIter"
  28. local pix
  29. local names = { 'quit', 'open', 'redo', 'refresh', 'stop',
  30. 'save', 'save-as', 'select-color', 'yes', 'no', 'zoom-fit' }
  31. for i, name in ipairs(names) do
  32. store:append(iter)
  33. pix = icon_view:render_icon('gtk-' .. name, gtk.ICON_SIZE_DIALOG, "")
  34. store:set(iter, 0, i, 1, name, 2, pix, -1)
  35. end
  36. w:show_all()