tkwrapper 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tkwrapper.rb +6 -1
- data/lib/util/tk/finder.rb +40 -24
- data/lib/widgets/auto_resize_entry.rb +3 -3
- data/lib/widgets/base/comparator_item_store.rb +10 -1
- data/lib/widgets/base/manager.rb +5 -0
- data/lib/widgets/base/matches.rb +4 -0
- data/lib/widgets/base/widget.rb +1 -0
- data/lib/widgets/base/widget_store.rb +37 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abffb1cc7ae4efaf8b26ebdd49acca56837989829713473f21971f8a5f5a9063
|
4
|
+
data.tar.gz: 1e659e3049a41d4aff307f700ac27cc86d014ec844134aa65bc7bd20c2f692db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efbad85fe488198ff115feac31872163da0da8b796ef0a21babf33d21976e14da0f809a93a502cbfc0f9225e4446e30c1b567680af2b3c7e7eae862cf0b5f64b
|
7
|
+
data.tar.gz: 7d0addd32901d46c6d0175219ee83dd4478f699bc05ec7804f0a76dac02b1950a11f7a22dafa494996961bc8f25582c1f6be4f36c3cf19c9b3a3e5050cb0df9f
|
data/lib/tkwrapper.rb
CHANGED
data/lib/util/tk/finder.rb
CHANGED
@@ -2,42 +2,32 @@
|
|
2
2
|
|
3
3
|
require "#{LIB_DIR}/widgets/base/manager"
|
4
4
|
require "#{LIB_DIR}/widgets/base/matcher"
|
5
|
-
|
5
|
+
require "#{LIB_DIR}/widgets/base/matches"
|
6
6
|
|
7
7
|
class TkWrapper::Util::Tk::Finder
|
8
|
+
Match = TkWrapper::Widgets::Base::Match
|
8
9
|
Matcher = TkWrapper::Widgets::Base::Matcher
|
10
|
+
Matches = TkWrapper::Widgets::Base::Matches
|
9
11
|
|
10
|
-
def initialize(widgets: nil)
|
12
|
+
def initialize(widgets: nil, lookup: nil)
|
13
|
+
@lookup = lookup
|
11
14
|
@widgets = widgets
|
12
15
|
end
|
13
16
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
(match = matcher.match(id, widget)) && block.call(match)
|
19
|
-
end
|
20
|
-
end
|
17
|
+
def iter(comparators, widgets = @widgets, lookup = @lookup)
|
18
|
+
Enumerator.new do |y|
|
19
|
+
comparators = each_widget_lookup_match(lookup, comparators) { |m| y << m }
|
20
|
+
each_widget_comparator_match(widgets, comparators) { |m| y << m }
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def find(comparators, widgets = @widgets)
|
25
|
-
|
26
|
-
|
27
|
-
each_widget_match(widgets, matchers) do |match|
|
28
|
-
return match.widget if match
|
29
|
-
end
|
24
|
+
def find(comparators, widgets = @widgets, lookup = @lookup)
|
25
|
+
iter(comparators, widgets, lookup, &:itself).first
|
30
26
|
end
|
31
27
|
|
32
|
-
def find_all(comparators, widgets = @widgets)
|
33
|
-
|
34
|
-
matches
|
35
|
-
|
36
|
-
each_widget_match(widgets, matchers) do |match|
|
37
|
-
matches.push(match)
|
38
|
-
end
|
39
|
-
|
40
|
-
matches
|
28
|
+
def find_all(comparators, widgets = @widgets, lookup = @lookup)
|
29
|
+
it = iter(comparators, widgets, lookup, &:itself)
|
30
|
+
it.each_with_object(Matches.new) { |match, matches| matches.push(match) }
|
41
31
|
end
|
42
32
|
|
43
33
|
private
|
@@ -46,4 +36,30 @@ class TkWrapper::Util::Tk::Finder
|
|
46
36
|
comparators = [comparators] unless comparators.is_a?(Array)
|
47
37
|
comparators.map { |comparator| Matcher.new(comparator: comparator) }
|
48
38
|
end
|
39
|
+
|
40
|
+
def each_widget_lookup_match(lookup, comparators, &block)
|
41
|
+
return comparators unless lookup
|
42
|
+
|
43
|
+
comparators.filter do |comparator|
|
44
|
+
next true unless [String, Symbol].include?(comparator.class)
|
45
|
+
|
46
|
+
(lookup[comparator] || []).each do |widget|
|
47
|
+
block.call(Match.new(comparator, widget: widget))
|
48
|
+
end
|
49
|
+
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def each_widget_comparator_match(widgets, comparators, &block)
|
55
|
+
matchers = create_value_matchers(comparators)
|
56
|
+
|
57
|
+
widgets.each do |widget|
|
58
|
+
widget.ids.each do |id|
|
59
|
+
matchers.each do |matcher|
|
60
|
+
(match = matcher.match(id, widget)) && block.call(match)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
49
65
|
end
|
@@ -5,8 +5,8 @@ class TkWrapper::Widgets::AutoResizeEntry < TkWrapper::Widgets::Entry
|
|
5
5
|
attr_accessor :min_width, :add_width
|
6
6
|
|
7
7
|
def initialize(**args)
|
8
|
-
@min_width = args
|
9
|
-
@add_width = args
|
8
|
+
@min_width = args.dig(:config, :min_width) || 0
|
9
|
+
@add_width = args.dig(:config, :add_width) || 0
|
10
10
|
super(**args)
|
11
11
|
end
|
12
12
|
|
@@ -27,7 +27,7 @@ class TkWrapper::Widgets::AutoResizeEntry < TkWrapper::Widgets::Entry
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def resize
|
30
|
-
max_width = @cell.bbox[2]
|
30
|
+
max_width = [@cell.bbox[2], 0].max
|
31
31
|
text_width = @font.measure(value)
|
32
32
|
new_width = [[@min_width, text_width + @add_width].max, max_width].min
|
33
33
|
tk_widget.width = 0
|
@@ -10,8 +10,12 @@ class TkWrapper::Widgets::Base::ComparatorItemStore
|
|
10
10
|
@comparator_map = {} # for lookup using comparisons by Matcher class
|
11
11
|
end
|
12
12
|
|
13
|
+
def map_key?(key)
|
14
|
+
[String, Symbol].include?(key)
|
15
|
+
end
|
16
|
+
|
13
17
|
def push(key, *items)
|
14
|
-
if
|
18
|
+
if map_key?(key)
|
15
19
|
(@key_map[key] ||= []).concat(items)
|
16
20
|
else
|
17
21
|
(@comparator_map[key] ||= []).concat(items)
|
@@ -25,6 +29,11 @@ class TkWrapper::Widgets::Base::ComparatorItemStore
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
32
|
+
def [](key)
|
33
|
+
items = map_key?(key) ? @key_map[key] : @comparator_map[key]
|
34
|
+
items&.length == 1 ? items.first : items
|
35
|
+
end
|
36
|
+
|
28
37
|
private
|
29
38
|
|
30
39
|
def items_from_key_map(id)
|
data/lib/widgets/base/manager.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'comparator_item_store'
|
4
|
+
require_relative 'widget_store'
|
4
5
|
|
5
6
|
class TkWrapper::Widgets::Base::Manager
|
6
7
|
ComparatorItemStore = TkWrapper::Widgets::Base::ComparatorItemStore
|
8
|
+
WidgetStore = TkWrapper::Widgets::Base::WidgetStore
|
9
|
+
|
10
|
+
attr_reader :widgets
|
7
11
|
|
8
12
|
def initialize
|
9
13
|
@configurations = ComparatorItemStore.new
|
10
14
|
@modifications = ComparatorItemStore.new
|
15
|
+
@widgets = WidgetStore.new
|
11
16
|
end
|
12
17
|
|
13
18
|
def add_configurations(matcher = nil, configuration = nil, **configurations)
|
data/lib/widgets/base/matches.rb
CHANGED
data/lib/widgets/base/widget.rb
CHANGED
@@ -49,6 +49,7 @@ class TkWrapper::Widgets::Base::Widget
|
|
49
49
|
@config.merge(*@manager.configurations(self)) if @manager
|
50
50
|
self.configure if configure
|
51
51
|
@manager&.execute_modifications(self)
|
52
|
+
@manager&.widgets&.push(self)
|
52
53
|
@childs.each { |child| child.build(self, manager: @manager) }
|
53
54
|
end
|
54
55
|
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "#{LIB_DIR}/util/tk/finder"
|
4
|
+
require_relative 'comparator_item_store'
|
5
|
+
|
6
|
+
class TkWrapper::Widgets::Base::WidgetStore
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :@finder, :find, :find_all, :iter
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@lookup = {}
|
13
|
+
@finder = TkWrapper::Util::Tk::Finder.new(widgets: self, lookup: @lookup)
|
14
|
+
end
|
15
|
+
|
16
|
+
def push(widget)
|
17
|
+
widget.ids.each do |id|
|
18
|
+
(@lookup[id] ||= []).push(widget)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def each(&block)
|
23
|
+
@lookup.each_value do |widgets|
|
24
|
+
widgets.each { |widget| block.call(widget) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def [](key)
|
29
|
+
@lookup[key].size == 1 ? @lookup[key].first : @lookup[key]
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def map_key?(key)
|
35
|
+
[String, Symbol].include?(key)
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tkwrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Schnitzler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.4'
|
13
27
|
description:
|
14
28
|
email: reception@e.mail.de
|
15
29
|
executables: []
|
@@ -33,6 +47,7 @@ files:
|
|
33
47
|
- lib/widgets/base/matcher.rb
|
34
48
|
- lib/widgets/base/matches.rb
|
35
49
|
- lib/widgets/base/widget.rb
|
50
|
+
- lib/widgets/base/widget_store.rb
|
36
51
|
- lib/widgets/entry.rb
|
37
52
|
- lib/widgets/frame.rb
|
38
53
|
- lib/widgets/grid.rb
|