simple_tk 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_tk/get_set_helper.rb +33 -3
- data/lib/simple_tk/version.rb +1 -1
- data/lib/simple_tk/window.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d652d890ae873e6ee33badd9e219143448f2dd9
|
4
|
+
data.tar.gz: f40d8842de4c763186d104206649d87c09cb2d57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a184799291406c81ceee8c4471ea7d2513a027c90c87147e6e56a7be0927f517b958609c1960dc4ddddb33c10cea9d60b3f74297377fd4cea834f4b4dbd3e2e6
|
7
|
+
data.tar.gz: '058a34b5c36d60f6c5fcbecd2fa6f8e8a439969008caf786f629fd51b6c7dc9a9e55154d537d85a71522d8d95b26896c4dbd77ff7b8032d0d956abfd4312dbc8'
|
@@ -26,16 +26,31 @@ module SimpleTk
|
|
26
26
|
# If this is a Symbol then it defines the method name of the retrieved value to call with the new value.
|
27
27
|
# If this ia a Proc then it will be called with the retrieved value and the new value as arguments.
|
28
28
|
# If this is nil then the hash value is replaced with the new value.
|
29
|
+
# key_filter::
|
30
|
+
# If set to a proc keys are passed to this proc and only kept if the proc returns a true value.
|
31
|
+
# Any key rejected by the filter become unavailable via the helper.
|
29
32
|
#
|
30
33
|
# GetSetHelper.new(my_obj, :@data)
|
31
34
|
# GetSetHelper.new(my_obj, :@data, true, :value, :value=)
|
32
35
|
# GetSetHelper.new(my_obj, :@data, true, ->(v){ v.value }, ->(i,v){ i.value = v })
|
33
|
-
def initialize(parent, hash_ivar, auto_symbol = true, getter = nil, setter = nil)
|
36
|
+
def initialize(parent, hash_ivar, auto_symbol = true, getter = nil, setter = nil, key_filter = nil)
|
34
37
|
@parent = parent
|
35
38
|
@hash_ivar = hash_ivar
|
36
39
|
@auto_symbol = auto_symbol
|
37
40
|
@getter = getter
|
38
41
|
@setter = setter
|
42
|
+
@key_filter = key_filter.is_a?(Proc) ? key_filter : nil
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Gets the available keys.
|
47
|
+
def keys
|
48
|
+
h = @parent.instance_variable_get(@hash_ivar)
|
49
|
+
if @key_filter
|
50
|
+
h.keys.select &@key_filter
|
51
|
+
else
|
52
|
+
h.keys.dup
|
53
|
+
end
|
39
54
|
end
|
40
55
|
|
41
56
|
##
|
@@ -43,7 +58,7 @@ module SimpleTk
|
|
43
58
|
def [](name)
|
44
59
|
name = name.to_sym if @auto_symbol
|
45
60
|
h = @parent.instance_variable_get(@hash_ivar)
|
46
|
-
if
|
61
|
+
if keys.include?(name)
|
47
62
|
v = h[name]
|
48
63
|
if @getter.is_a?(Symbol)
|
49
64
|
v.send @getter
|
@@ -62,7 +77,7 @@ module SimpleTk
|
|
62
77
|
def []=(name, value)
|
63
78
|
name = name.to_sym if @auto_symbol
|
64
79
|
h = @parent.instance_variable_get(@hash_ivar)
|
65
|
-
if
|
80
|
+
if keys.include?(name)
|
66
81
|
if @setter.is_a?(Symbol)
|
67
82
|
h[name].send @setter, value
|
68
83
|
elsif @setter.is_a?(Proc)
|
@@ -75,5 +90,20 @@ module SimpleTk
|
|
75
90
|
end
|
76
91
|
end
|
77
92
|
|
93
|
+
##
|
94
|
+
# Iterates over the hash.
|
95
|
+
def each
|
96
|
+
h = @parent.instance_variable_get(@hash_ivar)
|
97
|
+
if block_given?
|
98
|
+
keys.each do |k|
|
99
|
+
yield k, h[k]
|
100
|
+
end
|
101
|
+
elsif @key_filter
|
102
|
+
h.dup.keep_if{ |k,v| @key_filter.call(k) }.each
|
103
|
+
else
|
104
|
+
h.each
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
78
108
|
end
|
79
109
|
end
|
data/lib/simple_tk/version.rb
CHANGED
data/lib/simple_tk/window.rb
CHANGED
@@ -385,7 +385,7 @@ module SimpleTk
|
|
385
385
|
def add_combo_box(name, options = {}, &block)
|
386
386
|
options = options.dup
|
387
387
|
proc = get_command(options.delete(:command), &block)
|
388
|
-
item = add_widget
|
388
|
+
item = add_widget Tk::Tile::Combobox, name, nil, options.merge(create_var: :textvariable)
|
389
389
|
if proc
|
390
390
|
item.bind('<ComboboxSelected>') { proc.call }
|
391
391
|
end
|