More Adventures with Wx::GridTableBase

EchoB
Thu, 21 Feb 2008 19:04:59 -0000

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
==============================================================