tkwrapper 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tk_extensions.rb +7 -6
- data/lib/util/tk/cell.rb +1 -0
- data/lib/util/tk/finder.rb +3 -2
- data/lib/widgets/base/configuration.rb +12 -6
- data/lib/widgets/base/manager.rb +4 -0
- data/lib/widgets/base/widget.rb +10 -4
- data/lib/widgets/base/widget_store.rb +2 -1
- data/lib/widgets/base/window_info.rb +13 -0
- data/lib/widgets/button.rb +7 -0
- data/lib/widgets/mount_point.rb +25 -0
- data/lib/widgets/widgets.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25ebb6c8831b18ae3b55f4d98896cc5cf824d628fd4bc245b6fc1ed9fd8c5ef0
|
4
|
+
data.tar.gz: b90ca62d87faa02e1a07f5f1145e175d55dfcfeacd71782c709a484038701dfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4d1820254e60b3d9ce4be52a8875b0acbda213dac7aa200352d794ff1146611e84ac1f9bb16589f6fa6d61ba3b65468c940cf27d965ead1e3913fbc5b1cce7e
|
7
|
+
data.tar.gz: fd00a3c5ae1c29aa66762f554a43223a5ce32ef538c340a8549ba56fb12853743f80ae90862aac30f99383be61497fe1744bbb85e7ca7ef1e83d32785e4f5133
|
data/lib/tk_extensions.rb
CHANGED
@@ -26,12 +26,13 @@ module TkExtensions
|
|
26
26
|
# the class names may be aliases (e.g. Tk::Tile::Entry is an alias for
|
27
27
|
# Tk::Tile::TEntry)
|
28
28
|
tk_class_names = [
|
29
|
-
'TkRoot',
|
30
|
-
'TkText',
|
31
|
-
'TkMenu',
|
32
|
-
'Tk::Tile::Entry',
|
33
|
-
'Tk::Tile::Frame',
|
34
|
-
'Tk::Tile::Label' # becomes TkExtensions::Label
|
29
|
+
'TkRoot', # becomes TkExtensions::TkWidgets::TkRoot
|
30
|
+
'TkText', # becomes TkExtensions::TkWidgets::TkText
|
31
|
+
'TkMenu', # becomes TkExtensions::TkWidgets::TkMenu
|
32
|
+
'Tk::Tile::Entry', # becomes TkExtensions::TkWidgets::Entry
|
33
|
+
'Tk::Tile::Frame', # becomes TkExtensions::TkWidgets::Frame
|
34
|
+
'Tk::Tile::Label', # becomes TkExtensions::TkWidgets::Label
|
35
|
+
'Tk::Tile::Button' # becomes TkExtensions::TkWidgets::Button
|
35
36
|
]
|
36
37
|
tk_class_names.each do |tk_class_name|
|
37
38
|
# extract last part of the name (e.g. Tk::Tile::Entry => Entry)
|
data/lib/util/tk/cell.rb
CHANGED
data/lib/util/tk/finder.rb
CHANGED
@@ -15,6 +15,7 @@ class TkWrapper::Util::Tk::Finder
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def iter(comparators, widgets = @widgets, lookup = @lookup)
|
18
|
+
comparators = [comparators] unless comparators.is_a?(Array)
|
18
19
|
Enumerator.new do |y|
|
19
20
|
comparators = each_widget_lookup_match(lookup, comparators) { |m| y << m }
|
20
21
|
each_widget_comparator_match(widgets, comparators) { |m| y << m }
|
@@ -33,7 +34,6 @@ class TkWrapper::Util::Tk::Finder
|
|
33
34
|
private
|
34
35
|
|
35
36
|
def create_value_matchers(comparators)
|
36
|
-
comparators = [comparators] unless comparators.is_a?(Array)
|
37
37
|
comparators.map { |comparator| Matcher.new(comparator: comparator) }
|
38
38
|
end
|
39
39
|
|
@@ -55,7 +55,8 @@ class TkWrapper::Util::Tk::Finder
|
|
55
55
|
matchers = create_value_matchers(comparators)
|
56
56
|
|
57
57
|
widgets.each do |widget|
|
58
|
-
widget.ids.
|
58
|
+
ids = widget.ids.empty? ? [nil] : widget.ids
|
59
|
+
ids.each do |id|
|
59
60
|
matchers.each do |matcher|
|
60
61
|
(match = matcher.match(id, widget)) && block.call(match)
|
61
62
|
end
|
@@ -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)
|
data/lib/widgets/base/manager.rb
CHANGED
data/lib/widgets/base/widget.rb
CHANGED
@@ -3,6 +3,7 @@ require "#{LIB_DIR}/util/tk/finder"
|
|
3
3
|
require "#{LIB_DIR}/tk_extensions"
|
4
4
|
|
5
5
|
require_relative 'base'
|
6
|
+
require_relative 'window_info'
|
6
7
|
|
7
8
|
class TkWrapper::Widgets::Base::Widget
|
8
9
|
extend Forwardable
|
@@ -12,12 +13,13 @@ class TkWrapper::Widgets::Base::Widget
|
|
12
13
|
def_delegators :@finder, :find, :find_all
|
13
14
|
|
14
15
|
attr_accessor :config
|
15
|
-
attr_reader :parent, :ids, :cell, :childs, :manager
|
16
|
+
attr_reader :parent, :ids, :cell, :childs, :manager, :winfo
|
16
17
|
|
17
18
|
def tk_class() end
|
18
19
|
|
19
20
|
def initialize(config: {}, childs: [], manager: nil, ids: [])
|
20
21
|
@cell = TkWrapper::Util::Tk::Cell.new(self)
|
22
|
+
@winfo = TkWrapper::Widgets::Base::WindowInfo.new(self)
|
21
23
|
@finder = TkWrapper::Util::Tk::Finder.new(widgets: self)
|
22
24
|
@config = TkWrapper::Widgets::Base::Configuration.new(config)
|
23
25
|
@childs = childs.is_a?(Array) ? childs : [childs]
|
@@ -30,7 +32,7 @@ class TkWrapper::Widgets::Base::Widget
|
|
30
32
|
|
31
33
|
return unless tk_class
|
32
34
|
|
33
|
-
|
35
|
+
tk_class.new(parent&.tk_widget)
|
34
36
|
end
|
35
37
|
|
36
38
|
# if parent is provided and self has no tk_class, the tk_widget of the
|
@@ -41,6 +43,10 @@ class TkWrapper::Widgets::Base::Widget
|
|
41
43
|
(@tk_widget = create_tk_widget(parent)) || parent&.tk_widget
|
42
44
|
end
|
43
45
|
|
46
|
+
def build_childs
|
47
|
+
@childs.each { |child| child.build(self, manager: @manager) }
|
48
|
+
end
|
49
|
+
|
44
50
|
def build(parent, configure: true, manager: nil)
|
45
51
|
@parent = parent
|
46
52
|
tk_widget # creates the widget if possible and not yet created
|
@@ -50,7 +56,7 @@ class TkWrapper::Widgets::Base::Widget
|
|
50
56
|
self.configure if configure
|
51
57
|
@manager&.execute_modifications(self)
|
52
58
|
@manager&.widgets&.push(self)
|
53
|
-
|
59
|
+
build_childs
|
54
60
|
end
|
55
61
|
|
56
62
|
def configure
|
@@ -69,6 +75,6 @@ class TkWrapper::Widgets::Base::Widget
|
|
69
75
|
|
70
76
|
def push(child)
|
71
77
|
@childs.push(child)
|
72
|
-
child.build(self)
|
78
|
+
child.build(self, manager: @manager)
|
73
79
|
end
|
74
80
|
end
|
@@ -17,6 +17,7 @@ class TkWrapper::Widgets::Base::WidgetStore
|
|
17
17
|
widget.ids.each do |id|
|
18
18
|
(@lookup[id] ||= []).push(widget)
|
19
19
|
end
|
20
|
+
(@lookup[nil] ||= []).push(widget) if widget.ids.empty?
|
20
21
|
end
|
21
22
|
|
22
23
|
def each(&block)
|
@@ -26,7 +27,7 @@ class TkWrapper::Widgets::Base::WidgetStore
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def [](key)
|
29
|
-
@lookup[key]
|
30
|
+
@lookup[key]&.size == 1 ? @lookup[key].first : @lookup[key]
|
30
31
|
end
|
31
32
|
|
32
33
|
private
|
@@ -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
|
@@ -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/widgets.rb
CHANGED
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.6.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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tk
|
@@ -48,11 +48,14 @@ files:
|
|
48
48
|
- lib/widgets/base/matches.rb
|
49
49
|
- lib/widgets/base/widget.rb
|
50
50
|
- lib/widgets/base/widget_store.rb
|
51
|
+
- lib/widgets/base/window_info.rb
|
52
|
+
- lib/widgets/button.rb
|
51
53
|
- lib/widgets/entry.rb
|
52
54
|
- lib/widgets/frame.rb
|
53
55
|
- lib/widgets/grid.rb
|
54
56
|
- lib/widgets/label.rb
|
55
57
|
- lib/widgets/menu.rb
|
58
|
+
- lib/widgets/mount_point.rb
|
56
59
|
- lib/widgets/root.rb
|
57
60
|
- lib/widgets/text.rb
|
58
61
|
- lib/widgets/widgets.rb
|