1 #
2 # tk/radiobutton.rb : treat radiobutton widget
3 #
4 require 'tk'
5 require 'tk/button'
6
7 class Tk::RadioButton<Tk::Button
8 TkCommandNames = ['radiobutton'.freeze].freeze
9 WidgetClassName = 'Radiobutton'.freeze
10 WidgetClassNames[WidgetClassName] = self
11 #def create_self(keys)
12 # if keys and keys != None
13 # tk_call_without_enc('radiobutton', @path, *hash_kv(keys, true))
14 # else
15 # tk_call_without_enc('radiobutton', @path)
16 # end
17 #end
18 #private :create_self
19
20 def __boolval_optkeys
21 super() << 'indicatoron'
22 end
23 private :__boolval_optkeys
24
25 def __strval_optkeys
26 super() << 'selectcolor'
27 end
28 private :__strval_optkeys
29
30 def __ruby2val_optkeys # { key=>proc, ... }
31 {
32 'variable'=>proc{|v| tk_trace_variable(v)} # for backward compatibility
33 }
34 end
35 private :__ruby2val_optkeys
36
37
38 def deselect
39 tk_send_without_enc('deselect')
40 self
41 end
42 def select
43 tk_send_without_enc('select')
44 self
45 end
46
47 def get_value
48 var = tk_send_without_enc('cget', '-variable')
49 if TkVariable::USE_TCLs_SET_VARIABLE_FUNCTIONS
50 _fromUTF8(INTERP._get_global_var(var))
51 else
52 INTERP._eval(Kernel.format('global %s; set %s', var, var))
53 end
54 end
55
56 def set_value(val)
57 var = tk_send_without_enc('cget', '-variable')
58 if TkVariable::USE_TCLs_SET_VARIABLE_FUNCTIONS
59 _fromUTF8(INTERP._set_global_var(var, _get_eval_string(val, true)))
60 else
61 s = '"' + _get_eval_string(val).gsub(/[\[\]$"\\]/, '\\\\\&') + '"'
62 INTERP._eval(Kernel.format('global %s; set %s %s', var, var, s))
63 end
64 end
65 end
66
67 Tk::Radiobutton = Tk::RadioButton
68 #TkRadioButton = Tk::RadioButton unless Object.const_defined? :TkRadioButton
69 #TkRadiobutton = Tk::Radiobutton unless Object.const_defined? :TkRadiobutton
70 Tk.__set_toplevel_aliases__(:Tk, Tk::RadioButton,
71 :TkRadioButton, :TkRadiobutton)