tkwrapper 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/widgets/auto_resize_entry.rb +11 -3
- data/lib/widgets/base/configuration.rb +3 -1
- data/lib/widgets/base/manager.rb +42 -12
- data/lib/widgets/base/widget.rb +10 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a31665aae98cd470f88451d45cd6332030c8fe874e18faa1040bcd42103d9ace
|
4
|
+
data.tar.gz: 93f428a63f6bf0832bf91accfdec1f14715cbfc6de2e9055f29b4cb146da0bf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 461b4344678f1d7a374ad6d1d01ffbab5c4865a9c513457c7145b21e9582e9d0922d3666a93adf6ed8f57428c6485b8e693694438db1966a7967c01c0ae6e3fc
|
7
|
+
data.tar.gz: f0a8d152e7aac88206454340c2fbce7e605117a85e2dc0cd550bffc4db9e49d09dd21b4610e52e19a87dc6313ce37b98c9a4bc4e8c44bf033b3f84fe41289833
|
@@ -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(config: {}, childs: [])
|
8
|
-
@min_width = config
|
9
|
-
@add_width = config
|
8
|
+
@min_width = config[:min_width] || 0
|
9
|
+
@add_width = config[:add_width] || 0
|
10
10
|
super(config: config, childs: childs)
|
11
11
|
end
|
12
12
|
|
@@ -18,6 +18,14 @@ class TkWrapper::Widgets::AutoResizeEntry < TkWrapper::Widgets::Entry
|
|
18
18
|
resize
|
19
19
|
end
|
20
20
|
|
21
|
+
def value=(value)
|
22
|
+
tk_widget.textvariable.value = value
|
23
|
+
end
|
24
|
+
|
25
|
+
def value
|
26
|
+
tk_widget.textvariable.value
|
27
|
+
end
|
28
|
+
|
21
29
|
def config_for_dummy_label
|
22
30
|
grid_info = TkGrid.info(tk_widget)
|
23
31
|
{ config: { grid: {
|
@@ -31,7 +39,7 @@ class TkWrapper::Widgets::AutoResizeEntry < TkWrapper::Widgets::Entry
|
|
31
39
|
def create_dummy_label_with_same_size(&block)
|
32
40
|
label = TkWrapper::Widgets::Label.new(**config_for_dummy_label)
|
33
41
|
label.build(@parent)
|
34
|
-
label.tk_widget.text =
|
42
|
+
label.tk_widget.text = value
|
35
43
|
label.tk_widget.lower
|
36
44
|
result = block.call(label)
|
37
45
|
label.tk_widget.destroy
|
@@ -20,7 +20,9 @@ class TkWrapper::Widgets::Base::Configuration
|
|
20
20
|
}
|
21
21
|
}.freeze
|
22
22
|
|
23
|
-
NON_TK_OPTIONS = %i[
|
23
|
+
NON_TK_OPTIONS = %i[
|
24
|
+
id tk_class tearoff weights menu min_width add_width
|
25
|
+
].freeze
|
24
26
|
|
25
27
|
def initialize(config)
|
26
28
|
@config = parse_and_clone(config)
|
data/lib/widgets/base/manager.rb
CHANGED
@@ -3,30 +3,60 @@
|
|
3
3
|
# manages widgets and their global configurations
|
4
4
|
class TkWrapper::Widgets::Base::Manager
|
5
5
|
def initialize
|
6
|
-
@
|
7
|
-
@
|
6
|
+
@configuration_matchers = { regex: {}, map: {} }
|
7
|
+
@modification_matchers = { regex: {}, map: {} }
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def add_configurations(matcher = nil, config = nil, **configs)
|
11
|
+
add_matcher(matcher, config, @configuration_matchers) if config
|
12
|
+
|
13
|
+
configs.each { |mat, cfg| add_matcher(mat, cfg, @configuration_matchers) }
|
12
14
|
end
|
13
15
|
|
14
16
|
def add_modification(matcher, &callback)
|
15
|
-
|
17
|
+
add_matcher(matcher, callback, @modification_matchers)
|
16
18
|
end
|
17
19
|
|
18
20
|
def configurations(widget)
|
19
|
-
|
20
|
-
|
21
|
-
end
|
21
|
+
configs = find_matching_items(widget.ids, @configuration_matchers)
|
22
|
+
configs.map { |config| config[0] }
|
22
23
|
end
|
23
24
|
|
24
25
|
def execute_modifications(widget)
|
25
|
-
|
26
|
-
|
26
|
+
callbacks = find_matching_items(widget.ids, @modification_matchers)
|
27
|
+
callbacks.each do |callback|
|
28
|
+
callback, match = callback
|
29
|
+
match ? callback.call(widget, match) : callback.call(widget)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def find_matching_items(keys, container)
|
36
|
+
keys.each_with_object([]) do |key, items|
|
37
|
+
items.concat(
|
38
|
+
items_from_map(key, container),
|
39
|
+
items_by_regex(key, container)
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def items_from_map(key, container)
|
45
|
+
(container[:map][key] || []).map { |item| [item, nil] } || []
|
46
|
+
end
|
47
|
+
|
48
|
+
def items_by_regex(key, container)
|
49
|
+
container[:regex].each_with_object([]) do |(matcher, items), merged_items|
|
50
|
+
match = matcher.match(key)
|
51
|
+
merged_items.concat(items.map { |item| [item, match] }) if match
|
52
|
+
end
|
53
|
+
end
|
27
54
|
|
28
|
-
|
29
|
-
|
55
|
+
def add_matcher(matcher, item, container)
|
56
|
+
if matcher.is_a?(Regexp)
|
57
|
+
(container[:regex][matcher] ||= []).push(item)
|
58
|
+
else
|
59
|
+
(container[:map][matcher] ||= []).push(item)
|
30
60
|
end
|
31
61
|
end
|
32
62
|
end
|
data/lib/widgets/base/widget.rb
CHANGED
@@ -18,14 +18,22 @@ class TkWrapper::Widgets::Base::Widget
|
|
18
18
|
@manager ||= TkWrapper::Widgets::Base::Manager.new
|
19
19
|
end
|
20
20
|
|
21
|
-
def self.config(matcher, configuration)
|
22
|
-
manager.
|
21
|
+
def self.config(matcher = nil, configuration = nil, **configurations)
|
22
|
+
manager.add_configurations(matcher, configuration, **configurations)
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.modify(matcher, &callback)
|
26
26
|
manager.add_modification(matcher, &callback)
|
27
27
|
end
|
28
28
|
|
29
|
+
def ids
|
30
|
+
case @id
|
31
|
+
when Array then @id
|
32
|
+
when nil then []
|
33
|
+
else [@id]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
29
37
|
def manager
|
30
38
|
TkWrapper::Widgets::Base::Widget.manager
|
31
39
|
end
|