minimal.lua 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #! /usr/bin/env lua
  2. -- XXX:This example is outdated and uses libgtkflow in a pre-0.8-way
  3. -- TODO: fix this example. use the .with_type-constructor of Sources and Sinks
  4. local lgi = require 'lgi'
  5. local GObject = lgi.require('GObject')
  6. local Gtk = lgi.require('Gtk')
  7. local GFlow = lgi.require('GFlow')
  8. local GtkFlow = lgi.require('GtkFlow')
  9. local window = Gtk.Window {
  10. title = 'window',
  11. default_width = 400,
  12. default_height = 300,
  13. on_destroy = Gtk.main_quit
  14. }
  15. local sw = Gtk.ScrolledWindow {}
  16. local nv = GtkFlow.NodeView.new()
  17. local button = Gtk.Button { label = 'Add Node' }
  18. function button:on_clicked()
  19. local n = GFlow.SimpleNode {}
  20. local sink_v = GObject.Value(GObject.Type.INT,0)
  21. local source_v = GObject.Value(GObject.Type.INT,0)
  22. local sink = GFlow.SimpleSink.new(sink_v)
  23. local source = GFlow.SimpleSource.new(source_v)
  24. sink:set_name("sink")
  25. source:set_name("source")
  26. n:add_source(source)
  27. n:add_sink(sink)
  28. n:set_name("node")
  29. nv:add_node(n)
  30. end
  31. local vbox = Gtk.VBox()
  32. sw:add(nv)
  33. vbox:pack_start(button, false, false, 0)
  34. vbox:pack_start(sw, true, true, 1)
  35. window:add(vbox)
  36. window:show_all()
  37. Gtk.main()