The saga continues! I have tried linking a grid to a gridtablebase and gotten mixed results but nothing like what i wanted. results have ranged from, nothing to crashing the ruby interpreter. It seems to me you cannot join a GridTableBase to a Grid w/o having data in the GridTableBase first. Is this true? Then, I get an error when I didnt have GetAttr defined in my GridTableBase. HALP! :-D ===GridTableBase class ==========class TimeTableBase < Wx::GridTableBase def initialize(recordset = nil) super() @record_set = recordset end def set_recordset(recordset) @record_set = recordset end def get_number_rows return_value = nil if @record_set != nil return_value = @record_set.count() end return return_value end def get_number_cols return_value = nil if @record_set != nil return_value = @record_set.columns.length end return return_value end def get_col_label_value(col) return col.to_s end def is_empty_cell(row, col) return_value = true cell_value = get_value(row, col) if (cell_value != nil) if cell_value != "" return_value = false end end return return_value end def get_value(row, col) return_value = nil if @record_set != nil begin return_value = @record_set[@record_set.size][row].values[col] rescue end end return return_value end def get_attr(row, col, kind) # "" # Not having this in gave this error: end #main.rb:26:in `get_attr'': in method # GetAttr'', argument 4 of type # wxGridCellAttr::wxAttrKind'' (TypeError) # end =====Frame class =================================class TimeFrame < Wx::Frame def initialize(timefly, title, pos, size, style #Wx::MINIMIZE_BOX | Wx::MAXIMIZE_BOX | Wx::RESIZE_BORDER | Wx::SYSTEM_MENU | Wx::CAPTION | Wx::CLOSE_BOX | Wx::CLIP_CHILDREN) super(nil,-1,title,pos,size,style) @timefly = timefly @database = @timefly.database() ... .... .... @time_grid = Wx::Grid.new(self, -1) #@time_grid_table = nil #@time_grid_table = TimeTableBase.new(recordset) #@time_grid.set_table(@time_grid_table) # <-- this line causes # runtime failure and # simply crashes - no # error code evt_button(30) {|evt| on_go_button_pressed(evt)} end def on_go_button_pressed(evt) timelog = @database[:timelog] sc_date = @sc_date.get_value()#+"/"+@sc_month.get_value()+"/"+@sc_day.get_value() recordset = timelog#.filter(:time_open => sd_date) if recordset != nil @time_grid_table = nil @time_grid_table = TimeTableBase.new(recordset) #@time_grid.set_table(@time_grid_table) # <-- this line causes # runtime failure and # simply crashes - no # error code end end end ==============================================================
EchoB wrote:> I have tried linking a grid to a gridtablebase and gotten mixed results > but nothing like what i wanted. results have ranged from, nothing to > crashing the ruby interpreter. >Please do report crashes, ideally using the bug tracker. Whatever the problem, wxRuby should raise an exception rather than segfault. But we need a complete, self-contained, minimal sample that demonstrates the problem.> It seems to me you cannot join a GridTableBase to a Grid w/o having data > in the GridTableBase first. > Is this true? >Well, whatever your GridTableBase class is, it is obliged to return meaningful values for the required methods (eg get_number_cols, get_number_rows) whatever its internal state. From the code you posted, it seems if the "recordset" is not defined in your GridTable class, it returns nil for those methods. Which it shouldn''t do - at least return 0. As I''ve suggested before, I''m not sure why you''re trying to use GridTableBase rather than just using a straightforward Wx::Grid and calling set_value to populate the table whenever the recordset is changed. It would only really be sensible if your recordset is so huge that filling the table manually is too slow. alex
> Well, whatever your GridTableBase class is, it is obliged to return> meaningful values for the required methods (eg get_number_cols, > get_number_rows) whatever its internal state. From the code you posted, > it seems if the "recordset" is not defined in your GridTable class, it > returns nil for those methods. Which it shouldn''t do - at least return 0. > > As I''ve suggested before, I''m not sure why you''re trying to use > GridTableBase rather than just using a straightforward Wx::Grid and > calling set_value to populate the table whenever the recordset is > changed. It would only really be sensible if your recordset is so huge > that filling the table manually is too slow. Ok. What is the order of operations one should use to define a grid, and then a gridtablebase? My dataset is going to change many times at runtime. Here is the larger picture: My application is a time tracking application, working like a punch clock. So projectIDs, TimeIn, TimeOut, and descriptions can get into the hundreds per week and defiantly per month. I have an Sqlite3 database with Sequel as the abstraction layer retrieving the dataset. I have completed the "data entry" portion of my project. In order for that information to be useful, I need to be able to view it, etc. I am passing Sequel datasets to my derived wxGridTableBase class. The nature of my dataset is that I would like to adjust the dataset on an event driven basis. For example button(s) to switch views between: week summary of hours month summary of hours daily summary of hours etc.. All ordered by projectID. I can handle the sql queries. But I have yet to even be able to successfully link the wxGrid to the wxGridTableBase. I have scoured forums and the wxRuby docs, sample code (BigDemo, etc...), and asked in #wxruby. Google returns results in wxPython, but that doesn''t help me. I guess I just don''t know what I''m doing with it yet. To sum up: 1) What is the best practice or order of operations for defining a wxGrid and then linking it to a wxGridTableBase? 2) Is the linking in #1 possible to do on a runtime event-driven basis? 3) Is there any wxRuby demo code anywhere? Or where can I find more ruby/wxruby ''centric documentation on this class?