Class: Canis::RadioButton

Inherits:
ToggleButton show all
Defined in:
lib/canis/core/widgets/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 text is the value to display, which can include an ampersand for a hotkey value is the value returned if selected, which usually is similar to text (or a short word) width is helpful if placing the brackets to right of text, used to align round brackets

By default, radio buttons place the button on the left of the text.

Typically, the variable’s update_command is passed a block to execute whenever any of the radiobuttons of this group is fired.

Since:

  • 1.2.0

Direct Known Subclasses

TabButton

Instance Attribute Summary

Attributes inherited from Widget

#_object_created, #col_offset, #config, #curpos, #focussed, #form, #handler, #id, #key_label, #parent_component, #row_offset, #state

Instance Method Summary collapse

Methods inherited from ToggleButton

#checked?, #handle_key

Methods inherited from Button

#action, #bind_hotkey, button_layout, #command, #default_button, #handle_key, #map_keys, #mnemonic, #repaint, #selected?, #text

Methods inherited from Widget

#action_manager, #bgcolor, #color, #color_pair, #command, #destroy, #focus, #focusable, #focusable?, #handle_key, #hide, #init_vars, #modified?, #move, #on_enter, #on_leave, #override_graphic, #process_key, #property_set, #remove, #repaint, #repaint_all, #repaint_required, #rowcol, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #unbind_key

Methods included from Io

#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rb_getstr, #warn

Methods included from Utils

#ORIG_process_key, #ORIGbind_key, #ORIGkeycode_tos, #_process_key, #bind_composite_mapping, #bind_key, #bind_keys, #check_composite_mapping, #create_logger, #define_key, #define_prefix_command, #execute_mapping, #get_attrib, #get_color, #key, #key_tos, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #xxxbind_composite_mapping

Methods included from ConfigSetup

#config_setup, #variable_set

Methods included from EventHandler

#bind, #event?, #event_list, #fire_handler, #fire_property_change, #register_events

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)

Since:

  • 1.2.0



3589
3590
3591
3592
3593
3594
3595
3596
3597
# File 'lib/canis/core/widgets/rwidget.rb', line 3589

def initialize form, config={}, &block
  @surround_chars = ['(', ')'] if @surround_chars.nil?
  super
  $log.warn "XXX: FIXME Please set 'value' for radiobutton. If not sure, try setting it to the same value as 'text'" unless @value
  # I am setting value of value here if not set 2011-10-21 
  @value ||= @text
  ## trying with off since i can't do conventional style construction
  #raise "A single Variable must be set for a group of Radio Buttons for this to work." unless @variable
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.

Since:

  • 1.2.0



3634
3635
3636
3637
3638
3639
3640
# File 'lib/canis/core/widgets/rwidget.rb', line 3634

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

Since:

  • 1.2.0



3626
3627
3628
3629
# File 'lib/canis/core/widgets/rwidget.rb', line 3626

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

Since:

  • 1.2.0



3600
3601
3602
# File 'lib/canis/core/widgets/rwidget.rb', line 3600

def getvalue
  @variable.get_value @name
end

#getvalue_for_paintObject

Since:

  • 1.2.0



3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
# File 'lib/canis/core/widgets/rwidget.rb', line 3604

def getvalue_for_paint
  buttontext = getvalue() == @value ? "o" : " "
  dtext = @width.nil? ? text : "%-*s" % [@width, 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

Since:

  • 1.2.0



3619
3620
3621
3622
3623
# File 'lib/canis/core/widgets/rwidget.rb', line 3619

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