tkwrapper 1.3.0 → 1.4.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 +1 -0
- data/lib/util/tk/finder.rb +2 -2
- data/lib/widgets/auto_resize_entry.rb +6 -6
- data/lib/widgets/base/configuration.rb +3 -1
- data/lib/widgets/base/manager.rb +7 -0
- data/lib/widgets/base/widget.rb +21 -68
- data/lib/widgets/grid.rb +2 -2
- data/lib/widgets/menu.rb +8 -5
- 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: 81c1971220f794d1e17288aac5b75221393727be934288a4993a621c35b3282d
|
4
|
+
data.tar.gz: f2a841f6f3a6a7ee040c85fe0f2081234780bf1ff0bf4aeb70de9cf4c2a75055
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22cf843324096411be2441088df910d723ecc353aa6b54dd64ba5703b2fcd47bec3c2424a38e910fefb187fdcf23ec60dd44640de3f0657a3cb2969e84da016c
|
7
|
+
data.tar.gz: acb296b0e78c570e7d80ba96d91c4ebf62ecfd1ce7c97fac088546d599e0468a23dafac325ee14ae9fa0d4d08a9c8c70e5972df849346a05d8e2ac3ee9fb1154
|
data/lib/tkwrapper.rb
CHANGED
data/lib/util/tk/finder.rb
CHANGED
@@ -21,7 +21,7 @@ class TkWrapper::Util::Tk::Finder
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def find(comparators, widgets = @widgets)
|
25
25
|
matchers = create_value_matchers(comparators)
|
26
26
|
|
27
27
|
each_widget_match(widgets, matchers) do |match|
|
@@ -29,7 +29,7 @@ class TkWrapper::Util::Tk::Finder
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def find_all(comparators, widgets = @widgets)
|
33
33
|
matchers = create_value_matchers(comparators)
|
34
34
|
matches = TkWrapper::Widgets::Base::Matches.new
|
35
35
|
|
@@ -4,14 +4,14 @@ 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[:min_width] || 0
|
9
|
-
@add_width = config[:add_width] || 0
|
10
|
-
super(
|
7
|
+
def initialize(**args)
|
8
|
+
@min_width = args[:config][:min_width] || 0
|
9
|
+
@add_width = args[:config][:add_width] || 0
|
10
|
+
super(**args)
|
11
11
|
end
|
12
12
|
|
13
|
-
def build(parent,
|
14
|
-
super(parent,
|
13
|
+
def build(parent, **args)
|
14
|
+
super(parent, **args)
|
15
15
|
parent.tk_widget.bind('Configure') { resize }
|
16
16
|
tk_widget.textvariable = TkVariable.new unless tk_widget.textvariable
|
17
17
|
tk_widget.textvariable.trace('write') { resize }
|
@@ -21,7 +21,7 @@ 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)
|
@@ -112,6 +112,8 @@ class TkWrapper::Widgets::Base::Configuration
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def merge_global_configurations(manager, widget)
|
115
|
+
return unless manager
|
116
|
+
|
115
117
|
merge(*manager.configurations(widget))
|
116
118
|
end
|
117
119
|
end
|
data/lib/widgets/base/manager.rb
CHANGED
data/lib/widgets/base/widget.rb
CHANGED
@@ -1,11 +1,6 @@
|
|
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"
|
3
|
+
require "#{LIB_DIR}/tk_extensions"
|
9
4
|
|
10
5
|
require_relative 'base'
|
11
6
|
|
@@ -14,54 +9,20 @@ class TkWrapper::Widgets::Base::Widget
|
|
14
9
|
include TkExtensions
|
15
10
|
include Enumerable
|
16
11
|
|
17
|
-
|
18
|
-
def_delegator :@finder, :find_all_widgets, :find_all
|
12
|
+
def_delegators :@finder, :find, :find_all
|
19
13
|
|
20
14
|
attr_accessor :config
|
21
|
-
attr_reader :parent, :ids, :cell, :childs
|
15
|
+
attr_reader :parent, :ids, :cell, :childs, :manager
|
22
16
|
|
23
17
|
def tk_class() end
|
24
18
|
|
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)
|
19
|
+
def initialize(config: {}, childs: [], manager: nil, ids: [])
|
51
20
|
@cell = TkWrapper::Util::Tk::Cell.new(self)
|
52
21
|
@finder = TkWrapper::Util::Tk::Finder.new(widgets: self)
|
53
22
|
@config = TkWrapper::Widgets::Base::Configuration.new(config)
|
54
23
|
@childs = childs.is_a?(Array) ? childs : [childs]
|
55
|
-
@
|
56
|
-
|
57
|
-
add_ids(config[:id])
|
58
|
-
end
|
59
|
-
|
60
|
-
def add_ids(ids)
|
61
|
-
return unless ids
|
62
|
-
|
63
|
-
ids = [ids] unless ids.is_a?(Array)
|
64
|
-
@ids.concat(ids)
|
24
|
+
@manager = manager
|
25
|
+
@ids = ids.is_a?(Array) ? ids : [ids]
|
65
26
|
end
|
66
27
|
|
67
28
|
def create_tk_widget(parent)
|
@@ -80,41 +41,33 @@ class TkWrapper::Widgets::Base::Widget
|
|
80
41
|
(@tk_widget = create_tk_widget(parent)) || parent&.tk_widget
|
81
42
|
end
|
82
43
|
|
83
|
-
def build(parent, configure: true)
|
44
|
+
def build(parent, configure: true, manager: nil)
|
84
45
|
@parent = parent
|
85
46
|
tk_widget # creates the widget if possible and not yet created
|
86
47
|
@font = TkWrapper::Util::Tk::Font.new(tk_widget)
|
48
|
+
@manager ||= manager
|
49
|
+
@config.merge(*@manager.configurations(self)) if @manager
|
87
50
|
self.configure if configure
|
88
|
-
manager
|
89
|
-
@childs.each { |child| child.build(self) }
|
90
|
-
end
|
91
|
-
|
92
|
-
def push(child)
|
93
|
-
@childs.push(child)
|
94
|
-
child.build(self)
|
51
|
+
@manager&.execute_modifications(self)
|
52
|
+
@childs.each { |child| child.build(self, manager: @manager) }
|
95
53
|
end
|
96
54
|
|
97
55
|
def configure
|
98
|
-
@config.merge_global_configurations(manager, self)
|
99
56
|
@config.configure_tk_widget(tk_widget)
|
100
57
|
@config.configure_tearoff
|
101
58
|
end
|
102
59
|
|
103
|
-
def
|
104
|
-
|
105
|
-
|
106
|
-
|
60
|
+
def each(&block)
|
61
|
+
nodes_to_walk = [self]
|
62
|
+
until nodes_to_walk.empty?
|
63
|
+
node = nodes_to_walk.pop
|
64
|
+
block.call(node)
|
65
|
+
nodes_to_walk = node.childs + nodes_to_walk
|
66
|
+
end
|
107
67
|
end
|
108
68
|
|
109
|
-
def
|
110
|
-
|
111
|
-
|
112
|
-
return unless items
|
113
|
-
|
114
|
-
with_match = items[0].is_a?(Array)
|
115
|
-
|
116
|
-
items.each do |item|
|
117
|
-
with_match ? callback.call(item[0], item[1]) : callback.call(item)
|
118
|
-
end
|
69
|
+
def push(child)
|
70
|
+
@childs.push(child)
|
71
|
+
child.build(self)
|
119
72
|
end
|
120
73
|
end
|
data/lib/widgets/grid.rb
CHANGED
@@ -10,8 +10,8 @@ class TkWrapper::Widgets::Grid < TkWrapper::Widgets::Base::Widget
|
|
10
10
|
TkWidgets::Frame
|
11
11
|
end
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
super(
|
13
|
+
def initialize(**arguments)
|
14
|
+
super(**arguments)
|
15
15
|
@childs.map! { |row| row.is_a?(Array) ? row : [row] }
|
16
16
|
configure_cells_for_grid
|
17
17
|
@childs.flatten! && @childs.select! { |cell| cell.is_a?(Widget) }
|
data/lib/widgets/menu.rb
CHANGED
@@ -5,8 +5,8 @@ class TkWrapper::Widgets::Menu < TkWrapper::Widgets::Base::Widget
|
|
5
5
|
TkWidgets::TkMenu
|
6
6
|
end
|
7
7
|
|
8
|
-
def build(parent)
|
9
|
-
super(parent)
|
8
|
+
def build(parent, **args)
|
9
|
+
super(parent, **args)
|
10
10
|
parent.tk_widget['menu'] = tk_widget
|
11
11
|
end
|
12
12
|
|
@@ -15,15 +15,18 @@ class TkWrapper::Widgets::Menu < TkWrapper::Widgets::Base::Widget
|
|
15
15
|
TkWidgets::TkMenu
|
16
16
|
end
|
17
17
|
|
18
|
-
def build(parent)
|
19
|
-
|
18
|
+
def build(parent, **args)
|
19
|
+
args[:configure] = false
|
20
|
+
super(parent, **args)
|
20
21
|
@config[:menu] = tk_widget
|
21
22
|
parent.tk_widget.add :cascade, **@config.config
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
26
|
class Command < TkWrapper::Widgets::Base::Widget
|
26
|
-
def build(parent)
|
27
|
+
def build(parent, **args)
|
28
|
+
args[:configure] = false
|
29
|
+
super(parent, **args)
|
27
30
|
parent.tk_widget.add :command, **@config.config
|
28
31
|
end
|
29
32
|
end
|