ruby-****@sourc*****
ruby-****@sourc*****
2012年 10月 9日 (火) 09:57:49 JST
------------------------- REMOTE_ADDR = 184.145.82.7 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-spbttr ------------------------- @@ -6,11 +6,17 @@ In section [4.9] about '((<Numeric - Text Data Entry|tut-gtk2-numtxt>))' we have learned about the Gtk::SpinButton. While Gtk::CellRendererText can display numbers, a better option is to use Gtk::CellRendererSpin, hence, instead of using a Gtk::Entry object when a numeric content is to be edited, in tree view the Gtk::CellRendererSpin is used. -{{image_left("treev-crs-03-spin-btts.png")}} +{{image_right("treev-crs-03-spin-btts.png")}} -Just like with the pixbuf renderer example there is a problem with the spin button renderers, you can see this from the image on the the left, where we would expect spin buttons in the Count column. Obviously there is again a problem in GTK+. As of Ruby 1.8.6 and Ruby-GNOME2 rel.: 2-0.17.0-rc1, {{image_right("dialog-warning.png")}} most of the methods in Gtk::CellRendererSpin class do not work as expected. It also looks that this is a combined C GTK+ as well as Ruby GTK+ problem. I have compiled the C example from Andrew Klause's book, and it exhibits exactly the same problems as my Ruby translation. You may check it out by clicking on ((<treestore-spin.c|tut-gtk2-treev-treev-spin-cgtk-01>)) +The appearance of user interface in 'spin-rndr.rb' program example is not at all different, from the example in section [8.7.1] ((<(Toggle Button Renderers)|tut-gtk2-treev-crs#Toggle Button Renderers>)). However, do not be deceived with appearance! You will only see the spin-button if you click on any child's cell in 'Count' row. Just like in the example in section [8.7.1], also in our 'spin-rndr.rb' program here we took care of the most obvious 'data dependencies between different cells on our display. If you forgot about it you can refresh your memory buy jumping into section [8.7.1.2] ((<(Data Dependencies Between Cells In Different Columns And Rows In Tree View)|tut-gtk2-treev-crs#Data Dependencies Between Cells In Different Columns And Rows In Tree View>)). There you will discover why clicking on the check-box in product categories control records has no effect. However, the reason that clicking on 'Count' column for both product category rows does not open a spin butt on will become clear if you look at the following code segment: + + column = Gtk::TreeViewColumn.new("Count", renderer, "text" => COUNT_COLUMN) + column.set_cell_data_func(renderer) do |tvc, cell, model, iter| + cell.editable = iter.has_child? ? false : true + fix_parents_total(iter) if !iter.has_child? + end -With Gtk2 2.24.10-3 and Ruby 1.9.3 the example below works if the CellRendererSpin renderer is set to editable +Whether the 'Count' cell is editable her is controlled in the cell data function block, which is executed for all the rows in this particular (Count) column. {{br}} ((*spin-rndr.rb*))