tkwrapper 1.3.0 → 1.6.1
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 +7 -1
- data/lib/util/hash_recursive.rb +2 -2
- data/lib/util/tk/cell.rb +1 -0
- data/lib/util/tk/finder.rb +42 -25
- data/lib/widgets/auto_resize_entry.rb +8 -8
- data/lib/widgets/auto_resize_text.rb +25 -0
- data/lib/widgets/base/comparator_item_store.rb +10 -1
- data/lib/widgets/base/configuration.rb +17 -9
- data/lib/widgets/base/manager.rb +16 -0
- data/lib/widgets/base/matcher.rb +1 -1
- data/lib/widgets/base/matches.rb +8 -4
- data/lib/widgets/base/widget.rb +57 -68
- data/lib/widgets/base/widget_store.rb +38 -0
- data/lib/widgets/base/window_info.rb +13 -0
- data/lib/widgets/button.rb +9 -0
- data/lib/widgets/entry.rb +3 -1
- data/lib/widgets/frame.rb +3 -1
- data/lib/widgets/grid.rb +7 -3
- data/lib/widgets/label.rb +3 -1
- data/lib/widgets/menu.rb +12 -7
- data/lib/widgets/mount_point.rb +25 -0
- data/lib/widgets/root.rb +3 -1
- data/lib/widgets/text.rb +3 -1
- data/lib/widgets/widgets.rb +3 -0
- metadata +22 -4
- data/lib/tk_extensions.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a67fc8eac231f5b0b875cdd2fba4f107a3b596206766a4e57793e4f3d1b71992
|
4
|
+
data.tar.gz: 9bd2376b17ebf7e866f7858f98d2e9698575dec8a3fa2794c84c7b625048b33c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b467177153264f4a1cf973e4ae321d57c94f421e14eddfac98db6766ed06ca133f7af73931ef3f2ca3b23800363dacc533c666fb883f2bcb01c19a5432250b75
|
7
|
+
data.tar.gz: 00f36bd8f579688715d25b580a028e577f3820a83749b39bfd353c90ed32a3e0509ebcc5ca0306a3cf48576dd3d52d136e093ad26d87a33212cb84cb9a09b456
|
data/lib/tkwrapper.rb
CHANGED
@@ -2,10 +2,16 @@
|
|
2
2
|
|
3
3
|
LIB_DIR = __dir__
|
4
4
|
|
5
|
-
module TkWrapper
|
5
|
+
module TkWrapper
|
6
|
+
module Util
|
7
|
+
module Tk
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
6
11
|
|
7
12
|
require_relative 'widgets/widgets'
|
8
13
|
|
9
14
|
module TkWrapper
|
15
|
+
Manager = TkWrapper::Widgets::Base::Manager
|
10
16
|
Widget = TkWrapper::Widgets::Base::Widget
|
11
17
|
end
|
data/lib/util/hash_recursive.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Util
|
4
|
-
def self.merge_recursive!(*hashes)
|
4
|
+
def self.merge_recursive!(*hashes, overwrite: true)
|
5
5
|
hashes[0].merge!(*hashes[1..]) do |_key, old, new|
|
6
6
|
if old.is_a?(Hash) && new.is_a?(Hash)
|
7
7
|
merge_recursive!(old, new)
|
8
8
|
else
|
9
|
-
new
|
9
|
+
overwrite ? new : old
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/util/tk/cell.rb
CHANGED
data/lib/util/tk/finder.rb
CHANGED
@@ -2,48 +2,65 @@
|
|
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
|
-
|
19
|
-
end
|
20
|
-
end
|
17
|
+
def iter(comparators, widgets = @widgets, lookup = @lookup)
|
18
|
+
comparators = [comparators] unless comparators.is_a?(Array)
|
19
|
+
Enumerator.new do |y|
|
20
|
+
comparators = each_widget_lookup_match(lookup, comparators) { |m| y << m }
|
21
|
+
each_widget_comparator_match(widgets, comparators) { |m| y << m }
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
each_widget_match(widgets, matchers) do |match|
|
28
|
-
return match.widget if match
|
29
|
-
end
|
25
|
+
def find(comparators, widgets = @widgets, lookup = @lookup)
|
26
|
+
iter(comparators, widgets, lookup, &:itself).first
|
30
27
|
end
|
31
28
|
|
32
|
-
def
|
33
|
-
|
34
|
-
matches
|
35
|
-
|
36
|
-
each_widget_match(widgets, matchers) do |match|
|
37
|
-
matches.push(match)
|
38
|
-
end
|
39
|
-
|
40
|
-
matches
|
29
|
+
def find_all(comparators, widgets = @widgets, lookup = @lookup)
|
30
|
+
it = iter(comparators, widgets, lookup, &:itself)
|
31
|
+
it.each_with_object(Matches.new) { |match, matches| matches.push(match) }
|
41
32
|
end
|
42
33
|
|
43
34
|
private
|
44
35
|
|
45
36
|
def create_value_matchers(comparators)
|
46
|
-
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
|
+
ids = widget.ids.empty? ? [nil] : widget.ids
|
59
|
+
ids.each do |id|
|
60
|
+
matchers.each do |matcher|
|
61
|
+
(match = matcher.match(id, widget)) && block.call(match)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
49
66
|
end
|
@@ -4,15 +4,15 @@ class TkWrapper::Widgets::AutoResizeEntry < TkWrapper::Widgets::Entry
|
|
4
4
|
# auto resizes on user input, only works if in the grid geometry manager of tk
|
5
5
|
attr_accessor :min_width, :add_width
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@min_width = config
|
9
|
-
@add_width = config
|
10
|
-
super(
|
7
|
+
def initialize(**args)
|
8
|
+
@min_width = args.dig(:config, :min_width) || 0
|
9
|
+
@add_width = args.dig(:config, :add_width) || 0
|
10
|
+
super(**args)
|
11
11
|
end
|
12
12
|
|
13
|
-
def build(parent,
|
14
|
-
super(parent,
|
15
|
-
parent.
|
13
|
+
def build(parent, **args)
|
14
|
+
super(parent, **args)
|
15
|
+
parent.bind('Configure') { resize }
|
16
16
|
tk_widget.textvariable = TkVariable.new unless tk_widget.textvariable
|
17
17
|
tk_widget.textvariable.trace('write') { resize }
|
18
18
|
resize
|
@@ -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
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'text'
|
4
|
+
|
5
|
+
class TkWrapper::Widgets::AutoResizeText < TkWrapper::Widgets::Text
|
6
|
+
def build(parent, **args)
|
7
|
+
super(parent, **args)
|
8
|
+
bind('<Modified>', ->(ev) { resize(ev) })
|
9
|
+
bind('<Modified>', -> { puts 'hihi' })
|
10
|
+
end
|
11
|
+
|
12
|
+
def resize(event)
|
13
|
+
return unless tk_widget.modified?
|
14
|
+
|
15
|
+
puts event
|
16
|
+
puts 'yes!'
|
17
|
+
tk_widget.modified(false)
|
18
|
+
#max_width = [@cell.bbox[2], 0].max
|
19
|
+
#puts @font.metrics
|
20
|
+
#new_width = [[@min_width, text_width + @add_width].max, max_width].min
|
21
|
+
#tk_widget.width = 0
|
22
|
+
#tk_widget.grid(ipadx: new_width / 2.0)
|
23
|
+
#@parent.tk_widget.update
|
24
|
+
end
|
25
|
+
end
|
@@ -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)
|
@@ -21,21 +21,21 @@ class TkWrapper::Widgets::Base::Configuration
|
|
21
21
|
}.freeze
|
22
22
|
|
23
23
|
NON_TK_OPTIONS = %i[
|
24
|
-
|
24
|
+
tk_class tearoff weights menu min_width add_width
|
25
25
|
].freeze
|
26
26
|
|
27
27
|
def initialize(config)
|
28
28
|
@config = parse_and_clone(config)
|
29
29
|
end
|
30
30
|
|
31
|
-
def merge(*configurations)
|
31
|
+
def merge(*configurations, overwrite: true)
|
32
32
|
configurations = configurations.map do |configuration|
|
33
33
|
configuration = configuration.config if configuration.is_a?(self.class)
|
34
34
|
|
35
35
|
parse_and_clone(configuration)
|
36
36
|
end
|
37
37
|
|
38
|
-
Util.merge_recursive!(@config, *configurations)
|
38
|
+
Util.merge_recursive!(@config, *configurations, overwrite: overwrite)
|
39
39
|
end
|
40
40
|
|
41
41
|
def [](key)
|
@@ -77,17 +77,23 @@ class TkWrapper::Widgets::Base::Configuration
|
|
77
77
|
@config[:grid].reject { |option, _| NON_TK_OPTIONS.include?(option) }
|
78
78
|
end
|
79
79
|
|
80
|
+
def configure_grid(tk_widget)
|
81
|
+
grid = grid(only_tk_options: true)
|
82
|
+
return if grid.empty?
|
83
|
+
|
84
|
+
tk_widget.grid(grid)
|
85
|
+
end
|
86
|
+
|
80
87
|
def configure_tk_widget(tk_widget)
|
81
88
|
@config.each do |option, value|
|
82
89
|
next if NON_TK_OPTIONS.include?(option)
|
83
90
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
91
|
+
case option
|
92
|
+
when :grid then configure_grid(tk_widget)
|
93
|
+
when :pack then tk_widget.pack(value)
|
94
|
+
when :place then tk_widget.place(value)
|
95
|
+
else tk_widget[option] = value
|
88
96
|
end
|
89
|
-
|
90
|
-
tk_widget[option] = value
|
91
97
|
end
|
92
98
|
|
93
99
|
configure_weights(tk_widget)
|
@@ -112,6 +118,8 @@ class TkWrapper::Widgets::Base::Configuration
|
|
112
118
|
end
|
113
119
|
|
114
120
|
def merge_global_configurations(manager, widget)
|
121
|
+
return unless manager
|
122
|
+
|
115
123
|
merge(*manager.configurations(widget))
|
116
124
|
end
|
117
125
|
end
|
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)
|
@@ -37,4 +42,15 @@ class TkWrapper::Widgets::Base::Manager
|
|
37
42
|
end
|
38
43
|
end
|
39
44
|
end
|
45
|
+
|
46
|
+
def configure(widget)
|
47
|
+
widget.config.merge(*configurations(widget))
|
48
|
+
end
|
49
|
+
|
50
|
+
def tk_widget(id)
|
51
|
+
@widgets[id].tk_widget
|
52
|
+
end
|
53
|
+
|
54
|
+
alias modify add_modification
|
55
|
+
alias config add_configurations
|
40
56
|
end
|
data/lib/widgets/base/matcher.rb
CHANGED
@@ -39,7 +39,7 @@ class TkWrapper::Widgets::Base::Matcher
|
|
39
39
|
when String, Symbol then match_string(value, comparator, widget)
|
40
40
|
when Regexp then match_regex(value, comparator, widget)
|
41
41
|
when Class then match_class(value, comparator, widget)
|
42
|
-
when nil then Match(value,
|
42
|
+
when nil then Match.new(value, widget: widget)
|
43
43
|
else false
|
44
44
|
end
|
45
45
|
end
|
data/lib/widgets/base/matches.rb
CHANGED
@@ -25,10 +25,14 @@ class TkWrapper::Widgets::Base::Matches
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def [](key)
|
28
|
-
case @matches[key]
|
29
|
-
when 0 then nil
|
30
|
-
when 1
|
31
|
-
else
|
28
|
+
case @matches[key]&.size
|
29
|
+
when 0, nil then nil
|
30
|
+
when 1 then @matches[key][0]
|
31
|
+
else @matches[key]
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
def first
|
36
|
+
@matches.first&.[](1)
|
37
|
+
end
|
34
38
|
end
|
data/lib/widgets/base/widget.rb
CHANGED
@@ -1,67 +1,43 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'tk'
|
4
|
-
|
5
|
-
require "#{LIB_DIR}/tk_extensions"
|
6
|
-
require "#{LIB_DIR}/util/tk/font"
|
7
1
|
require "#{LIB_DIR}/util/tk/cell"
|
8
2
|
require "#{LIB_DIR}/util/tk/finder"
|
9
3
|
|
10
4
|
require_relative 'base'
|
5
|
+
require_relative 'window_info'
|
11
6
|
|
12
7
|
class TkWrapper::Widgets::Base::Widget
|
13
8
|
extend Forwardable
|
14
|
-
include TkExtensions
|
15
9
|
include Enumerable
|
16
10
|
|
17
|
-
|
18
|
-
|
11
|
+
def_delegators :@finder, :find, :find_all
|
12
|
+
def_delegators :tk_widget, :update
|
13
|
+
def_delegator :tk_widget, :bind_append, :bind
|
14
|
+
def_delegator :@manager, :widgets, :managed
|
19
15
|
|
20
16
|
attr_accessor :config
|
21
|
-
attr_reader :parent, :ids, :cell, :childs
|
17
|
+
attr_reader :parent, :ids, :cell, :childs, :manager, :winfo
|
22
18
|
|
23
19
|
def tk_class() end
|
24
20
|
|
25
|
-
def
|
26
|
-
@manager ||= TkWrapper::Widgets::Base::Manager.new
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.config(matcher = nil, configuration = nil, **configurations)
|
30
|
-
manager.add_configurations(matcher, configuration, **configurations)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.modify(matcher, &callback)
|
34
|
-
manager.add_modification(matcher, &callback)
|
35
|
-
end
|
36
|
-
|
37
|
-
def manager
|
38
|
-
TkWrapper::Widgets::Base::Widget.manager
|
39
|
-
end
|
40
|
-
|
41
|
-
def each(&block)
|
42
|
-
nodes_to_walk = [self]
|
43
|
-
until nodes_to_walk.empty?
|
44
|
-
node = nodes_to_walk.pop
|
45
|
-
block.call(node)
|
46
|
-
nodes_to_walk = node.childs + nodes_to_walk
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def initialize(config: {}, childs: [], id: nil)
|
21
|
+
def initialize(parent: nil, config: {}, childs: [], manager: nil, ids: [], id: [])
|
51
22
|
@cell = TkWrapper::Util::Tk::Cell.new(self)
|
23
|
+
@winfo = TkWrapper::Widgets::Base::WindowInfo.new(self)
|
52
24
|
@finder = TkWrapper::Util::Tk::Finder.new(widgets: self)
|
53
25
|
@config = TkWrapper::Widgets::Base::Configuration.new(config)
|
54
|
-
@
|
55
|
-
@ids =
|
56
|
-
|
57
|
-
|
26
|
+
@manager = manager
|
27
|
+
@ids = init_id(id) + init_id(ids)
|
28
|
+
@parent = parent
|
29
|
+
modify_configuration(@config)
|
30
|
+
@childs = normalize_childs(childs)
|
31
|
+
parent&.push(self)
|
58
32
|
end
|
59
33
|
|
60
|
-
def
|
61
|
-
|
34
|
+
def init_id(id)
|
35
|
+
id.is_a?(Array) ? id : [id]
|
36
|
+
end
|
62
37
|
|
63
|
-
|
64
|
-
|
38
|
+
def normalize_childs(childs)
|
39
|
+
childs = create_childs || childs
|
40
|
+
childs.is_a?(Array) ? childs : [childs]
|
65
41
|
end
|
66
42
|
|
67
43
|
def create_tk_widget(parent)
|
@@ -69,7 +45,7 @@ class TkWrapper::Widgets::Base::Widget
|
|
69
45
|
|
70
46
|
return unless tk_class
|
71
47
|
|
72
|
-
|
48
|
+
tk_class.new(parent&.tk_widget)
|
73
49
|
end
|
74
50
|
|
75
51
|
# if parent is provided and self has no tk_class, the tk_widget of the
|
@@ -80,41 +56,54 @@ class TkWrapper::Widgets::Base::Widget
|
|
80
56
|
(@tk_widget = create_tk_widget(parent)) || parent&.tk_widget
|
81
57
|
end
|
82
58
|
|
83
|
-
def
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
59
|
+
def each(&block)
|
60
|
+
nodes_to_walk = [self]
|
61
|
+
until nodes_to_walk.empty?
|
62
|
+
node = nodes_to_walk.pop
|
63
|
+
block.call(node)
|
64
|
+
nodes_to_walk = node.childs + nodes_to_walk
|
65
|
+
end
|
90
66
|
end
|
91
67
|
|
92
68
|
def push(child)
|
93
69
|
@childs.push(child)
|
94
|
-
child.build(self)
|
70
|
+
child.build(self, manager: @manager)
|
95
71
|
end
|
96
72
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
@
|
73
|
+
protected
|
74
|
+
|
75
|
+
def build_childs
|
76
|
+
@childs.each { |child| child.build(self, manager: @manager) }
|
101
77
|
end
|
102
78
|
|
103
|
-
def
|
104
|
-
items = find_all(matchers)
|
79
|
+
def modify_configuration(config) end
|
105
80
|
|
106
|
-
|
107
|
-
end
|
81
|
+
def create_childs() end
|
108
82
|
|
109
|
-
def
|
110
|
-
items = find_all(matchers)
|
83
|
+
def before_build(**args) end
|
111
84
|
|
112
|
-
|
85
|
+
def after_build() end
|
113
86
|
|
114
|
-
|
87
|
+
def inner_build(configure: true, manager: nil)
|
88
|
+
tk_widget # creates the widget if possible and not yet created
|
89
|
+
@font = TkWrapper::Util::Tk::Font.new(tk_widget)
|
90
|
+
@manager ||= manager
|
91
|
+
@config.merge(*@manager.configurations(self), overwrite: false) if @manager
|
92
|
+
self.configure if configure
|
93
|
+
@manager&.execute_modifications(self)
|
94
|
+
@manager&.widgets&.push(self)
|
95
|
+
build_childs
|
96
|
+
end
|
115
97
|
|
116
|
-
|
117
|
-
|
118
|
-
|
98
|
+
def build(parent, configure: true, manager: nil)
|
99
|
+
@parent = parent
|
100
|
+
before_build(configure: configure, manager: manager)
|
101
|
+
inner_build(configure: configure, manager: manager)
|
102
|
+
after_build
|
103
|
+
end
|
104
|
+
|
105
|
+
def configure
|
106
|
+
@config.configure_tk_widget(tk_widget)
|
107
|
+
@config.configure_tearoff
|
119
108
|
end
|
120
109
|
end
|
@@ -0,0 +1,38 @@
|
|
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
|
+
(@lookup[nil] ||= []).push(widget) if widget.ids.empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
def each(&block)
|
24
|
+
@lookup.each_value do |widgets|
|
25
|
+
widgets.each { |widget| block.call(widget) }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def [](key)
|
30
|
+
@lookup[key]&.size == 1 ? @lookup[key].first : @lookup[key]
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def map_key?(key)
|
36
|
+
[String, Symbol].include?(key)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class TkWrapper::Widgets::Base::WindowInfo
|
2
|
+
def initialize(widget)
|
3
|
+
@widget = widget
|
4
|
+
end
|
5
|
+
|
6
|
+
def method_missing(name, *args)
|
7
|
+
if @widget.tk_widget.respond_to?("winfo_#{name}")
|
8
|
+
@widget.tk_widget.send("winfo_#{name}", *args)
|
9
|
+
else
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/widgets/entry.rb
CHANGED
data/lib/widgets/frame.rb
CHANGED
data/lib/widgets/grid.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'tkextlib/tile'
|
4
|
+
|
3
5
|
# classification of TkGrid
|
4
6
|
class TkWrapper::Widgets::Grid < TkWrapper::Widgets::Base::Widget
|
5
7
|
attr_reader :parent, :matrix
|
@@ -7,14 +9,16 @@ class TkWrapper::Widgets::Grid < TkWrapper::Widgets::Base::Widget
|
|
7
9
|
Widget = TkWrapper::Widgets::Base::Widget
|
8
10
|
|
9
11
|
def tk_class
|
10
|
-
|
12
|
+
Tk::Tile::Frame
|
11
13
|
end
|
12
14
|
|
13
|
-
def initialize(
|
14
|
-
|
15
|
+
def initialize(**arguments)
|
16
|
+
parent = arguments.delete(:parent)
|
17
|
+
super(**arguments)
|
15
18
|
@childs.map! { |row| row.is_a?(Array) ? row : [row] }
|
16
19
|
configure_cells_for_grid
|
17
20
|
@childs.flatten! && @childs.select! { |cell| cell.is_a?(Widget) }
|
21
|
+
parent&.push(self)
|
18
22
|
end
|
19
23
|
|
20
24
|
def configure_cells_for_grid
|
data/lib/widgets/label.rb
CHANGED
data/lib/widgets/menu.rb
CHANGED
@@ -1,29 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'tk'
|
4
|
+
|
3
5
|
class TkWrapper::Widgets::Menu < TkWrapper::Widgets::Base::Widget
|
4
6
|
def tk_class
|
5
|
-
|
7
|
+
TkMenu
|
6
8
|
end
|
7
9
|
|
8
|
-
def build(parent)
|
9
|
-
super(parent)
|
10
|
+
def build(parent, **args)
|
11
|
+
super(parent, **args)
|
10
12
|
parent.tk_widget['menu'] = tk_widget
|
11
13
|
end
|
12
14
|
|
13
15
|
class Cascade < TkWrapper::Widgets::Base::Widget
|
14
16
|
def tk_class
|
15
|
-
|
17
|
+
TkMenu
|
16
18
|
end
|
17
19
|
|
18
|
-
def build(parent)
|
19
|
-
|
20
|
+
def build(parent, **args)
|
21
|
+
args[:configure] = false
|
22
|
+
super(parent, **args)
|
20
23
|
@config[:menu] = tk_widget
|
21
24
|
parent.tk_widget.add :cascade, **@config.config
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
28
|
class Command < TkWrapper::Widgets::Base::Widget
|
26
|
-
def build(parent)
|
29
|
+
def build(parent, **args)
|
30
|
+
args[:configure] = false
|
31
|
+
super(parent, **args)
|
27
32
|
parent.tk_widget.add :command, **@config.config
|
28
33
|
end
|
29
34
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class TkWrapper::Widgets::MountPoint < TkWrapper::Widgets::Base::Widget
|
4
|
+
def initialize(**args)
|
5
|
+
super(**args)
|
6
|
+
end
|
7
|
+
|
8
|
+
def build_childs(skip: true)
|
9
|
+
super() unless skip
|
10
|
+
end
|
11
|
+
|
12
|
+
def mount=(childs)
|
13
|
+
mount(childs)
|
14
|
+
end
|
15
|
+
|
16
|
+
def mount(childs = nil)
|
17
|
+
if childs
|
18
|
+
@childs = childs.is_a?(Array) ? childs : [childs]
|
19
|
+
end
|
20
|
+
@childs.each do |child|
|
21
|
+
child.config.merge(@config)
|
22
|
+
end
|
23
|
+
build_childs(skip: false)
|
24
|
+
end
|
25
|
+
end
|
data/lib/widgets/root.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'tk'
|
4
|
+
|
3
5
|
class TkWrapper::Widgets::Root < TkWrapper::Widgets::Base::Widget
|
4
6
|
def initialize(**arguments)
|
5
7
|
super(**arguments)
|
@@ -7,6 +9,6 @@ class TkWrapper::Widgets::Root < TkWrapper::Widgets::Base::Widget
|
|
7
9
|
end
|
8
10
|
|
9
11
|
def tk_class
|
10
|
-
|
12
|
+
TkRoot
|
11
13
|
end
|
12
14
|
end
|
data/lib/widgets/text.rb
CHANGED
data/lib/widgets/widgets.rb
CHANGED
@@ -9,6 +9,9 @@ require_relative 'frame'
|
|
9
9
|
require_relative 'label'
|
10
10
|
require_relative 'menu'
|
11
11
|
require_relative 'text'
|
12
|
+
require_relative 'auto_resize_text'
|
12
13
|
require_relative 'entry'
|
13
14
|
require_relative 'auto_resize_entry'
|
14
15
|
require_relative 'grid'
|
16
|
+
require_relative 'mount_point'
|
17
|
+
require_relative 'button'
|
metadata
CHANGED
@@ -1,22 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tkwrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.1
|
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-21 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: []
|
16
30
|
extensions: []
|
17
31
|
extra_rdoc_files: []
|
18
32
|
files:
|
19
|
-
- lib/tk_extensions.rb
|
20
33
|
- lib/tkwrapper.rb
|
21
34
|
- lib/util/hash_recursive.rb
|
22
35
|
- lib/util/tk/cell.rb
|
@@ -25,6 +38,7 @@ files:
|
|
25
38
|
- lib/util/tk/tk.rb
|
26
39
|
- lib/util/virtual_methods.rb
|
27
40
|
- lib/widgets/auto_resize_entry.rb
|
41
|
+
- lib/widgets/auto_resize_text.rb
|
28
42
|
- lib/widgets/base/base.rb
|
29
43
|
- lib/widgets/base/comparator_item_store.rb
|
30
44
|
- lib/widgets/base/configuration.rb
|
@@ -33,11 +47,15 @@ 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
|
51
|
+
- lib/widgets/base/window_info.rb
|
52
|
+
- lib/widgets/button.rb
|
36
53
|
- lib/widgets/entry.rb
|
37
54
|
- lib/widgets/frame.rb
|
38
55
|
- lib/widgets/grid.rb
|
39
56
|
- lib/widgets/label.rb
|
40
57
|
- lib/widgets/menu.rb
|
58
|
+
- lib/widgets/mount_point.rb
|
41
59
|
- lib/widgets/root.rb
|
42
60
|
- lib/widgets/text.rb
|
43
61
|
- lib/widgets/widgets.rb
|
data/lib/tk_extensions.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'tk'
|
2
|
-
require 'tkextlib/tile'
|
3
|
-
|
4
|
-
module TkExtensions
|
5
|
-
# allow a Tk widget to have multiple bindings for the same event
|
6
|
-
module MultiBind
|
7
|
-
def bind(event, &callback)
|
8
|
-
@bindings ||= {}
|
9
|
-
|
10
|
-
unless @bindings[event]
|
11
|
-
@bindings[event] = []
|
12
|
-
super(event) { execute_all_bindings(event) }
|
13
|
-
end
|
14
|
-
|
15
|
-
@bindings[event].push(callback)
|
16
|
-
end
|
17
|
-
|
18
|
-
def execute_all_bindings(event)
|
19
|
-
@bindings[event].each(&:call)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module TkWidgets
|
24
|
-
# from several Tk widgets create subclasses, which include MultiBind
|
25
|
-
# the reason why we loop over strings and not the classes themselve is, that
|
26
|
-
# the class names may be aliases (e.g. Tk::Tile::Entry is an alias for
|
27
|
-
# Tk::Tile::TEntry)
|
28
|
-
tk_class_names = [
|
29
|
-
'TkRoot', # becomes TkExtensions::TkRoot
|
30
|
-
'TkText', # becomes TkExtensions::TkText
|
31
|
-
'TkMenu', # becomes TkExtensions::TkMenu
|
32
|
-
'Tk::Tile::Entry', # becomes TkExtensions::Entry
|
33
|
-
'Tk::Tile::Frame', # becomes TkExtensions::Frame
|
34
|
-
'Tk::Tile::Label' # becomes TkExtensions::Label
|
35
|
-
]
|
36
|
-
tk_class_names.each do |tk_class_name|
|
37
|
-
# extract last part of the name (e.g. Tk::Tile::Entry => Entry)
|
38
|
-
new_child_class_name = tk_class_name.match(/([^:]*)$/)[1]
|
39
|
-
# get the class from the class constant name
|
40
|
-
tk_class = const_get(tk_class_name)
|
41
|
-
# create a new child class of tk_class and have it include MultiBind, which
|
42
|
-
# overwrites the bind method of that class to allow for multiple bindings
|
43
|
-
new_child_class = Class.new(tk_class) { include(MultiBind) }
|
44
|
-
# make the new class known to the TkExtensions namespace to allow to use it
|
45
|
-
# by e.g. TkExtensions::Entry
|
46
|
-
const_set(new_child_class_name, new_child_class)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|