Is there any sample code around that sorts a virtual listctrl?
I have loaded data into a ListCtrl and set things up so that if I
click on a column heading on_col_left_click(event) gets called and it
in turn sorts / reverses the sort of that column. I am printing out
the data for debugging purposes so I know that my internal data
representation is getting sorted but I nothing is getting updated in
my window.
The docs talk about using refresh_item(int) and refresh_items
(start_int, end_int) to update the display but I''m getting an error
message of:
plekdb.rb:80:in `on_col_left_click'': undefined method
`refresh_item''
for #<DbViewer:0x6e1098> (NoMethodError)
I''ve no clue about what I''m missing and haven''t been
able to find
anything helpful in the wxRuby sample code, the wxPython sample code,
or the Cross-Platform GUI Programming with wxWidgets book (which I
have access to online through safari)
I also don''t understand what I should be returning if the ListCtrl
requests more rows than I have data for... right now I''m returning
"
" and ending up with blank lines in my table, but that seems rather
inelegant.
I''ll post / send some sample code for sorting / displaying from a
separate data source once I have it working and maybe you can add it
to the samples library.... I''d expect that being able to quickly whip
up a cross platform data viewer is a popular reason to use wxRuby.
-Hawley
-------------------
def on_col_left_click(event)
@log.write_text("col clicked, id=%d" % event.get_column())
if @sort_column == event.get_column()
@the_data.reverse!
else
@sort_column = event.get_column()
@the_data.sort! {|a,b| a[@sort_column]<=>b[@sort_column]}
end
@the_data.each do |d|
@log.write_text( "%s %s" % [d[0], d[4]]) ## just sorting
on the d[4] column while debugging
end
refresh_item(0)
#ensure_visible(0)
end
#---------------------------------------------------
# These methods are callbacks for implementing the
# "virtualness" of the list... Normally you would
# determine the text, attributes and/or image based
# on values from some external data source, but for
# this demo we''ll just calculate them
def on_get_item_text(item, col)
#return "Item %d, column %d" % [item,col]
begin#
return @the_data[item][col]
rescue
return " "
end
end
--------------------------------------------------------------
Hi Hawley Hawley Waldman wrote:> The docs talk about using refresh_item(int) and refresh_items > (start_int, end_int) to update the display but I''m getting an error > message of: > plekdb.rb:80:in `on_col_left_click'': undefined method `refresh_item'' > for #<DbViewer:0x6e1098> (NoMethodError) >Thanks very much for the report. Turns out that refresh_item(s) methods were missing from our wx header files, and so from the ruby API. I''ve fixed this in SVN and they now work as described.> I also don''t understand what I should be returning if the ListCtrl > requests more rows than I have data for... right now I''m returning " > " and ending up with blank lines in my table, but that seems rather > inelegant. >Are you using "set_item_count(@data.length)" to tell the ListCtrl how many data items you have? http://wxruby.rubyforge.org/doc/listctrl.html#ListCtrl_setitemcount> I''ll post / send some sample code for sorting / displaying from a > separate data source once I have it working and maybe you can add it > to the samples library.... I''d expect that being able to quickly whip > up a cross platform data viewer is a popular reason to use wxRuby. >We''d be pleased to add it. I agree that with these fixes the virtual ListCtrl seems a nice & versatile feature. alex
Thanks Alex, I''ll checkout the new version. I installed wxRuby (preview) as a gem and frankly my brain is preoccupied with the two guitars and a bass that I need to finish building by Tuesday, but I''d also like to have this little display thing done before I leave town with these instruments so could you please post here / email me off list with how to get and use the updated version? Sorry that I''m so brain dead right now, I haven''t had a day off since the 1st because of the preparations for this trade show. Sincerely, Hawley On 1/14/07, Alex Fenton <alex at pressure.to> wrote:> > Hi Hawley > > Hawley Waldman wrote: > > The docs talk about using refresh_item(int) and refresh_items > > (start_int, end_int) to update the display but I''m getting an error > > message of: > > plekdb.rb:80:in `on_col_left_click'': undefined method `refresh_item'' > > for #<DbViewer:0x6e1098> (NoMethodError) > > > Thanks very much for the report. Turns out that refresh_item(s) methods > were missing from our wx header files, and so from the ruby API. I''ve > fixed this in SVN and they now work as described. > > I also don''t understand what I should be returning if the ListCtrl > > requests more rows than I have data for... right now I''m returning " > > " and ending up with blank lines in my table, but that seems rather > > inelegant. > > > Are you using "set_item_count(@data.length)" to tell the ListCtrl how > many data items you have? > > http://wxruby.rubyforge.org/doc/listctrl.html#ListCtrl_setitemcount > > I''ll post / send some sample code for sorting / displaying from a > > separate data source once I have it working and maybe you can add it > > to the samples library.... I''d expect that being able to quickly whip > > up a cross platform data viewer is a popular reason to use wxRuby. > > > We''d be pleased to add it. I agree that with these fixes the virtual > ListCtrl seems a nice & versatile feature. > > alex > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/wxruby-users/attachments/20070114/b99f2b49/attachment.html
Hawley Waldman wrote:> could you please post here / email me off list with how to get and use > the updated version?You''ll need to checkout from SVN and build from source. See here: http://wxruby.rubyforge.org/wiki/wiki.pl?Installation and possibly here, if you haven''t installed wxWidgets before: http://wxruby.rubyforge.org/wiki/wiki.pl?Release_HowTo If you already have SWIG and wxWidgets and a compiler, it''s svn checkout svn://rubyforge.org/var/svn/wxruby/trunk/wxruby2 cd wxruby2 rake rake install alex