I’m working on a database editor, and the CellRenderCombo
will work well for selecting one of many choices.
Thank you for developing and documenting this, Masao M..
(Joe Van D. - 11-14-2005)
I’m not a big fan of how the combo select (or option menu, not sure of
the correct name) widget works in Gtk treeviews. I have to click four
times in order to choose a new computer.
…And it’s not even obvious that the column contains combo select widgets.
Yes, I have the same usability concerns.
Setting has_entry to false will lower the number of clicks
to three.
Possible fixes :
1. Implement CellRenderComboBox
This would have the "V" always displayed, to let
the user know the column supports selection.
Clicking on the "V" would bring up the select list,
so only two clicks would be needed to make
changes.
Also, the "V" could support a tree navigation of
selections,
rather than a long list.
If CellRenderComboBox is already done please let me
know.
2. Add my own "V" to the right of the CellRenderCombo
Any idea how hard this is ?
3. Use a special font or color.
I could easily do this to let user know the
column contains combo select widgets.
4. Other ideas ??
The code below illustrates these issues:
A. CellRenderCombo performs well with a big table
with many choices per entry.
B. Difference between Editable Combo and non-editable
is shown.
C. Problem selecting off a list with 1000 choices
is shown.
Appreciate your help - Andy
#! /usr/bin/env ruby
A demo of the CellRendererCombo in a TreeView
A table of 1000 rows and 9 columns is displayed.
Each column supports 1000 choices.
All values are displayed as strings to test performance.
The first column is editable, the remaining ones are not.
The code should not be used as an example of how to properly
build CellRendererCombo boxes - it simply illustrates the GUI.
require ‘gtk2’
module ComboDemo
class ListStore < Gtk::Window
def initialize
super('CellRenderCombo in TreeView demo')
sw = Gtk::ScrolledWindow.new(nil, nil)
sw.shadow_type = Gtk::SHADOW_ETCHED_IN
sw.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC)
add sw
ar1 = []
(9999001..9999999).each{ |i|
ar2 = []
(1..9).each{ |j| ar2 << (i + j).to_s }
ar1 << ar2
}
bug = Struct.new('Bug', :a, :b, :c, :d, :e, :f, :g, :h, :i)
model = Gtk::ListStore.new
(String,String,String,String,String,String,String,String,String)
ar1.each do |bug|
iter = model.append;
(0…8).each{ |i|
iter[i] = bug[i]
}
end
picks = []
(9999000…9999999).each{ |i| picks << i.to_s }
treeview = Gtk::TreeView.new(model) # create tree view
############### Add editable column to the tree view
###############################
tex = Gtk::CellRendererCombo.new
tex.signal_connect("edited") do |*args| # Support data entry
iter = treeview.model.get_iter(args[1])
iter[0] = args[2]
end
list = Gtk::ListStore.new(String)
picks.each{ |i| iter = list.append; iter[0] = i }
tex.model = list # Set values to select from
tex.editable = true # User can change values
tex.has_entry = true # User can type in text as well
as
select from list
tex.text_column = 0
col = Gtk::TreeViewColumn.new("Editable Combo", tex, 'text' => 0)
col.set_sort_column_id(0)
col.resizable = true
treeview.append_column(col)
############### Add 8 non-editable columns to the tree view
##########################
(1..8).each{ |cnum|
tex = Gtk::CellRendererCombo.new
tex.signal_connect("edited") do |*args| ## Data entry
iter = treeview.model.get_iter(args[1])
iter[cnum] = args[2]
end
list = Gtk::ListStore.new(String)
picks.each{ |i| iter = list.append; iter[0] = i }
tex.model = list # Set values to select from
tex.editable = true # User can edit
tex.has_entry = false # User can't type in text
tex.text_column = 0
col = Gtk::TreeViewColumn.new("Combo " + cnum.to_s, tex, 'text'
=>
cnum.to_i)
col.set_sort_column_id(cnum)
col.resizable = true
treeview.append_column(col)
}
sw.add(treeview)
set_default_size(150, 150)
end
end
end
Gtk.init
ComboDemo::ListStore.new.show_all
Gtk.main