The Accidental Rubyist

invalid byte sequence in UTF-8

Messageboxes: List and customized

leave a comment »

Now it is possible to pass a list of items to a messagebox. It will allow scrollable selection from the list as seen below. A list of default (preselected) values may be passed. Select mode of multiple and single may be defined. A list_variable may also be supplied. As its value changes, the listbox will immediately reflect the change.


      @mb = RubyCurses::MessageBox.new do
       title "Enter your name"
       message "Enter your name"
       type :list
       list %w[john tim lee wong rahul edward why chad andy]
       list_select_mode 'multiple'
       default_values %w[ lee why ]
      end
 
Message box from a list

Message box from a list

Fields of any kind may be created, pushed into an array and passed to the messagebox. The message box will display the fields with Ok and Cancel buttons. Thus configuration popups are easy to make.


      @mb = RubyCurses::MessageBox.new do
       title "HTTP Configuration"
       type :field_list
       field_list field_list
       default_button 0
      end
 

field_list is an array containing field defined as fields normally are, but without a form.


      $radio = RubyCurses::Variable.new
      #$radio.update_command(colorlabel) {|tv, label|  label.color tv.value}
      radio1 = RubyCurses::RadioButton.new nil do
        text_variable $radio
        text "ruby"
        value "ruby"
        color "red"
        bgcolor 'white'
        row 9
        col 4
      end
      radio2 = RubyCurses::RadioButton.new nil do
        text_variable $radio
        text  "python"
        value  "python"
        color "blue"
        bgcolor 'white'
        row 10
        col 4
      end
      field_list << radio1
      field_list << radio2
 
A totally customized message box

A totally customized message box

Note: As I create more examples of MessageBoxes, and integrate them with the main demo, there are likely to be some changes in the API of messageboxes.

Advertisements

Written by totalrecall

December 2, 2008 at 2:53 pm

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: