Chauk-Mean P
2007-Oct-23 13:18 UTC
[wxruby-development] CheckListBox : delete method bug !
Hi,
I''ve practically finished a patch for removing the limitation of
CheckListBox
(http://rubyforge.org/pipermail/wxruby-development/2007-October/000973.html)
but I just discovered a new bug related with this control !!
I need to redefine the delete method to take into account the deletion
of the associated data. The problem is that if I just redefine this
method and simply call super, the control doesn''t work anymore !
Here is a sample code that shows the problem (for wxRuby 1.9.1 with
some copy/paste of wxRuby 1.9.2 for convenience). I''m running on
Windows 2000.
require "wx"
######################################
# Copy/Paste of wxRuby 1.9.2 additions
class Wx::App
def self.run(&block)
app_klass = Class.new(self)
app_klass.class_eval do
define_method(:on_init, &block)
end
the_app = app_klass.new
the_app.main_loop
end
end
class Wx::CommandEvent
alias :get_index :get_int
end
# End of Copy/Paste of wxRuby 1.9.2 additions
#############################################
class Wx::CheckListBox
# if the following method is defined, some items cannot be checked !
def delete n
super
end
end
Wx::App.run do
helloframe = Wx::Frame.new(nil, :title => "CheckListBox Sample")
do |frame|
lb = Wx::CheckListBox.new(frame) do |c|
# use of append within the initializer
0.upto(3) { |i| c.append "item#{i+1}" }
end
evt_listbox lb.wx_id do |event|
lb.delete event.index
end
end
helloframe.show
end
---------------
If I run the application, and if I select the "item2", this item is
deleted as expected.
But afterwards, "item4" cannot be checked.
If I just remove/comment the delete method within the Wx::CheckListBox
class, everything is OK and I can check/uncheck all items as expected
after the deletion.
I don''t know if it is a wxRuby or a wxWidgets problem, but given all
issues I discovered with CheckListBox, I had the impression that this
control is a second class citizen.
Cheers.
Chauk-Mean.
Chauk-Mean P wrote:> I''ve practically finished a patch for removing the limitation of > CheckListBoxThanks for following this up.> I need to redefine the delete method to take into account the deletion > of the associated data. The problem is that if I just redefine this > method and simply call super, the control doesn''t work anymore !The problem here is that you should not be calling super, but rather the old definition of ''delete'' in CheckListBox. If you call super you''re calling ControlWithItems#delete, which probably misses some specific code in wxCLB to deal with deleting. The following code works for me (and will also avoid warnings): class Wx::CheckListBox alias :__wx_delete :delete define_method(:delete) do | n | __wx_delete(n) end end cheers alex
Alex Fenton wrote:> class Wx::CheckListBox > alias :__wx_delete :delete > define_method(:delete) do | n | > __wx_delete(n) > end > endPS - or an alternative, commonly used in the ruby part of core wxRuby - eg bitmap.rb class Wx::CheckListBox __wx_delete = self.instance_method(:delete) define_method(:delete) do | n | __wx_delete.bind(self).call(n) end end The advantage of this is that it avoids cluttering the method table with additional aliased methods. cheers alex
Chauk-Mean P
2007-Oct-23 13:50 UTC
[wxruby-development] CheckListBox : delete method bug !
Alex, 2007/10/23, Alex Fenton <alex at pressure.to>:> The problem here is that you should not be calling super, but rather the > old definition of ''delete'' in CheckListBox. If you call super you''re > calling ControlWithItems#delete, which probably misses some specific > code in wxCLB to deal with deleting. The following code works for me > (and will also avoid warnings):You''re right. This works. I''m glad that this was not a CheckListBox issue :-). I''m gonna attach the patch files with the other message. Cheers. Chauk-Mean.