Module: Tk::Cget
- Included in:
- Button, Canvas, CheckButton, Entry, Frame, Label, LabelFrame, Listbox, Menu, MenuButton, Message, PanedWindow, RadioButton, Scale, Scrollbar, Spinbox, Text, Tile::ComboBox, Tile::Progressbar, Tile::Separator, Tile::Sizegrip, Tile::Style, Tile::Treeview, Toplevel
- Defined in:
- lib/ffi-tk/command/cget.rb
Constant Summary collapse
- CGET_MAP =
{}
Class Method Summary collapse
- .option_hash_to_tcl(hash) ⇒ Object
- .option_to_ruby(name, value) ⇒ Object
- .type_to_ruby(type, value) ⇒ Object
Instance Method Summary collapse
Class Method Details
.option_hash_to_tcl(hash) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ffi-tk/command/cget.rb', line 83 def option_hash_to_tcl(hash) result = {} hash.each do |key, value| case type = CGET_MAP[option = key.to_tcl_option] when :command command = register_command(key, &value) result[option] = command else result[option] = value end end result end |
.option_to_ruby(name, value) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/ffi-tk/command/cget.rb', line 42 def option_to_ruby(name, value) if type = CGET_MAP[name.to_tcl_option] type_to_ruby(type, value) else raise 'Unknown type for %p: %p' % [name, value] end end |
.type_to_ruby(type, value) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ffi-tk/command/cget.rb', line 50 def type_to_ruby(type, value) case type when :integer value.respond_to?(:to_i?) ? value.to_i? : value.to_i when :symbol value&.to_sym when :boolean Tk.boolean(value) when :color, :string, :font, :bitmap value.respond_to?(:to_s?) ? value.to_s? : value when :variable Variable.new(value.to_s?) if value.respond_to?(:to_s?) when :list case value when Array value when String value.split else value.to_a end when :float value.to_f when :pathname Tk.(value.to_s) when :command string = value.to_s string unless string.empty? else raise 'Unknown type: %p: %p' % [type, value] end end |
Instance Method Details
#cget(option) ⇒ Object
35 36 37 38 |
# File 'lib/ffi-tk/command/cget.rb', line 35 def cget(option) option = option.to_tcl_option Cget.option_to_ruby(option, execute('cget', option)) end |