Hi, I''m using wxruby 2.0.1 w/ Ruby 1.8.7 on OS X 10.6.2. So far I have successfully implemented a grid with bool, choice and text edit controls. To combine the edit code with my app, I have subclassed the editor controls to get hooks for the begin_edit/end_edit events. This worked fine for the GridCellTextEditor and the GridCellChoiceEditor. My problem is, that I can''t seem to get events for the GridCellNumberEditor. Find attached the modified grid example with subclassed controls. I''m getting the begin_edit/end_edit outputs for the choice control but not for the number control. To reproduce, start the application, click the choice editor and select a value. Note the console output that occurs on begin and end edit. Now click the number editor and change the number using the spin control. Notice how there is NO console output although the editor has been instantiated earlier. What''s wrong? Is there another, preferable way of integrating a control''s events into an application to generate callbacks and allow for value vetoes? Thanks in advance, Tony -- Posted via http://www.ruby-forum.com/.
here''s the code (I can''t seem to attach it) [code] begin require ''rubygems'' rescue LoadError end require ''wx'' class MyNumberEditor < Wx::GridCellNumberEditor def initialize(min, max) super puts "creating number editor" end def begin_edit row, col, grid puts "begin edit" super end def end_edit row, col, grid puts "end edit" super end end class MyChoiceEditor < Wx::GridCellChoiceEditor def initialize choices puts "choice init" super end def begin_edit(row, col, grid) puts "choice begin edit" super end def end_edit(row, col, grid) puts "choice end edit w/ value #{get_value()}" super end end class GridFrame < Wx::Frame def initialize(parent, id = -1, title = "MyFrame", pos = Wx::DEFAULT_POSITION, size = Wx::DEFAULT_SIZE, style = Wx::DEFAULT_FRAME_STYLE) super(parent, id, title, pos, size, style) sizer = Wx::BoxSizer.new(Wx::VERTICAL) set_status_text(Wx::VERSION_STRING) make_grid(self) sizer.add(@grid, 1, Wx::ALL|Wx::GROW, 4) set_sizer(sizer) end def make_grid(panel) @grid = Wx::Grid.new(panel, -1) @grid.create_grid( 20, 12 ) @grid.set_default_cell_background_colour(Wx::WHITE) editor = MyNumberEditor.new(7,23) @grid.set_cell_value(3, 1, ''Number editor below'') @grid.set_cell_editor(4, 1, editor) editor = MyChoiceEditor.new([''foo'', ''bar'', ''baz'']) @grid.set_cell_value(3, 3, ''Choice editor below'') @grid.set_cell_editor(4, 3, editor) @grid.auto_size_row(3, true) end end class GridApp < Wx::App def on_init frame = GridFrame.new(nil, -1, "Grid Sample", Wx::Point.new(10, 100), Wx::Size.new(630,400)) set_top_window(frame) frame.show() end end GridApp.new.main_loop() [/code] -- Posted via http://www.ruby-forum.com/.
me again - I''m still struggling with the Grid code. Maybe this is a problem with my runtime environment? I''m using wxruby 2.0.1 on Snow Leopard 10.6.2 using Ruby 1.8.7 and wxWidgets 2.8.10. Is this supposed to be a valid combination? It seems that, with this combination the GridCellNumberEditor cannot be properly derived from. When registered as an editor with a Grid, the constructor is called but, upon editing, neither the begin_edit nor the end_edit methods from the derived class are called. All of this, in spite a NumberCellEditor is properly displayed and the code also calls to TableBase''s set_value() method when the editor closes. What''s going on? Is this a bug or am I completely misled on the usage of this? Thanks for any pointers in the right direction. Tony. --- #!/usr/bin/env arch -i386 ruby begin require ''rubygems'' rescue LoadError end require ''wx'' class MyGridTable < Wx::GridTableBase attr_reader :cols, :rows def initialize(rows, cols) super() @rows = rows @cols = cols end def get_number_rows @rows end def get_number_cols @cols end def get_value(row, col) (col + @cols * row).to_s end def get_attr(row, col, attr_kind) Wx::GridCellAttr.new end def is_empty_cell(row, col) false end def set_value(x, y, val) puts "Attempting to change cell (#{x}, #{y}) to ''#{val}''" end def get_type_name(row, col) "FOOBAR" end end class MyEditor < Wx::GridCellNumberEditor def initialize puts ''my editor init'' # called upon app start super(0,100) end def begin_edit row, col, grid super puts "begin edit" # never gets called end def end_edit(row, col, grid) puts "end edit" # never gets called super end end class GridFrame < Wx::Frame def initialize() super(nil, :title => ''Grid editor example'', :size => [600, 300]) main_sizer = Wx::VBoxSizer.new @grid = Wx::Grid.new(self) @grid.register_data_type( "FOOBAR", Wx::GridCellStringRenderer.new, MyEditor.new ) @grid.table = MyGridTable.new(10, 10) main_sizer.add(@grid, 1, Wx::EXPAND|Wx::ALL, 5) self.sizer = main_sizer end end Wx::App.run do GridFrame.new.show end -- Posted via http://www.ruby-forum.com/.
> I''m using wxruby 2.0.1 on Snow Leopard 10.6.2 using Ruby 1.8.7 and > wxWidgets 2.8.10. Is this supposed to be a valid combination? > > It seems that, with this combination the GridCellNumberEditor cannot be > properly derived from.Update: I cross-checked this with Windows XP, wxWidgets 2.8.10 and Ruby 1.8.6. The behavior is identical (begin_edit and end_edit are NOT called) except that, with XP, using the mousewheel and accepting an input with "Enter" works out of the box - which it doesn''t on OS X. And that was exactly the reason why I tried to override begin_edit and end_edit. Ouch. -- Posted via http://www.ruby-forum.com/.
Tony Meier wrote:> me again - I''m still struggling with the Grid code. Maybe this is a > problem with my runtime environment? > > I''m using wxruby 2.0.1 on Snow Leopard 10.6.2 using Ruby 1.8.7 and > wxWidgets 2.8.10. Is this supposed to be a valid combination? >2.0.1 came out just before Snow Leopard was released, and I think we need to update and rebuild for 10.6 - just haven''t got around to it though I''ve been using 10.6 for a few months. However, this sort of problem would almost certainly show up as big-fail crash on startup, rather than minor behavioural differences.> It seems that, with this combination the GridCellNumberEditor cannot be > properly derived from.I have a feeling that the concrete XXXEditor classes are not fully inheritable from - they are designed as concrete final classes in C++. But I''m not sure about this - will have a go with your sample later today (also looking at your wheel question) and let you know alex
Hi Alex, any news on this issue? I''m still struggling to completely wrap my head around the CellEditors. Right now I''ve managed to get everything working half-way but one issue remains: Leaving the Cell-Editor with Enter. On Windows, this works with normal editors but not with numeric editors. On OSX this doesn''t work at all. Looking up the wxwidgets documentation, I found that there should be a virtual editor method called "handleReturn" (see [1]). Attempts to implement a ruby method handle_return doesn''t yield any result. Can you please advise what would be the best (or any) way to process an enter key and to finalize cell editing? Thanks, Tony [1] http://docs.wxwidgets.org/trunk/classwx_grid_cell_editor.html#265a3c935b3d5c204c8c75149fa0cb74 Alex Fenton wrote:> Tony Meier wrote: >> me again - I''m still struggling with the Grid code. Maybe this is a >> problem with my runtime environment? >> >> I''m using wxruby 2.0.1 on Snow Leopard 10.6.2 using Ruby 1.8.7 and >> wxWidgets 2.8.10. Is this supposed to be a valid combination? >> > > 2.0.1 came out just before Snow Leopard was released, and I think we > need to update and rebuild for 10.6 - just haven''t got around to it > though I''ve been using 10.6 for a few months. > > However, this sort of problem would almost certainly show up as big-fail > crash on startup, rather than minor behavioural differences. > >> It seems that, with this combination the GridCellNumberEditor cannot be >> properly derived from. > > I have a feeling that the concrete XXXEditor classes are not fully > inheritable from - they are designed as concrete final classes in C++. > But I''m not sure about this - will have a go with your sample later > today (also looking at your wheel question) and let you know > > alex-- Posted via http://www.ruby-forum.com/.