Module: Tk::Cget
- Included in:
- Button, Canvas, CheckButton, Entry, Frame, Label, LabelFrame, Listbox, Menu, MenuButton, Message, PanedWindow, RadioButton, Scale, Scrollbar, Spinbox, Text, 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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ffi-tk/command/cget.rb', line 76 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
40 41 42 43 44 45 46 |
# File 'lib/ffi-tk/command/cget.rb', line 40 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
48 49 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 |
# File 'lib/ffi-tk/command/cget.rb', line 48 def type_to_ruby(type, value) case type when :integer 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 if name = value.to_s? Variable.new(name) end when :list value.to_a 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
33 34 35 36 |
# File 'lib/ffi-tk/command/cget.rb', line 33 def cget(option) option = option.to_tcl_option Cget.option_to_ruby(option, execute('cget', option)) end |