tkwrapper 1.0.0 → 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/util/hash_recursive.rb +3 -6
- data/lib/widgets/auto_resize_entry.rb +12 -4
- data/lib/widgets/base/configuration.rb +16 -18
- data/lib/widgets/base/manager.rb +42 -12
- data/lib/widgets/base/widget.rb +15 -2
- data/lib/widgets/grid.rb +5 -3
- data/lib/widgets/menu.rb +3 -3
- metadata +2 -2
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
|
data/lib/util/hash_recursive.rb
CHANGED
@@ -19,12 +19,9 @@ module Util
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.
|
23
|
-
hash.
|
24
|
-
value
|
25
|
-
next recursive_transform_key_value!(value, &block) if value.is_a?(Hash)
|
26
|
-
|
27
|
-
block.call(key, value)
|
22
|
+
def self.clone_recursive(hash)
|
23
|
+
hash.transform_values do |value|
|
24
|
+
value.is_a?(Hash) ? clone_recursive(value) : value
|
28
25
|
end
|
29
26
|
end
|
30
27
|
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(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: {
|
@@ -29,9 +37,9 @@ class TkWrapper::Widgets::AutoResizeEntry < TkWrapper::Widgets::Entry
|
|
29
37
|
end
|
30
38
|
|
31
39
|
def create_dummy_label_with_same_size(&block)
|
32
|
-
label = Label.new(**config_for_dummy_label)
|
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
|
@@ -5,7 +5,7 @@ require "#{LIB_DIR}/util/hash_recursive.rb"
|
|
5
5
|
require_relative 'base'
|
6
6
|
|
7
7
|
class TkWrapper::Widgets::Base::Configuration
|
8
|
-
|
8
|
+
attr_reader :config
|
9
9
|
|
10
10
|
GRID_SPECIAL_VALUES = {
|
11
11
|
onecell: {
|
@@ -20,32 +20,24 @@ 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
|
-
@config =
|
28
|
+
@config = parse_and_clone(config)
|
27
29
|
end
|
28
30
|
|
29
|
-
def merge
|
31
|
+
def merge(*configurations)
|
30
32
|
configurations = configurations.map do |configuration|
|
31
|
-
|
33
|
+
configuration = configuration.config if configuration.is_a?(self.class)
|
32
34
|
|
33
|
-
|
35
|
+
parse_and_clone(configuration)
|
34
36
|
end
|
35
37
|
|
36
38
|
Util.merge_recursive!(@config, *configurations)
|
37
39
|
end
|
38
40
|
|
39
|
-
def parse!(config)
|
40
|
-
Util.each_recursive(config) do |hash, key, value|
|
41
|
-
next if value.is_a?(Hash)
|
42
|
-
|
43
|
-
hash[key] = parse_value(key, value)
|
44
|
-
end
|
45
|
-
|
46
|
-
config
|
47
|
-
end
|
48
|
-
|
49
41
|
def [](key)
|
50
42
|
key = key.to_sym
|
51
43
|
return self.class.new(@config[key]) if @config[key].is_a?(Hash)
|
@@ -55,7 +47,13 @@ class TkWrapper::Widgets::Base::Configuration
|
|
55
47
|
|
56
48
|
def []=(key, value)
|
57
49
|
key = key.to_sym
|
58
|
-
@config[key] =
|
50
|
+
@config[key] = parse_and_clone(value, key)
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_and_clone(value, key = nil)
|
54
|
+
return parse_value(key, value) unless value.is_a?(Hash)
|
55
|
+
|
56
|
+
value.each_with_object({}) { |(k, v), h| h[k] = parse_and_clone(v, k) }
|
59
57
|
end
|
60
58
|
|
61
59
|
def parse_value(key, value)
|
@@ -114,6 +112,6 @@ class TkWrapper::Widgets::Base::Configuration
|
|
114
112
|
end
|
115
113
|
|
116
114
|
def merge_global_configurations(manager, widget)
|
117
|
-
merge
|
115
|
+
merge(*manager.configurations(widget))
|
118
116
|
end
|
119
117
|
end
|
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
|
@@ -60,6 +68,11 @@ class TkWrapper::Widgets::Base::Widget
|
|
60
68
|
@childs.each { |child| child.build(self) }
|
61
69
|
end
|
62
70
|
|
71
|
+
def push(child)
|
72
|
+
@childs.push(child)
|
73
|
+
child.build(self)
|
74
|
+
end
|
75
|
+
|
63
76
|
def configure
|
64
77
|
@config.merge_global_configurations(manager, self)
|
65
78
|
@config.configure_tk_widget(tk_widget)
|
data/lib/widgets/grid.rb
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
class TkWrapper::Widgets::Grid < TkWrapper::Widgets::Base::Widget
|
5
5
|
attr_reader :parent, :matrix
|
6
6
|
|
7
|
+
Widget = TkWrapper::Widgets::Base::Widget
|
8
|
+
|
7
9
|
def tk_class
|
8
10
|
TkWidgets::Frame
|
9
11
|
end
|
@@ -20,7 +22,7 @@ class TkWrapper::Widgets::Grid < TkWrapper::Widgets::Base::Widget
|
|
20
22
|
row.each_with_index do |cell, col_i|
|
21
23
|
next unless cell.is_a?(Widget)
|
22
24
|
|
23
|
-
|
25
|
+
cell.config.merge({ grid: { row: row_i, column: col_i } })
|
24
26
|
|
25
27
|
configure_colspan(cell, row_i, col_i)
|
26
28
|
configure_rowspan(cell, row_i, col_i)
|
@@ -33,7 +35,7 @@ class TkWrapper::Widgets::Grid < TkWrapper::Widgets::Base::Widget
|
|
33
35
|
colspan = cols_after_cell.reduce(1) do |span, content|
|
34
36
|
content == :right ? span + 1 : (break span)
|
35
37
|
end
|
36
|
-
|
38
|
+
cell.config.merge({ grid: { columnspan: colspan } })
|
37
39
|
end
|
38
40
|
|
39
41
|
def configure_rowspan(cell, row_i, col_i)
|
@@ -41,6 +43,6 @@ class TkWrapper::Widgets::Grid < TkWrapper::Widgets::Base::Widget
|
|
41
43
|
rowspan = rows_after_cell.reduce(1) do |span, row|
|
42
44
|
row[col_i] == :bottom ? span + 1 : (break span)
|
43
45
|
end
|
44
|
-
|
46
|
+
cell.config.merge({ grid: { rowspan: rowspan } })
|
45
47
|
end
|
46
48
|
end
|
data/lib/widgets/menu.rb
CHANGED
@@ -29,7 +29,7 @@ class TkWrapper::Widgets::Menu < TkWrapper::Widgets::Base::Widget
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.create(structure: [], config: {})
|
32
|
-
|
32
|
+
new(
|
33
33
|
config: config,
|
34
34
|
childs: structure.map { |entry| create_subentry(entry) }
|
35
35
|
)
|
@@ -44,8 +44,8 @@ class TkWrapper::Widgets::Menu < TkWrapper::Widgets::Base::Widget
|
|
44
44
|
|
45
45
|
def self.create_subentry(entry)
|
46
46
|
case entry
|
47
|
-
in { config: config, structure:
|
48
|
-
return Cascade.new config: config, childs: create_subentries(
|
47
|
+
in { config: config, structure: st }
|
48
|
+
return Cascade.new config: config, childs: create_subentries(st)
|
49
49
|
else
|
50
50
|
return Command.new config: entry
|
51
51
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tkwrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.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-
|
11
|
+
date: 2021-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: reception@e.mail.de
|