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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 957efe49807e9800759aa22439bc99f5ea4ef0ec620bc7ea0b7d549474839a7a
4
- data.tar.gz: f654e23817c14ce6e59d67e7893f55c33c9168686faf66cbf0a96f955f4e7c6e
3
+ metadata.gz: a67fc8eac231f5b0b875cdd2fba4f107a3b596206766a4e57793e4f3d1b71992
4
+ data.tar.gz: 9bd2376b17ebf7e866f7858f98d2e9698575dec8a3fa2794c84c7b625048b33c
5
5
  SHA512:
6
- metadata.gz: 4891b05ca78bff3d2119b6b4d8ba0be178836d1cdd7475e07ddc3be19100d766e0ca0d9878d4afc9be330ffbf3ea008914d4f4432b0e3eff2df8cc02534b74f4
7
- data.tar.gz: 3ece495be24159cefde0ca65899c3022b181a3bb0d92e40727a9cbc2ca4494d376504a58313190a94fbf4dc8751949873753ec1c2313d9db4cc28fb29174a466
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 end
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
@@ -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
@@ -17,6 +17,7 @@ class TkWrapper::Util::Tk::Cell
17
17
  start_row = grid_info['row']
18
18
  end_row = start_row + grid_info['rowspan'] - 1
19
19
 
20
+ container.tk_widget.update
20
21
  TkGrid.bbox(container.tk_widget, start_col, start_row, end_col, end_row)
21
22
  end
22
23
 
@@ -2,48 +2,65 @@
2
2
 
3
3
  require "#{LIB_DIR}/widgets/base/manager"
4
4
  require "#{LIB_DIR}/widgets/base/matcher"
5
- require_relative 'tk'
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 each_widget_match(widgets, matchers, &block)
15
- widgets.each do |widget|
16
- widget.ids.each do |id|
17
- matchers.each do |matcher|
18
- (match = matcher.match(id, widget)) && block.call(match)
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 find_widget(comparators, widgets = @widgets)
25
- matchers = create_value_matchers(comparators)
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 find_all_widgets(comparators, widgets = @widgets)
33
- matchers = create_value_matchers(comparators)
34
- matches = TkWrapper::Widgets::Base::Matches.new
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(config: {}, childs: [], id: nil)
8
- @min_width = config[:min_width] || 0
9
- @add_width = config[:add_width] || 0
10
- super(config: config, childs: childs, id: id)
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, configure: true)
14
- super(parent, configure: configure)
15
- parent.tk_widget.bind('Configure') { resize }
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 [String, Symbol].include?(key)
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
- id tk_class tearoff weights menu min_width add_width
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
- if option == :grid
85
- grid = grid(only_tk_options: true)
86
- next if grid.empty?
87
- next tk_widget.grid(grid) if option == :grid
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
@@ -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
@@ -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, { widget: widget })
42
+ when nil then Match.new(value, widget: widget)
43
43
  else false
44
44
  end
45
45
  end
@@ -25,10 +25,14 @@ class TkWrapper::Widgets::Base::Matches
25
25
  end
26
26
 
27
27
  def [](key)
28
- case @matches[key].size
29
- when 0 then nil
30
- when 1 then @matches[key][0]
31
- else @matches[key]
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
@@ -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
- def_delegator :@finder, :find_widget, :find
18
- def_delegator :@finder, :find_all_widgets, :find_all
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 self.manager
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
- @childs = childs.is_a?(Array) ? childs : [childs]
55
- @ids = []
56
- add_ids(id)
57
- add_ids(config[:id])
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 add_ids(ids)
61
- return unless ids
34
+ def init_id(id)
35
+ id.is_a?(Array) ? id : [id]
36
+ end
62
37
 
63
- ids = [ids] unless ids.is_a?(Array)
64
- @ids.concat(ids)
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
- parent&.tk_widget ? tk_class.new(parent.tk_widget) : tk_class.new
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 build(parent, configure: true)
84
- @parent = parent
85
- tk_widget # creates the widget if possible and not yet created
86
- @font = TkWrapper::Util::Tk::Font.new(tk_widget)
87
- self.configure if configure
88
- manager.execute_modifications(self)
89
- @childs.each { |child| child.build(self) }
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
- def configure
98
- @config.merge_global_configurations(manager, self)
99
- @config.configure_tk_widget(tk_widget)
100
- @config.configure_tearoff
73
+ protected
74
+
75
+ def build_childs
76
+ @childs.each { |child| child.build(self, manager: @manager) }
101
77
  end
102
78
 
103
- def modify(matchers, &callback)
104
- items = find_all(matchers)
79
+ def modify_configuration(config) end
105
80
 
106
- callback.call(items)
107
- end
81
+ def create_childs() end
108
82
 
109
- def modify_each(matchers, &callback)
110
- items = find_all(matchers)
83
+ def before_build(**args) end
111
84
 
112
- return unless items
85
+ def after_build() end
113
86
 
114
- with_match = items[0].is_a?(Array)
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
- items.each do |item|
117
- with_match ? callback.call(item[0], item[1]) : callback.call(item)
118
- end
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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tkextlib/tile'
4
+
5
+ class TkWrapper::Widgets::Button < TkWrapper::Widgets::Base::Widget
6
+ def tk_class
7
+ Tk::Tile::Button
8
+ end
9
+ end
data/lib/widgets/entry.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tkextlib/tile'
4
+
3
5
  class TkWrapper::Widgets::Entry < TkWrapper::Widgets::Base::Widget
4
6
  def tk_class
5
- TkWidgets::Entry
7
+ Tk::Tile::Entry
6
8
  end
7
9
  end
data/lib/widgets/frame.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tkextlib/tile'
4
+
3
5
  class TkWrapper::Widgets::Frame < TkWrapper::Widgets::Base::Widget
4
6
  def tk_class
5
- TkWidgets::Frame
7
+ Tk::Tile::Frame
6
8
  end
7
9
  end
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
- TkWidgets::Frame
12
+ Tk::Tile::Frame
11
13
  end
12
14
 
13
- def initialize(config: {}, childs: [], id: nil)
14
- super(config: config, childs: childs, id: id)
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
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tkextlib/tile'
4
+
3
5
  class TkWrapper::Widgets::Label < TkWrapper::Widgets::Base::Widget
4
6
  def tk_class
5
- TkWidgets::Label
7
+ Tk::Tile::Label
6
8
  end
7
9
  end
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
- TkWidgets::TkMenu
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
- TkWidgets::TkMenu
17
+ TkMenu
16
18
  end
17
19
 
18
- def build(parent)
19
- super(parent, configure: false)
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
- TkWidgets::TkRoot
12
+ TkRoot
11
13
  end
12
14
  end
data/lib/widgets/text.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'tk'
4
+
3
5
  class TkWrapper::Widgets::Text < TkWrapper::Widgets::Base::Widget
4
6
  def tk_class
5
- TkWidgets::TkText
7
+ TkText
6
8
  end
7
9
  end
@@ -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.3.0
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-16 00:00:00.000000000 Z
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