The Accidental Rubyist

invalid byte sequence in UTF-8

Comboboxes (editable)

leave a comment »

If a ComboBox is declared as editable, the edit box inserts the entered values as per insert_policy:

  • NO_INSERT
  • INSERT_AT_BOTTOM
  • INSERT_AT_TOP
  • INSERT_AT_CURRENT
  • INSERT_AFTER_CURRENT
  • INSERT_BEFORE_CURRENT

Events are fired appropriately: INTERVAL_ADDED, CONTENTS_CHANGED, INTERVAL_REMOVED as per this link (Contents Changed ). See the demo: testcombo.rb on github. In order to bind events, a listmodel has been created and bound.


      policies = [:NO_INSERT, :INSERT_AT_TOP, :INSERT_AT_BOTTOM,
        :INSERT_AT_CURRENT, :INSERT_BEFORE_CURRENT, :INSERT_AFTER_CURRENT]

      policies.each do |policy|
          name="combo#{r}"

          list = ListDataModel.new( %w[spotty tiger secret pass torvalds qwerty quail toiletry])
          list.bind(:LIST_DATA_EVENT, name) { |lde,n| $results.value = lde.to_s[0,70]; $log.debug " STA: #{$results} #{lde}"  }

        ComboBox.new @form do
          name name
          row r
          col 30
          display_length 10
          bgcolor 'cyan'
          editable true
          list_data_model list
          insert_policy policy
          set_label Label.new @form, {'text' => "Combo: "+policy.to_s}
        end
        r+=1
      end
 

In case you are wondering what $result is, its a Variable linked to a Label. Changing the value, updates the label.

editable comboboxes

editable comboboxes


      $results = Variable.new
      $results.value = "Event"
      var = RubyCurses::Label.new @form, {'text_variable' => $results, "row" => 22, "col" => 2}
 

Issues: In the edit box, pressing a key, updates the field with the next matching value from the list. However, I’ve forgotten to do this in the popup/Listbox. Should be implemented in a day.

Advertisements

Written by totalrecall

December 18, 2008 at 1:24 am

Posted in ncurses, rbcurse, ruby

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: