/GTK3- TreeView만 표시

4904 단어 GTK3gtkRuby
gem install gtk3

최대한 간단하게 하면 이런 느낌이에요.
개량할 여지가 있을 거예요.
require 'gtk3'
require 'csv'
require 'open-uri'

url = "https://raw.githubusercontent.com/pandas-dev/pandas/master/pandas/tests/data/iris.csv"
iris = CSV.parse(URI.open(url))

ls = Gtk::ListStore.new(*([String] * 5))
mf = ls.create_filter

treeview = Gtk::TreeView.new(mf)
iris.shift.each_with_index do |header, i|
  column = Gtk::TreeViewColumn.new(header, Gtk::CellRendererText.new, text: i)
  treeview.append_column(column)
end

iris.each do |val|
  iter = ls.append
  iter.values = val
end

win = Gtk::Window.new
win.title = 'Gtk::TreeModelFilter sample'
win.set_size_request 500, 400

sw = Gtk::ScrolledWindow.new
sw.add_with_viewport(treeview)

win.add sw
win.signal_connect('destroy') { Gtk.main_quit }
win.show_all
Gtk.main

좋은 웹페이지 즐겨찾기