class Canis::RadioButton
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.
Public Class Methods
if a variable has been defined, off and on value will be set in it (default 0,1)
Canis::ToggleButton::new
# File lib/canis/core/widgets/rwidget.rb, line 3587 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
Public Instance Methods
ideally this should not be used. But implemented for completeness. it is recommended to toggle some other radio button than to uncheck this.
# File lib/canis/core/widgets/rwidget.rb, line 3632 def checked tf if tf toggle elsif !@variable.nil? and getvalue() != @value # XXX ??? @variable.set_value "", "" end end
added for bindkeys since that calls fire, not toggle - XXX i don't like this
Canis::ToggleButton#fire
# File lib/canis/core/widgets/rwidget.rb, line 3624 def fire @variable.set_value @value, @name super end
all radio buttons will return the value of the selected value, not the offered value
# File lib/canis/core/widgets/rwidget.rb, line 3598 def getvalue @variable.get_value @name end
# File lib/canis/core/widgets/rwidget.rb, line 3602 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
# File lib/canis/core/widgets/rwidget.rb, line 3617 def toggle @variable.set_value @value, @name # call fire of button class 2008-12-09 17:49 fire end