I''m having a problem inserting a row in a Grid under Windows. The following stripped-down program illustrated the problem: ---------------------------------------------- require ''rubygems'' require ''wx'' include Wx class TestApp < App def on_init frame = Frame.new(nil, -1, "Application") panel = Panel.new(frame) @grid = Grid.new(panel) @grid.create_grid(1, 2) sizer = BoxSizer.new(VERTICAL) sizer.add(@grid, 1, GROW|ALL, 2) panel.set_sizer(sizer) evt_grid_cell_change do |evt| row = evt.get_row @grid.insert_rows(row, 1) end frame.show(TRUE) end end TestApp.new.main_loop ---------------------------------------------- The intent is to add a new row when one enters data in the last empty row, but when data is entered into a cell in the last row, the program crashes: C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `process_event'': stack level too deep (SystemStackError) from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `__insert_rows'' from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `insert_rows'' from x.rb:19:in `on_init'' from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `call'' from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `process_event'' from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `__insert_rows'' from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `insert_rows'' from x.rb:19:in `on_init'' ... 18546 levels... from x.rb:26:in `process_event'' from x.rb:26:in `on_run'' from x.rb:26:in `main_loop'' from x.rb:26 It looks like insert_rows is getting invoked recursively. The same program works fine under FreeBSD, but I think I have an older (pre-wxruby2) version installed. -- Will Parsons
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 04.06.2011 20:49, schrieb Will Parsons:> I''m having a problem inserting a row in a Grid under Windows. The following > stripped-down program illustrated the problem: > > ---------------------------------------------- > require ''rubygems'' > require ''wx'' > > include Wx > > class TestApp < App > def on_init > frame = Frame.new(nil, -1, "Application") > panel = Panel.new(frame) > @grid = Grid.new(panel) > @grid.create_grid(1, 2) > > sizer = BoxSizer.new(VERTICAL) > sizer.add(@grid, 1, GROW|ALL, 2) > panel.set_sizer(sizer) > > evt_grid_cell_change do |evt| > row = evt.get_row > @grid.insert_rows(row, 1) > end > > frame.show(TRUE) > end > end > > TestApp.new.main_loop > ---------------------------------------------- > > The intent is to add a new row when one enters data in the last empty row, > but when data is entered into a cell in the last row, the program crashes: > > C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `process_event'': stack level too deep (SystemStackError) > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `__insert_rows'' > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `insert_rows'' > from x.rb:19:in `on_init'' > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `call'' > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `process_event'' > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `__insert_rows'' > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `insert_rows'' > from x.rb:19:in `on_init'' > ... 18546 levels... > from x.rb:26:in `process_event'' > from x.rb:26:in `on_run'' > from x.rb:26:in `main_loop'' > from x.rb:26 > > It looks like insert_rows is getting invoked recursively. The same program > works fine under FreeBSD, but I think I have an older (pre-wxruby2) version > installed. >I''d say that inserting a row causes a EVT_GRID_CELL_CHANGE event, effectively calling your event handler again, which in turn issues a new EVT_GRID_CELL_CHANGE, causing your event handler to be triggered once again, causing... ad infinitum. You may be able to prevent this by setting an instance variable and checking it''s value before trying to insert a row. Vale, Marvin -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJN62hZAAoJELh1XLHFkqhaRo8IAK8MDLwu3kPMJsCVxJ2AMpcN yKSu46kGbf2wqvi8EthZhLjeGsjwciYvIUGRK5eZ0hcKrweCAYGroUggGwtxKJWp Wd24RwZzR09Q/B1ErFHIPcMgj+0lo6uWOsV7lq2rIMigMMwGbkRc6VVPoUDSyyc0 rFn3DwU6L5NfyYrSJggodLep6XDUvcaWWvIJW+Afuy3b/awAQkxw5rQbbteB44Nf NN/aGcJD7B9ttl6qz0eWeGcPDaBWV1FUSzV+CCGpzsPcL1Kcg1IBTlYXmA2m8WQ8 jPPZRzNCXzedeK0CifnURK26dZsBwGEpU9Q8B/GFeGMvBt7TB88RHRwuxisfDWI=28vx -----END PGP SIGNATURE-----
On Sun, 05 Jun 2011 13:28:37 +0200, Quintus <sutniuq at gmx.net> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Am 04.06.2011 20:49, schrieb Will Parsons: > > I''m having a problem inserting a row in a Grid under Windows. The following > > stripped-down program illustrated the problem: > > > > ---------------------------------------------- > > require ''rubygems'' > > require ''wx'' > > > > include Wx > > > > class TestApp < App > > def on_init > > frame = Frame.new(nil, -1, "Application") > > panel = Panel.new(frame) > > @grid = Grid.new(panel) > > @grid.create_grid(1, 2) > > > > sizer = BoxSizer.new(VERTICAL) > > sizer.add(@grid, 1, GROW|ALL, 2) > > panel.set_sizer(sizer) > > > > evt_grid_cell_change do |evt| > > row = evt.get_row > > @grid.insert_rows(row, 1) > > end > > > > frame.show(TRUE) > > end > > end > > > > TestApp.new.main_loop > > ---------------------------------------------- > > > > The intent is to add a new row when one enters data in the last empty row, > > but when data is entered into a cell in the last row, the program crashes: > > > > C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `process_event'': stack level too deep (SystemStackError) > > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `__insert_rows'' > > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `insert_rows'' > > from x.rb:19:in `on_init'' > > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `call'' > > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `process_event'' > > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `__insert_rows'' > > from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `insert_rows'' > > from x.rb:19:in `on_init'' > > ... 18546 levels... > > from x.rb:26:in `process_event'' > > from x.rb:26:in `on_run'' > > from x.rb:26:in `main_loop'' > > from x.rb:26 > > > > It looks like insert_rows is getting invoked recursively. The same program > > works fine under FreeBSD, but I think I have an older (pre-wxruby2) version > > installed.Yes, but I''m not sure why it should. IOW this looks to me like a bug in wxruby, especially since this didn''t happen on the older wxruby. (I''m assuming the operative difference is between wxruby v1 vs. v2 rather than FreeBSD vs. Windows.)> I''d say that inserting a row causes a EVT_GRID_CELL_CHANGE event, > effectively calling your event handler again, which in turn issues a new > EVT_GRID_CELL_CHANGE, causing your event handler to be triggered once > again, causing... ad infinitum. > > You may be able to prevent this by setting an instance variable and > checking it''s value before trying to insert a row.Good suggestion - I''ll look into doing that. Gratias ago.> Vale, > MarvinEt valeas tu. -- Will Parsons
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Am 05.06.2011 20:55, schrieb Will Parsons:> On Sun, 05 Jun 2011 13:28:37 +0200, Quintus <sutniuq at gmx.net> wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> Am 04.06.2011 20:49, schrieb Will Parsons: >>> I''m having a problem inserting a row in a Grid under Windows. The following >>> stripped-down program illustrated the problem: >>> >>> ---------------------------------------------- >>> require ''rubygems'' >>> require ''wx'' >>> >>> include Wx >>> >>> class TestApp < App >>> def on_init >>> frame = Frame.new(nil, -1, "Application") >>> panel = Panel.new(frame) >>> @grid = Grid.new(panel) >>> @grid.create_grid(1, 2) >>> >>> sizer = BoxSizer.new(VERTICAL) >>> sizer.add(@grid, 1, GROW|ALL, 2) >>> panel.set_sizer(sizer) >>> >>> evt_grid_cell_change do |evt| >>> row = evt.get_row >>> @grid.insert_rows(row, 1) >>> end >>> >>> frame.show(TRUE) >>> end >>> end >>> >>> TestApp.new.main_loop >>> ---------------------------------------------- >>> >>> The intent is to add a new row when one enters data in the last empty row, >>> but when data is entered into a cell in the last row, the program crashes: >>> >>> C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `process_event'': stack level too deep (SystemStackError) >>> from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `__insert_rows'' >>> from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `insert_rows'' >>> from x.rb:19:in `on_init'' >>> from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `call'' >>> from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `process_event'' >>> from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `__insert_rows'' >>> from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in `insert_rows'' >>> from x.rb:19:in `on_init'' >>> ... 18546 levels... >>> from x.rb:26:in `process_event'' >>> from x.rb:26:in `on_run'' >>> from x.rb:26:in `main_loop'' >>> from x.rb:26 >>> >>> It looks like insert_rows is getting invoked recursively. The same program >>> works fine under FreeBSD, but I think I have an older (pre-wxruby2) version >>> installed. > > Yes, but I''m not sure why it should. IOW this looks to me like a bug in > wxruby, especially since this didn''t happen on the older wxruby. (I''m > assuming the operative difference is between wxruby v1 vs. v2 rather than > FreeBSD vs. Windows.)wxRuby (or at least wxWidgets) sometimes behaves a little different on Windows, especially regarding events. The most recent case I experienced was a TreeCtrl getting an EVT_SELECTION_CHANGED event during application startup, which it doesn''t get on Linux. Both systems used wxRuby 2.0.1.>> I''d say that inserting a row causes a EVT_GRID_CELL_CHANGE event, >> effectively calling your event handler again, which in turn issues a new >> EVT_GRID_CELL_CHANGE, causing your event handler to be triggered once >> again, causing... ad infinitum. >> >> You may be able to prevent this by setting an instance variable and >> checking it''s value before trying to insert a row. > > Good suggestion - I''ll look into doing that. Gratias ago.Adiuvare mihi gaudium est. ;-)>> Vale, >> Marvin > > Et valeas tu. >Si vales, bene est, ego quidem valeo. (I think it was the younger Pliny always shortening this to SVBEEQV). But the times I was used to Latin are gone now, hopefully the few phrases above are gramicatically correct ;-) Nevertheless I like Latin for being able to understand some phrases in Spanish, Italian or even English I''ve never encountered before (I''m from Germany). And, of course, being able to read (at least with a bit of efford of reactivating old knowledge) these *really* old texts is just cool. Vale, Marvin alias Quintus -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBAgAGBQJN7P5BAAoJELh1XLHFkqhaUk0H/0DOfWGx/VaE56X2UJFt3ylH hw5/apXeWxKnTal80L2+bqF9/yNg14qjYZCJEBJ6nJ54Eh/DggTKN1jAkg5Fz+5Y lM5/O3VQKYUgs14hLMEZSRykIL5p4tZAxXbC4MOxrwNE1FhiUrGlIZ3esBH4MoL4 xE/jg4ydXuWiOUw+KNjPd7NOMAGQ9zDWy2kA7Ku2hjUyM4ttnACYyQki2DFISm97 1yhz4pCYzO0JyJiJ1pslXtbop2XACW/nyqqddgt0HlMhdfzpqOffnyUnjH5rducg 2XXjLXuFsyNJ9JMgsEm98/p0Vrs+lqlLSEsvDZnaQSKeDjJCSJT86rogdMiXI5Y=1kQB -----END PGP SIGNATURE-----