Hi WxSugar 0.1.15 is now available via gems and download from rubyforge. This is a minor feature release which adds a couple of new facilities: * enumerable_controls: treats ListCtrl and ControlWithItems classes, such as ComboBox, ListBox, CheckListBox as Ruby enumerables * adds Window#has_style? The former is meant to give much more rubyish access to the contents of GUI controls which present the user with a list of item to choose from: # basic iteration listbox.each { | i | puts listbox.string(i) } # iterate with string labels listbox.each | i, string, data | puts "Item #{string} is at position #{i}, and has client data #{data}" end # access strings and item data as arrays puts listbox.strings[1] # Retrieve the label at position 1 # add a string listbox << ''foo'' # search list contents idx = listbox.index(''foo'') # finds the position of the item labelled ''foo'' idx = listbox.index(foo) # find the position of the item with data foo # enumerable methods listbox.select { | i | listbox.checked?(i) } These are meant as experimental methods - feedback welcome. a
Woot on enumerable_controls, that''s going to make my life way easier :) On 4/3/07, Alex Fenton <alex at pressure.to> wrote:> Hi > > WxSugar 0.1.15 is now available via gems and download from rubyforge. > > This is a minor feature release which adds a couple of new facilities: > > * enumerable_controls: treats ListCtrl and ControlWithItems classes, > such as ComboBox, ListBox, CheckListBox as Ruby enumerables > * adds Window#has_style? > > The former is meant to give much more rubyish access to the contents of > GUI controls which present the user with a list of item to choose from: > > # basic iteration > listbox.each { | i | puts listbox.string(i) } > > # iterate with string labels > listbox.each | i, string, data | > puts "Item #{string} is at position #{i}, and has client data #{data}" > end > > # access strings and item data as arrays > puts listbox.strings[1] # Retrieve the label at position 1 > > # add a string > listbox << ''foo'' > > # search list contents > idx = listbox.index(''foo'') # finds the position of the item labelled ''foo'' > idx = listbox.index(foo) # find the position of the item with data foo > > # enumerable methods > listbox.select { | i | listbox.checked?(i) } > > These are meant as experimental methods - feedback welcome. > > a > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-- -Phil <><
Apparently Analagous Threads
- [946] trunk/wxsugar/samples/sugar-sample.rb: Illustrate enumerable_controls and has_style
- [937] trunk/wxsugar/lib/wx_sugar/enumerable_controls.rb: Initial commit of enumerable_controls.rb
- [938] trunk/wxsugar/lib/wx_sugar/wx_classes: Enable enumerable_controls for ListCtrl and ControlWithItems family
- Bug? in wxSugar enumerable_controls.rb
- [945] trunk/wxsugar/lib/wx_sugar.rb: Add note about enumerable_controls, reorder list of extensions