Created
October 17, 2021 15:32
-
-
Save zhum/8a9af1dfffb7a874ad49f5b0d3d1b5ab to your computer and use it in GitHub Desktop.
Incorrect columns edit example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# | |
require 'gtk2' | |
Gtk.init | |
@window = Gtk::Window.new( Gtk::Window::TOPLEVEL ) | |
@window.set_size_request( 1500, 500 ) | |
@window.signal_connect( "delete_event" ) { Gtk.main_quit } | |
#@window.set_border_width( 5 ) | |
#@window.set_title( "Video searcher" ); | |
vbox2 = Gtk::VBox.new( false, 0 ) | |
scroller = Gtk::ScrolledWindow.new | |
scroller.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC ) | |
@window.add( vbox2 ) | |
vbox2.pack_start( scroller, true, true, 0 ) | |
# Create the TreeStore with columns | |
model = Gtk::TreeStore.new(String, String, String) | |
# Create the TreeView adding the TreeStore | |
tree = Gtk::TreeView.new( model ) | |
# Create the renderer and set properties | |
render = Gtk::CellRendererText.new | |
edit_render1 = Gtk::CellRendererText.new | |
edit_render1.editable = true | |
edit_render1.signal_connect('edited') do |renderer, val, var| | |
iter = model.get_iter(val) | |
warn "1 #{iter[0]}: #{iter[1]},#{iter[2]}" | |
iter[1] = var | |
end | |
edit_render2 = Gtk::CellRendererText.new | |
edit_render2.editable = true | |
edit_render2.signal_connect('edited') do |renderer, val, var| | |
iter = model.get_iter(val) | |
warn "2 #{iter[0]}: #{iter[1]},#{iter[2]}" | |
iter[2] = var | |
end | |
# Create the columns | |
c1 = Gtk::TreeViewColumn.new( "Title", render, {:text => 0} ) | |
c1.resizable = true | |
c1.max_width = 300 | |
c2 = Gtk::TreeViewColumn.new( "tst1", edit_render1, {:text => 1} ) | |
c2.resizable = true | |
c3 = Gtk::TreeViewColumn.new( "tst2", edit_render2, {:text => 1} ) | |
c3.resizable = true | |
# append the columns to treeview | |
tree.append_column( c1 ) | |
tree.append_column( c2 ) | |
tree.append_column( c3 ) | |
# add the treeview to the scroller | |
scroller.add( tree ) | |
#build_tree( tree, model ) | |
root = model.append( nil ) | |
root[0] = "ROOT" | |
root[1] = "-" | |
root[2] = "-" | |
[1,2,3,4].each{ |i| | |
val=model.append(root) | |
val.set_value(0,i.to_s) | |
val.set_value(1,i.to_s) | |
val.set_value(2,(i+10).to_s) | |
#add_tree(val,model,1,"#{i} test") | |
} | |
@window.show_all | |
Gtk.main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment