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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 688f0fe3a07729c95ffe968c6d1bb55a846ef7d9
4
- data.tar.gz: b96b21a78f9c6244bc66cb07018c5f356c003473
3
+ metadata.gz: 7d652d890ae873e6ee33badd9e219143448f2dd9
4
+ data.tar.gz: f40d8842de4c763186d104206649d87c09cb2d57
5
5
  SHA512:
6
- metadata.gz: 524e8e9e20024a885938ea049b292c04a393c5ebbfe7acdcc1600d1fc5a3f48ac313a257a858cee2ae287f95a2fe72b939411338f2bc2545417493ddb55f5de1
7
- data.tar.gz: 656d163a645705cf9964754a7c96a510d75de50616c190a38b21ff06887817ecbd0cf9cd2e5df00cf27674d639a5232c60d00c7e390ba3e37e9d0ec591bb15a4
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 h.include?(name)
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 h.include?(name)
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
@@ -1,3 +1,3 @@
1
1
  module SimpleTk
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -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 TK::Tile::Combobox, name, nil, options.merge(create_var: :textvariable)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_tk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Beau Barker