1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
#
# tk/scale.rb : treat scale widget
#
require 'tk'
class Tk::Scale<TkWindow
TkCommandNames = ['scale'.freeze].freeze
WidgetClassName = 'Scale'.freeze
WidgetClassNames[WidgetClassName] = self
def create_self(keys)
if keys and keys != None
if keys.key?('command') && ! keys['command'].kind_of?(String)
cmd = keys.delete('command')
keys['command'] = proc{|val| cmd.call(val.to_f)}
end
unless TkConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
#tk_call_without_enc('scale', @path, *hash_kv(keys, true))
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
else
begin
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
rescue
tk_call_without_enc(self.class::TkCommandNames[0], @path)
keys = __check_available_configure_options(keys)
unless keys.empty?
begin
tk_call_without_enc('destroy', @path)
rescue
# cannot destroy
configure(keys)
else
# re-create widget
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
end
end
end
end
else
#tk_call_without_enc('scale', @path)
tk_call_without_enc(self.class::TkCommandNames[0], @path)
end
end
private :create_self
def __strval_optkeys
super() << 'label'
end
private :__strval_optkeys
def _wrap_command_arg(cmd)
proc{|val|
if val.kind_of?(String)
cmd.call(number(val))
else
cmd.call(val)
end
}
end
private :_wrap_command_arg
def configure_cmd(slot, value)
configure(slot=>value)
end
def configure(slot, value=None)
if (slot == 'command' || slot == :command)
configure('command'=>value)
elsif slot.kind_of?(Hash) &&
(slot.key?('command') || slot.key?(:command))
slot = _symbolkey2str(slot)
slot['command'] = _wrap_command_arg(slot.delete('command'))
end
super(slot, value)
end
def command(cmd=Proc.new)
configure('command'=>cmd)
end
def get(x=None, y=None)
number(tk_send_without_enc('get', x, y))
end
def coords(val=None)
tk_split_list(tk_send_without_enc('coords', val))
end
def identify(x, y)
tk_send_without_enc('identify', x, y)
end
def set(val)
tk_send_without_enc('set', val)
end
def value
get
end
def value= (val)
set(val)
val
end
end
#TkScale = Tk::Scale unless Object.const_defined? :TkScale
Tk.__set_toplevel_aliases__(:Tk, Tk::Scale, :TkScale)
|