Class: RubyCurses::RadioButton

Inherits:
ToggleButton show all
Defined in:
lib/rbcurse/rwidget.rb

Overview

A selectable button that has a text value. It is based on a Variable that is shared by other radio buttons. Only one is selected at a time, unlike checkbox 2008-11-27 18:45 just made this inherited from Checkbox

Direct Known Subclasses

TabbedButton

Constant Summary

Constants included from Io

Io::ERROR_COLOR_PAIR, Io::FOOTER_COLOR_PAIR, Io::LINEONE, Io::MAIN_WINDOW_COLOR_PAIR

Instance Attribute Summary

Attributes inherited from Widget

#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #parent_component, #row_offset, #rows_panned, #state

Instance Method Summary collapse

Methods inherited from ToggleButton

#checked?, #handle_key

Methods inherited from Button

#action, #bind_hotkey, button_layout, #command, #handle_key, #mnemonic, #repaint, #text

Methods inherited from Widget

#changed, #click, #destroy, #enter, #event_list, #focus, #get_preferred_size, #handle_key, #height, #height=, #hide, #init_vars, #leave, #modified?, #move, #on_enter, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint, #repaint_all, #repaint_required, #rowcol, #set_buffer_modified, #set_buffering, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=

Methods included from Io

#askchoice, #askyesno, #askyesnocancel, #clear_error, #clear_this, #get_string, #newaskyesno, #old_print_header, #old_print_top_right, #print_action, #print_error, #print_footer_help, #print_header, #print_headers, #print_help, #print_help_page, #print_in_middle, #print_key_labels, #print_key_labels_row, #print_screen_labels, #print_status, #print_this, #print_top_right, #rbgetstr, #warn

Methods included from Utils

#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #view, #wrap_text

Methods included from ConfigSetup

#cget, #config_setup, #configure, #variable_set

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Constructor Details

#initialize(form, config = {}, &block) ⇒ RadioButton

if a variable has been defined, off and on value will be set in it (default 0,1)



2603
2604
2605
2606
# File 'lib/rbcurse/rwidget.rb', line 2603

def initialize form, config={}, &block
  @surround_chars = ['(', ')'] if @surround_chars.nil?
  super
end

Instance Method Details

#checked(tf) ⇒ Object

ideally this should not be used. But implemented for completeness. it is recommended to toggle some other radio button than to uncheck this.



2644
2645
2646
2647
2648
2649
2650
# File 'lib/rbcurse/rwidget.rb', line 2644

def checked tf
  if tf
    toggle
  elsif !@variable.nil? and getvalue() != @value # XXX ???
    @variable.set_value "",""
  end
end

#fireObject

added for bindkeys since that calls fire, not toggle - XXX i don’t like this



2636
2637
2638
2639
# File 'lib/rbcurse/rwidget.rb', line 2636

def fire
  @variable.set_value  @value,@name
  super
end

#getvalueObject

all radio buttons will return the value of the selected value, not the offered value



2609
2610
2611
2612
# File 'lib/rbcurse/rwidget.rb', line 2609

def getvalue
  #@text_variable.value
  @variable.get_value @name
end

#getvalue_for_paintObject



2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
# File 'lib/rbcurse/rwidget.rb', line 2614

def getvalue_for_paint
  buttontext = getvalue() == @value ? "o" : " "
  dtext = @display_length.nil? ? text : "%-*s" % [@display_length, text]
  if @align_right
    @text_offset = 0
    @col_offset = dtext.length + @surround_chars[0].length + 1
    return "#{dtext} " + @surround_chars[0] + buttontext + @surround_chars[1] 
  else
    pretext = @surround_chars[0] + buttontext + @surround_chars[1] 
    @text_offset = pretext.length + 1
    @col_offset = @surround_chars[0].length
    return pretext + " #{dtext}"
  end
end

#toggleObject



2629
2630
2631
2632
2633
# File 'lib/rbcurse/rwidget.rb', line 2629

def toggle
  @variable.set_value @value, @name
  # call fire of button class 2008-12-09 17:49 
  fire
end