Class: RubyCurses::RadioButton

Inherits:
ToggleButton show all
Defined in:
lib/rbcurse/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 2008-11-27 18:45 just made this inherited from Checkbox

Since:

  • 1.2.0

Direct Known Subclasses

TabButton

Instance Attribute Summary

Attributes inherited from Widget

#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #key_label, #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, #default_button, #handle_key, #mnemonic, #repaint, #selected?, #text

Methods inherited from Widget

#action_manager, #changed, #click, #color_pair, #command, #destroy, #enter, #event_list, #focus, #get_preferred_size, #handle_key, #height, #height=, #hide, #init_vars, #leave, #modified?, #move, #on_enter, #on_leave, #override_graphic, #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

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

Methods included from Utils

#OLDdefine_key, #_process_key, #bind_key, #bind_keys, #clean_string!, #define_key, #define_prefix_command, #display_app_help, #get_attrib, #get_color, #keycode_tos, #last_line, #one_line_window, #parse_formatted_text, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #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)

Since:

  • 1.2.0



3208
3209
3210
3211
3212
3213
3214
3215
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3208

def initialize form, config={}, &block
  @surround_chars = ['(', ')'] if @surround_chars.nil?
  super
  $log.warn "XXX: FIXME Please set 'value' for radiobutton. If you don't know, try setting it to 'text'" unless @value
  # I am setting value of value here if not set 2011-10-21 
  @value ||= @text
  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



3253
3254
3255
3256
3257
3258
3259
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3253

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



3245
3246
3247
3248
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3245

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



3218
3219
3220
3221
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3218

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

#getvalue_for_paintObject

Since:

  • 1.2.0



3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3223

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

Since:

  • 1.2.0



3238
3239
3240
3241
3242
# File 'lib/rbcurse/core/widgets/rwidget.rb', line 3238

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