Hi all, Here is an excerpt of code (with the new syntax from upcoming wxRuby 1.9.2) : evt_checklistbox(my_checklist, :on_checklistbox) evt_listbox(my_checklist, :on_listbox) evt_listbox(my_list, :on_listbox) def on_checklistbox(event) checklist = event.event_object # puts "listbox - event : item[#{event.int}] checked : #{event.checked?}" puts "listbox - event : item[#{event.selection}] checked : #{checklist.checked?(event.selection)}" end def on_listbox(event) puts "listbox - event : item[#{event.selection}] ''#{event.string}'' - selected : #{event.selection?}" end my_checklist is a CheckListBox and my_list is a ListBox. - Trouble 1 : When I select AND when I unselect an item in my_checklist or my_list, the on_listbox is called and displays : - the index (through event.selection) and the text (through event.string) of the item both when the item is selected AND when the item is unselected. - one can know if an item is actually selected through the event.selection? (or is_selection) call. This is fine and this is what I expect but the wxRuby documentation states that : "CommandEvent#get_selection Integer get_selection() Returns item index for a listbox or choice selection event (not valid for a deselection). CommandEvent#get_string String get_string() Returns item string for a listbox or choice selection event (not valid for a deselection)." => Question : The documentation contradicts the actual behaviour which I find correct. Is the documentation incorrect ? - Troubles 2 & 3 : When I check and when I uncheck an item in my_checklist, the on_checklistbox is called and displays : - the index (through event.int or event.selection) of the item that is checked or unchecked. - event.checked? doesn''t tell whether the item is checked or not (see the ommented line). I had to go through the CheckListBox object and calls checked? with the index (see the uncommented line). => Question : The wxRuby documentation states that : "CommandEvent#get_int Integer get_int() Returns the integer identifier corresponding to a listbox, choice or radiobox selection (only if the event was a selection, not a deselection), or a boolean value representing the value of a checkbox." Are int and selection synonyms or is one of them is the normal way for accessing the index of a checked/unchecked item from a CheckListBox ? Again the doc is not clear as int is expected to work only for a selection and not the deselection. => Other question : Is there a bug that makes checked? not working for an event of CheckListBox ? Sorry for this long post. Cheers. Chauk-Mean.
Alex Fenton
2007-Sep-20 11:29 UTC
[wxruby-users] Troubles with ListBox and CheckListBox events
Chauk-Mean P wrote: ...> the wxRuby documentation states that : > "CommandEvent#get_selection > Integer get_selection() > Returns item index for a listbox or choice selection event (not valid > for a deselection). >...> The documentation contradicts the actual behaviour which I find correct. > Is the documentation incorrect ? >On Win32 I see the same as you, ie the desirable behaviour that these work whether it''s a selection or a deselection, and also whether multiple selections are permitted (see the doc for get_extra_long). But the current wxWidgets documentation [1] still has the statement about GetSelection and GetString being invalid for deselections. I don''t know whether this is a wxWidgets doc error, or a warning that this is not guaranteed across platforms. Which have you tested on?> - event.checked? doesn''t tell whether the item is checked or not > (see the ommented line). I had to go through the CheckListBox object > and calls checked? with the index (see the uncommented line). >I took a look at the way wxWidgets implements this, and CommandEvent#is_checked is only meant to work with (a single) CheckBox - it will not work with a CheckListBox. To be fair, the docs do state this, but rather subtly. So for a CheckListBox it must be done by calling the Window''s checked? method, as you have done.> Are int and selection synonyms or is one of them is the normal way for > accessing the index of a checked/unchecked item from a CheckListBox ? > Again the doc is not clear as int is expected to work only for a > selection and not the deselection. >Yes, they are synonyms and the C++ methods do the same thing internally. I would be inclined to deprecate one but I find both names a bit inadequate, since get_selection may be returning the id of an item being checked or unchecked, not selected. The is_selection method does disambiguate these correctly though. As with much of the docs we inherited from Wx it''s doubtless comprehensive and mostly accurate but also a bit short on the overall picture for each class. Happily it''s easy to patch the wxRuby docs... alex [1] http://www.wxwidgets.org/manuals/stable/wx_wxcommandevent.html#wxcommandeventgetselection
Chauk-Mean P
2007-Sep-20 12:03 UTC
[wxruby-users] Troubles with ListBox and CheckListBox events
2007/9/20, Alex Fenton <alex at pressure.to>:> Chauk-Mean P wrote: > > ... > > the wxRuby documentation states that : > > "CommandEvent#get_selection > > Integer get_selection() > > Returns item index for a listbox or choice selection event (not valid > > for a deselection). > > > ... > > The documentation contradicts the actual behaviour which I find correct. > > Is the documentation incorrect ? > > > On Win32 I see the same as you, ie the desirable behaviour that these > work whether it''s a selection or a deselection, and also whether > multiple selections are permitted (see the doc for get_extra_long).I don''t understand the added value of get_extra_long as is_selection gives the same information.> > But the current wxWidgets documentation [1] still has the statement > about GetSelection and GetString being invalid for deselections. I don''t > know whether this is a wxWidgets doc error, or a warning that this is > not guaranteed across platforms. Which have you tested on?I understand. I''m running on Win32.> > - event.checked? doesn''t tell whether the item is checked or not > > (see the ommented line). I had to go through the CheckListBox object > > and calls checked? with the index (see the uncommented line). > > > I took a look at the way wxWidgets implements this, and > CommandEvent#is_checked is only meant to work with (a single) CheckBox - > it will not work with a CheckListBox. To be fair, the docs do state > this, but rather subtly. So for a CheckListBox it must be done by > calling the Window''s checked? method, as you have done.OK even if it''s a pity :-).> > Are int and selection synonyms or is one of them is the normal way for > > accessing the index of a checked/unchecked item from a CheckListBox ? > > Again the doc is not clear as int is expected to work only for a > > selection and not the deselection. > > > Yes, they are synonyms and the C++ methods do the same thing internally.OK.> I would be inclined to deprecate one but I find both names a bit > inadequate, since get_selection may be returning the id of an item being > checked or unchecked, not selected. The is_selection method does > disambiguate these correctly though.If agree. For a "selection event", selection is meaningful. For a "check event", both int and selection are not appropriate. I would propose to add the more general name index (get_index) which is both meaningful for a selection and a check. Thus, the same method may be used for the two kinds of event. selection and int methods may be kept for "compatibility reasons" with wxWidgets.> > As with much of the docs we inherited from Wx it''s doubtless > comprehensive and mostly accurate but also a bit short on the overall > picture for each class. Happily it''s easy to patch the wxRuby docs...It would be great if wxRuby doc clarifies these subtle things. Chauk-Mean.
Alex Fenton
2007-Sep-20 13:01 UTC
[wxruby-users] Troubles with ListBox and CheckListBox events
Chauk-Mean P wrote:> 2007/9/20, Alex Fenton <alex at pressure.to>: > >> But the current wxWidgets documentation [1] still has the statement >> about GetSelection and GetString being invalid for deselections. I don''t >> know whether this is a wxWidgets doc error, or a warning that this is >> not guaranteed across platforms. Which have you tested on? >> > > I understand. I''m running on Win32. >I''ll try on Linux later, but don''t have a OS X machine at the moment.>> I would be inclined to deprecate one but I find both names a bit >> inadequate, since get_selection may be returning the id of an item being >> checked or unchecked, not selected. The is_selection method does >> disambiguate these correctly though. >> > > If agree. For a "selection event", selection is meaningful. > For a "check event", both int and selection are not appropriate. > > I would propose to add the more general name index (get_index) which > is both meaningful for a selection and a check.Yes, that was my first thought for a name for such a method.> It would be great if wxRuby doc clarifies these subtle things. >It would. We do try and write overviews, eg the recently updated event handling one*. The focus of the small dev team is naturally enough on the core library right now; small contributions to the docs are thus really welcome. cheers alex * http://wxruby.rubyforge.org/svn/trunk/wxruby2/doc/textile/eventhandlingoverview.txtl
Chauk-Mean P
2007-Sep-20 13:50 UTC
[wxruby-users] Troubles with ListBox and CheckListBox events
2007/9/20, Alex Fenton <alex at pressure.to>:> > It would be great if wxRuby doc clarifies these subtle things. > > > It would. We do try and write overviews, eg the recently updated event > handling one*. The focus of the small dev team is naturally enough on > the core library right now; small contributions to the docs are thus > really welcome. >I will be glad to contribute to the documentation. Can you give me a link to a HOW TO for contributing to the doc. Cheers. Chauk-Mean.
Alex Fenton
2007-Sep-20 14:33 UTC
[wxruby-users] Troubles with ListBox and CheckListBox events
Chauk-Mean P wrote:> I will be glad to contribute to the documentation. > Can you give me a link to a HOW TO for contributing to the doc. >Thank you. I quickly put together this page: http://wxruby.rubyforge.org/wiki/wiki.pl?DocumentingWxRuby Alex
Alex Fenton
2007-Sep-20 21:57 UTC
[wxruby-users] Troubles with ListBox and CheckListBox events
Chauk-Mean P wrote:> 2007/9/20, Alex Fenton <alex at pressure.to>: > >> But the current wxWidgets documentation [1] still has the statement >> about GetSelection and GetString being invalid for deselections. I don''t >> know whether this is a wxWidgets doc error, or a warning that this is >> not guaranteed across platforms. Which have you tested on? >> > > I understand. I''m running on Win32. >I just tried this out on Linux/GTK and indeed get_selection and get_string are empty when it''s a deselection event. So wxWidget''s docs are correct and you shouldn''t rely on this working if you want to use this cross-platform. Also committed the get_index alias to core alex
Chauk-Mean P
2007-Sep-20 22:26 UTC
[wxruby-users] Troubles with ListBox and CheckListBox events
2007/9/20, Alex Fenton <alex at pressure.to>:> > I just tried this out on Linux/GTK and indeed get_selection and > get_string are empty when it''s a deselection event. So wxWidget''s docs > are correct and you shouldn''t rely on this working if you want to use > this cross-platform. >Thanks for the information.> Also committed the get_index alias to coreThat''s great. Chauk-Mean.