tkwrapper 1.6.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/util/hash_recursive.rb +2 -2
- data/lib/widgets/auto_resize_entry.rb +1 -1
- data/lib/widgets/auto_resize_text.rb +25 -0
- data/lib/widgets/base/configuration.rb +2 -2
- data/lib/widgets/base/matcher.rb +1 -1
- data/lib/widgets/base/matches.rb +4 -4
- data/lib/widgets/base/widget.rb +51 -22
- data/lib/widgets/button.rb +3 -1
- data/lib/widgets/entry.rb +3 -1
- data/lib/widgets/frame.rb +3 -1
- data/lib/widgets/grid.rb +5 -1
- data/lib/widgets/label.rb +3 -1
- data/lib/widgets/menu.rb +4 -2
- data/lib/widgets/root.rb +3 -1
- data/lib/widgets/text.rb +3 -1
- data/lib/widgets/widgets.rb +1 -0
- metadata +3 -3
- data/lib/tk_extensions.rb +0 -50
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/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
|
@@ -12,7 +12,7 @@ class TkWrapper::Widgets::AutoResizeEntry < TkWrapper::Widgets::Entry
|
|
12
12
|
|
13
13
|
def build(parent, **args)
|
14
14
|
super(parent, **args)
|
15
|
-
parent.
|
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
|
@@ -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
|
@@ -28,14 +28,14 @@ class TkWrapper::Widgets::Base::Configuration
|
|
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)
|
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,10 @@ 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
34
|
|
data/lib/widgets/base/widget.rb
CHANGED
@@ -1,30 +1,43 @@
|
|
1
1
|
require "#{LIB_DIR}/util/tk/cell"
|
2
2
|
require "#{LIB_DIR}/util/tk/finder"
|
3
|
-
require "#{LIB_DIR}/tk_extensions"
|
4
3
|
|
5
4
|
require_relative 'base'
|
6
5
|
require_relative 'window_info'
|
7
6
|
|
8
7
|
class TkWrapper::Widgets::Base::Widget
|
9
8
|
extend Forwardable
|
10
|
-
include TkExtensions
|
11
9
|
include Enumerable
|
12
10
|
|
13
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
|
14
15
|
|
15
16
|
attr_accessor :config
|
16
17
|
attr_reader :parent, :ids, :cell, :childs, :manager, :winfo
|
17
18
|
|
18
19
|
def tk_class() end
|
19
20
|
|
20
|
-
def initialize(config: {}, childs: [], manager: nil, ids: [])
|
21
|
+
def initialize(parent: nil, config: {}, childs: [], manager: nil, ids: [], id: [])
|
21
22
|
@cell = TkWrapper::Util::Tk::Cell.new(self)
|
22
23
|
@winfo = TkWrapper::Widgets::Base::WindowInfo.new(self)
|
23
24
|
@finder = TkWrapper::Util::Tk::Finder.new(widgets: self)
|
24
25
|
@config = TkWrapper::Widgets::Base::Configuration.new(config)
|
25
|
-
@childs = childs.is_a?(Array) ? childs : [childs]
|
26
26
|
@manager = manager
|
27
|
-
@ids =
|
27
|
+
@ids = init_id(id) + init_id(ids)
|
28
|
+
@parent = parent
|
29
|
+
modify_configuration(@config)
|
30
|
+
@childs = normalize_childs(childs)
|
31
|
+
parent&.push(self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def init_id(id)
|
35
|
+
id.is_a?(Array) ? id : [id]
|
36
|
+
end
|
37
|
+
|
38
|
+
def normalize_childs(childs)
|
39
|
+
childs = create_childs || childs
|
40
|
+
childs.is_a?(Array) ? childs : [childs]
|
28
41
|
end
|
29
42
|
|
30
43
|
def create_tk_widget(parent)
|
@@ -43,38 +56,54 @@ class TkWrapper::Widgets::Base::Widget
|
|
43
56
|
(@tk_widget = create_tk_widget(parent)) || parent&.tk_widget
|
44
57
|
end
|
45
58
|
|
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
|
66
|
+
end
|
67
|
+
|
68
|
+
def push(child)
|
69
|
+
@childs.push(child)
|
70
|
+
child.build(self, manager: @manager)
|
71
|
+
end
|
72
|
+
|
73
|
+
protected
|
74
|
+
|
46
75
|
def build_childs
|
47
76
|
@childs.each { |child| child.build(self, manager: @manager) }
|
48
77
|
end
|
49
78
|
|
50
|
-
def
|
51
|
-
|
79
|
+
def modify_configuration(config) end
|
80
|
+
|
81
|
+
def create_childs() end
|
82
|
+
|
83
|
+
def before_build(**args) end
|
84
|
+
|
85
|
+
def after_build() end
|
86
|
+
|
87
|
+
def inner_build(configure: true, manager: nil)
|
52
88
|
tk_widget # creates the widget if possible and not yet created
|
53
89
|
@font = TkWrapper::Util::Tk::Font.new(tk_widget)
|
54
90
|
@manager ||= manager
|
55
|
-
@config.merge(*@manager.configurations(self)) if @manager
|
91
|
+
@config.merge(*@manager.configurations(self), overwrite: false) if @manager
|
56
92
|
self.configure if configure
|
57
93
|
@manager&.execute_modifications(self)
|
58
94
|
@manager&.widgets&.push(self)
|
59
95
|
build_childs
|
60
96
|
end
|
61
97
|
|
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
|
+
|
62
105
|
def configure
|
63
106
|
@config.configure_tk_widget(tk_widget)
|
64
107
|
@config.configure_tearoff
|
65
108
|
end
|
66
|
-
|
67
|
-
def each(&block)
|
68
|
-
nodes_to_walk = [self]
|
69
|
-
until nodes_to_walk.empty?
|
70
|
-
node = nodes_to_walk.pop
|
71
|
-
block.call(node)
|
72
|
-
nodes_to_walk = node.childs + nodes_to_walk
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def push(child)
|
77
|
-
@childs.push(child)
|
78
|
-
child.build(self, manager: @manager)
|
79
|
-
end
|
80
109
|
end
|
data/lib/widgets/button.rb
CHANGED
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
15
|
def initialize(**arguments)
|
16
|
+
parent = arguments.delete(:parent)
|
14
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,8 +1,10 @@
|
|
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
10
|
def build(parent, **args)
|
@@ -12,7 +14,7 @@ class TkWrapper::Widgets::Menu < TkWrapper::Widgets::Base::Widget
|
|
12
14
|
|
13
15
|
class Cascade < TkWrapper::Widgets::Base::Widget
|
14
16
|
def tk_class
|
15
|
-
|
17
|
+
TkMenu
|
16
18
|
end
|
17
19
|
|
18
20
|
def build(parent, **args)
|
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
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.6.
|
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-
|
11
|
+
date: 2021-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tk
|
@@ -30,7 +30,6 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
-
- lib/tk_extensions.rb
|
34
33
|
- lib/tkwrapper.rb
|
35
34
|
- lib/util/hash_recursive.rb
|
36
35
|
- lib/util/tk/cell.rb
|
@@ -39,6 +38,7 @@ files:
|
|
39
38
|
- lib/util/tk/tk.rb
|
40
39
|
- lib/util/virtual_methods.rb
|
41
40
|
- lib/widgets/auto_resize_entry.rb
|
41
|
+
- lib/widgets/auto_resize_text.rb
|
42
42
|
- lib/widgets/base/base.rb
|
43
43
|
- lib/widgets/base/comparator_item_store.rb
|
44
44
|
- lib/widgets/base/configuration.rb
|
data/lib/tk_extensions.rb
DELETED
@@ -1,50 +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::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
|
36
|
-
]
|
37
|
-
tk_class_names.each do |tk_class_name|
|
38
|
-
# extract last part of the name (e.g. Tk::Tile::Entry => Entry)
|
39
|
-
new_child_class_name = tk_class_name.match(/([^:]*)$/)[1]
|
40
|
-
# get the class from the class constant name
|
41
|
-
tk_class = const_get(tk_class_name)
|
42
|
-
# create a new child class of tk_class and have it include MultiBind, which
|
43
|
-
# overwrites the bind method of that class to allow for multiple bindings
|
44
|
-
new_child_class = Class.new(tk_class) { include(MultiBind) }
|
45
|
-
# make the new class known to the TkExtensions namespace to allow to use it
|
46
|
-
# by e.g. TkExtensions::Entry
|
47
|
-
const_set(new_child_class_name, new_child_class)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|