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

#col_offset, #cols_panned, #config, #curpos, #ext_col_offset, #ext_row_offset, #form, #id, #parent_component, #row_offset, #rows_panned, #should_create_buffer, #state

Instance Method Summary collapse

Methods inherited from ToggleButton

#checked?, #handle_key

Methods inherited from Button

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

Methods inherited from Widget

#OLDbind_key, #buffer_to_screen, #buffer_to_window, #create_buffer, #destroy, #destroy_buffer, #focus, #get_buffer, #get_color, #get_preferred_size, #handle_key, #height, #height=, #hide, #init_vars, #is_double_buffered?, #modified?, #move, #on_enter, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint, #repaint_all, #repaint_required, #rowcol, #safe_create_buffer, #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

Methods included from Utils

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

Methods included from ConfigSetup

#cget, #config_setup, #configure, #variable_set

Methods included from EventHandler

#bind, #fire_handler, #fire_property_change

Methods included from DSL

#OLD_method_missing

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)



2521
2522
2523
2524
# File 'lib/rbcurse/rwidget.rb', line 2521

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.



2557
2558
2559
2560
2561
2562
2563
# File 'lib/rbcurse/rwidget.rb', line 2557

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



2550
2551
2552
2553
# File 'lib/rbcurse/rwidget.rb', line 2550

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



2526
2527
2528
2529
# File 'lib/rbcurse/rwidget.rb', line 2526

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

#getvalue_for_paintObject



2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
# File 'lib/rbcurse/rwidget.rb', line 2530

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



2544
2545
2546
2547
2548
# File 'lib/rbcurse/rwidget.rb', line 2544

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