tk_component 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2682373d27bd4a239726b01072c4ff1d16276cb0985df00981f976d439f3caac
4
- data.tar.gz: '081498a5e3d097ea8b4920bbe12e94a111ef0fd3d572bc9c64f22857a36cc544'
3
+ metadata.gz: ab47775b9e804ad9eed734826438dac14daff031dd710ed2ecda752fb258b090
4
+ data.tar.gz: 0a70c15c78074b6c1c7a3685863bdb1e76ad334c7be0687494015595717a00de
5
5
  SHA512:
6
- metadata.gz: 8d2c3b454eba444f57c06a047973d8b51082f71d91210640cdb7519510d86a963190c9ede99f464a2af0a382963b67e248fb6fcca69bd35352d0c5ed602d7cd6
7
- data.tar.gz: 6840a3c45ad39d4270ec5b9c1ee4510c8384c658bbb9b66c591f42141225ff4c823adcd0ee35d4bd37b6caac9fa5826b5832c016cb62de6d4e7abdfec43ea6da
6
+ metadata.gz: 1486fb9b4a7e12e71635ce7d0e2b83dfff83e9db85ce0e57ca41f93fa9e7d7cb99755e1c672d55dfbba6b42bf657358b801f81389bf9b0ded6422b124fffc96c
7
+ data.tar.gz: 644ed176397d24a3e513df17e50ad9c3757d9263a8f00feea0041beabb580e19b2ff6bccd93c8c673e333442b60d0f93b28dfd02a0734ef1cb740738acb90b52
data/.gitignore CHANGED
@@ -9,3 +9,6 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ # Gem projects shouldn't commit its Gemfile.lock
14
+ Gemfile.lock
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # TkComponent
2
2
 
3
- TkComponent allows you to create desktop UIs using a component structure taking advantadge of TK, the UI toolkit created for TCL and used by Python in TkInter
3
+ TkComponent allows you to create desktop UIs in Ruby, using a component
4
+ structure taking advantadge of TK, the UI toolkit created for TCL and
5
+ used by Python in TkInter.
4
6
 
5
7
  Still very much a work in progress.
6
8
 
@@ -24,17 +24,15 @@ class DataSource
24
24
  end
25
25
 
26
26
  class DemoRoot < TkComponent::Base
27
- def generate(parent_component, options = {})
28
- parse_component(parent_component, options) do |p|
29
- p.vframe(sticky: 'wens', x_flex: 1, y_flex: 1) do |f|
30
- f.label(text: "Directory of #{DataSource.shared.title_for_path(nil, [])}")
31
- f.insert_component(TkComponent::BrowserComponent, self,
32
- data_source: DataSource.shared,
33
- paned: true,
34
- sticky: 'nsew', x_flex: 1, y_flex: 1) do |bc|
35
- bc.on_event'PathChanged', ->(e) do
36
- puts "PathChanged: " + e.data_object.selected_path.to_s
37
- end
27
+ def render(p, parent_component)
28
+ p.vframe(sticky: 'wens', x_flex: 1, y_flex: 1) do |f|
29
+ f.label(text: "Directory of #{DataSource.shared.title_for_path(nil, [])}")
30
+ f.insert_component(TkComponent::BrowserComponent, self,
31
+ data_source: DataSource.shared,
32
+ paned: true,
33
+ sticky: 'nsew', x_flex: 1, y_flex: 1) do |bc|
34
+ bc.on_event'PathChanged', ->(e) do
35
+ puts "PathChanged: " + e.data_object.selected_path.to_s
38
36
  end
39
37
  end
40
38
  end
@@ -40,20 +40,18 @@ class DataSource
40
40
  end
41
41
 
42
42
  class DemoRoot < TkComponent::Base
43
- def generate(parent_component, options = {})
44
- parse_component(parent_component, options) do |p|
45
- p.vframe(sticky: 'wens', x_flex: 1, y_flex: 1) do |f|
46
- f.label(text: "Directory of #{ENV['HOME']}")
47
- f.insert_component(TkComponent::TableViewComponent, self,
48
- data_source: DataSource.shared,
49
- columns: [
50
- { key: :name, text: 'Name' },
51
- { key: :size, text: 'Size' }
52
- ],
53
- nested: true,
54
- lazy: true,
55
- sticky: 'nsew', x_flex: 1, y_flex: 1)
56
- end
43
+ def render(p, parent_component)
44
+ p.vframe(sticky: 'wens', x_flex: 1, y_flex: 1) do |f|
45
+ f.label(text: "Directory of #{ENV['HOME']}")
46
+ f.insert_component(TkComponent::TableViewComponent, self,
47
+ data_source: DataSource.shared,
48
+ columns: [
49
+ { key: :name, text: 'Name' },
50
+ { key: :size, text: 'Size' }
51
+ ],
52
+ nested: true,
53
+ lazy: true,
54
+ sticky: 'nsew', x_flex: 1, y_flex: 1)
57
55
  end
58
56
  end
59
57
  end
@@ -5,10 +5,14 @@ require "tk_component"
5
5
  require "pry"
6
6
 
7
7
  class ColorBlock < TkComponent::Base
8
- def generate(parent_component, options = {})
9
- parse_component(parent_component, options) do |p|
10
- p.canvas(background: options[:color], sticky: 'wens', x_flex: 1, y_flex: 1)
11
- end
8
+ attr_accessor :color
9
+ def initialize(options = {})
10
+ super
11
+ @color = options[:color] || 'white'
12
+ end
13
+
14
+ def render(p, parent_component)
15
+ p.canvas(background: color, sticky: 'wens', x_flex: 1, y_flex: 1)
12
16
  end
13
17
  end
14
18
 
@@ -16,19 +20,18 @@ class DemoRoot < TkComponent::Base
16
20
  COLORS = %w|red yellow green brown blue orange|
17
21
  ROWS = 10
18
22
  COLUMNS = 10
19
- def generate(parent_component, options = {})
20
- parse_component(parent_component, options) do |p|
21
- p.frame(sticky: 'wens', x_flex: 1, y_flex: 1) do |f|
22
- f.row(sticky: 'wens', x_flex: 1, y_flex: 1) do |r|
23
- r.button(text: "Refresh", columnspan: COLUMNS, sticky: 'e') do |b|
24
- b.on_click ->(e) { regenerate }
25
- end
23
+
24
+ def render(p, parent_component)
25
+ p.frame(sticky: 'wens', x_flex: 1, y_flex: 1) do |f|
26
+ f.row(sticky: 'wens', x_flex: 1, y_flex: 1) do |r|
27
+ r.button(text: "Refresh", columnspan: COLUMNS, sticky: 'e') do |b|
28
+ b.on_click ->(e) { regenerate }
26
29
  end
27
- ROWS.times do
28
- f.row(sticky: 'wens', x_flex: 1, y_flex: 1) do |r|
29
- COLUMNS.times do
30
- r.insert_component(ColorBlock, self, color: random_color, sticky: 'nsew', x_flex: 1, y_flex: 1)
31
- end
30
+ end
31
+ ROWS.times do
32
+ f.row(sticky: 'wens', x_flex: 1, y_flex: 1) do |r|
33
+ COLUMNS.times do
34
+ r.insert_component(ColorBlock, self, color: random_color, sticky: 'nsew', x_flex: 1, y_flex: 1)
32
35
  end
33
36
  end
34
37
  end
@@ -40,7 +43,7 @@ class DemoRoot < TkComponent::Base
40
43
  end
41
44
  end
42
45
 
43
- @tk_root = TkComponent::Window.new(title: "Demo")
46
+ @tk_root = TkComponent::Window.new(title: "Demo", root: true)
44
47
  @main_component = DemoRoot.new
45
48
  @tk_root.place_root_component(@main_component)
46
49
 
@@ -1,11 +1,6 @@
1
1
  require "tk_component/version"
2
2
  require "active_support/all"
3
-
4
- require_relative 'tk_component/basic_component'
5
- require_relative 'tk_component/base'
6
- require_relative 'tk_component/browser_component'
7
- require_relative 'tk_component/r_browser_component'
8
- require_relative 'tk_component/table_view_component'
9
- require_relative 'tk_component/window'
3
+ require_relative "tk_component/base"
10
4
  require_relative 'tk_component/builder'
11
- require_relative 'tk_component/turtle'
5
+ require_relative "tk_component/components"
6
+ require_relative "tk_component/extras"
@@ -1,113 +1,3 @@
1
- require 'tk'
2
- require 'tkextlib/tile'
3
-
4
- module TkComponent
5
- class Base
6
-
7
- attr_accessor :tk_item
8
- attr_accessor :parent
9
- attr_accessor :parent_node
10
- attr_accessor :children
11
- attr_accessor :node
12
-
13
- include BasicComponent
14
-
15
- def initialize(options = {})
16
- @parent = options[:parent]
17
- @parent_node = options[:parent_node]
18
- @children = []
19
- end
20
-
21
- def parse_component(parent_component, options = {})
22
- raise "You need to provide a block" unless block_given?
23
- @node = Builder::Node.new(:top, options)
24
- yield(@node)
25
- binding.pry if @node.sub_nodes.size != 1
26
- raise "Components need to have a single root node" unless @node.sub_nodes.size == 1
27
- @node.prepare_option_events(self)
28
- @node.prepare_grid
29
- @node = @node.sub_nodes.first # Get rid of the dummy top node
30
- end
31
-
32
- def parse_nodes(parent_node, options = {})
33
- old_sub_nodes = parent_node.sub_nodes.dup
34
- yield(parent_node)
35
- new_sub_nodes = parent_node.sub_nodes - old_sub_nodes
36
- new_sub_nodes.each { |n| n.prepare_option_events(self) }
37
- parent_node.prepare_grid
38
- new_sub_nodes
39
- end
40
-
41
- def build(parent_component)
42
- @node.build(@parent_node, parent_component)
43
- component_did_build
44
- children.each do |c|
45
- c.build(self)
46
- TkGrid.columnconfigure c.parent_node.tk_item.native_item, 0, weight: 1
47
- TkGrid.rowconfigure c.parent_node.tk_item.native_item, 0, weight: 1
48
- TkGrid.columnconfigure c.node.tk_item.native_item, 0, weight: 1
49
- TkGrid.rowconfigure c.node.tk_item.native_item, 0, weight: 1
50
- end
51
- end
52
-
53
- def regenerate
54
- old_node = @node
55
- old_children = @children
56
- @children = []
57
- generate(parent)
58
- rebuild(old_node)
59
- @children.each do |c|
60
- c.generate(self)
61
- c.build(self)
62
- end
63
- end
64
-
65
- def regenerate_from_node(node, parent_node, options = {}, &block)
66
- regenerate_from_index(parent_node, parent_node.sub_nodes.index(node), options, &block)
67
- end
68
-
69
- def regenerate_after_node(node, parent_node, options = {}, &block)
70
- return if parent_node.sub_nodes.index(node).nil?
71
- regenerate_from_index(parent_node, parent_node.sub_nodes.index(node) + 1, options, &block)
72
- end
73
-
74
- def regenerate_from_index(parent_node, index, options = {}, &block)
75
- old_children = @children.dup
76
- to_remove = parent_node.sub_nodes.slice!(index..-1)
77
- to_remove.each do |n|
78
- n.remove
79
- end
80
- new_sub_nodes = parse_nodes(parent_node, options, &block)
81
- new_children = @children - old_children
82
- new_sub_nodes.each do |n|
83
- n.build(parent_node, self)
84
- end
85
- new_children.each do |c|
86
- c.generate(self)
87
- c.build(self)
88
- end
89
- parent_node.apply_grid
90
- parent_node.built
91
- end
92
-
93
- def rebuild(old_node)
94
- build(parent)
95
- end
96
-
97
- def name
98
- self.class.name
99
- end
100
-
101
- def emit(event_name)
102
- TkComponent::Builder::Event.emit(event_name, parent_node.native_item, self.object_id)
103
- end
104
-
105
- def component_did_build
106
- end
107
-
108
- def add_child(child)
109
- binding.pry if children.nil?
110
- children << child
111
- end
112
- end
113
- end
1
+ require_relative 'base/basic_component'
2
+ require_relative 'base/base'
3
+ require_relative 'base/window'
@@ -0,0 +1,123 @@
1
+ require 'tk'
2
+ require 'tkextlib/tile'
3
+
4
+ module TkComponent
5
+ class Base
6
+
7
+ attr_accessor :tk_item
8
+ attr_accessor :parent
9
+ attr_accessor :parent_node
10
+ attr_accessor :children
11
+ attr_accessor :node
12
+
13
+ include BasicComponent
14
+
15
+ def initialize(options = {})
16
+ @parent = options[:parent]
17
+ @parent_node = options[:parent_node]
18
+ @children = []
19
+ end
20
+
21
+ def render(p, parent_component)
22
+ raise "Component #{self.class.to_s} needs to have a 'render' method"
23
+ end
24
+
25
+ def generate(parent_component)
26
+ parse_component(parent_component) do |p|
27
+ render(p, parent_component)
28
+ end
29
+ end
30
+
31
+ def parse_component(parent_component)
32
+ raise "You need to provide a block" unless block_given?
33
+ @node = Builder::Node.new(:top)
34
+ yield(@node)
35
+ binding.pry if @node.sub_nodes.size != 1
36
+ raise "Components need to have a single root node" unless @node.sub_nodes.size == 1
37
+ @node.prepare_option_events(self)
38
+ @node.prepare_grid
39
+ @node = @node.sub_nodes.first # Get rid of the dummy top node
40
+ end
41
+
42
+ def parse_nodes(parent_node, options = {})
43
+ old_sub_nodes = parent_node.sub_nodes.dup
44
+ yield(parent_node)
45
+ new_sub_nodes = parent_node.sub_nodes - old_sub_nodes
46
+ new_sub_nodes.each { |n| n.prepare_option_events(self) }
47
+ parent_node.prepare_grid
48
+ new_sub_nodes
49
+ end
50
+
51
+ def build(parent_component)
52
+ @node.build(@parent_node, parent_component)
53
+ component_did_build
54
+ children.each do |c|
55
+ c.build(self)
56
+ TkGrid.columnconfigure c.parent_node.tk_item.native_item, 0, weight: 1
57
+ TkGrid.rowconfigure c.parent_node.tk_item.native_item, 0, weight: 1
58
+ TkGrid.columnconfigure c.node.tk_item.native_item, 0, weight: 1
59
+ TkGrid.rowconfigure c.node.tk_item.native_item, 0, weight: 1
60
+ end
61
+ end
62
+
63
+ def regenerate
64
+ old_node = @node
65
+ old_children = @children
66
+ @children = []
67
+ generate(parent)
68
+ rebuild(old_node)
69
+ @children.each do |c|
70
+ c.generate(self)
71
+ c.build(self)
72
+ end
73
+ end
74
+
75
+ def regenerate_from_node(node, parent_node, &block)
76
+ regenerate_from_index(parent_node, parent_node.sub_nodes.index(node), &block)
77
+ end
78
+
79
+ def regenerate_after_node(node, parent_node, &block)
80
+ return if parent_node.sub_nodes.index(node).nil?
81
+ regenerate_from_index(parent_node, parent_node.sub_nodes.index(node) + 1, &block)
82
+ end
83
+
84
+ def regenerate_from_index(parent_node, index, &block)
85
+ old_children = @children.dup
86
+ to_remove = parent_node.sub_nodes.slice!(index..-1)
87
+ to_remove.each do |n|
88
+ n.remove
89
+ end
90
+ new_sub_nodes = parse_nodes(parent_node, &block)
91
+ new_children = @children - old_children
92
+ new_sub_nodes.each do |n|
93
+ n.build(parent_node, self)
94
+ end
95
+ new_children.each do |c|
96
+ c.generate(self)
97
+ c.build(self)
98
+ end
99
+ parent_node.apply_grid
100
+ parent_node.built
101
+ end
102
+
103
+ def rebuild(old_node)
104
+ build(parent)
105
+ end
106
+
107
+ def name
108
+ self.class.name
109
+ end
110
+
111
+ def emit(event_name)
112
+ TkComponent::Builder::Event.emit(event_name, parent_node.native_item, self.object_id)
113
+ end
114
+
115
+ def component_did_build
116
+ end
117
+
118
+ def add_child(child)
119
+ binding.pry if children.nil?
120
+ children << child
121
+ end
122
+ end
123
+ end
@@ -50,7 +50,7 @@ module TkComponent
50
50
  layout_options = options.slice(*LAYOUT_OPTIONS)
51
51
  c_node = node_from_command(:frame, layout_options, &block)
52
52
  comp = component_class.new(options.merge(parent: parent_component, parent_node: c_node))
53
- comp.generate(parent_component, options)
53
+ comp.generate(parent_component)
54
54
  parent_component.add_child(comp)
55
55
  comp
56
56
  end
@@ -0,0 +1,5 @@
1
+ require_relative 'components/browser_component'
2
+ require_relative 'components/table_view_component'
3
+
4
+ # Soon will be deprecated
5
+ require_relative 'components/r_browser_component'
@@ -0,0 +1,68 @@
1
+ module TkComponent
2
+ class BrowserColumnComponent < TkComponent::Base
3
+
4
+ attr_accessor :browser
5
+ attr_accessor :column_index
6
+
7
+ def initialize(options = {})
8
+ super
9
+ @browser = options[:browser]
10
+ @column_index = options[:column_index] || 0
11
+ end
12
+
13
+ def render(p, parent_component)
14
+ if @column_index <= @browser.selected_path.size
15
+ current_item = @browser.selected_path[@column_index]
16
+ path_so_far = @browser.selected_path.slice(0, @column_index)
17
+ items = @browser.data_source.items_for_path(path_so_far)
18
+ items ||= []
19
+ else
20
+ items = []
21
+ current_item = nil
22
+ end
23
+ command = @browser.paned ? :hpaned : :hframe
24
+ p.send(command, sticky: 'nsew', x_flex: 1, y_flex: 1) do |f|
25
+ @tree = f.tree(sticky: 'nsew', x_flex: 1, y_flex: 1,
26
+ on_select: :select_item,
27
+ scrollers: 'y', heading: @browser.data_source.title_for_path(path_so_far, items)) do |t|
28
+ items.each do |item|
29
+ t.tree_node(at: 'end',
30
+ text: item,
31
+ selected: item == current_item)
32
+ end
33
+ end
34
+ if (@browser.max_columns.blank? || @browser.max_columns > @column_index + 1) &&
35
+ (@column_index < @browser.selected_path.size || items.present?)
36
+ f.hframe(sticky: 'nsew', x_flex: 1, y_flex: 1) do |hf|
37
+ @next_column = hf.insert_component(TkComponent::BrowserColumnComponent, self,
38
+ browser: @browser,
39
+ column_index: @column_index + 1,
40
+ sticky: 'nsew', x_flex: 1, y_flex: 1) do |bc|
41
+ bc.on_event 'ItemSelected', ->(e) do
42
+ emit('ItemSelected')
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def component_did_build
51
+ show_current_selection
52
+ end
53
+
54
+ def show_current_selection
55
+ @tree.tk_item.scroll_to_selection
56
+ end
57
+
58
+ def select_item(e)
59
+ item = e.sender.native_item.selection&.first.text.to_s
60
+ return if @browser.selected_path[@column_index] == item
61
+ @browser.selected_path[@column_index] = item
62
+ @browser.selected_path.slice!(@column_index + 1..-1) if @column_index < @browser.selected_path.size - 1
63
+ puts "New selected path: #{@browser.selected_path}"
64
+ @next_column&.regenerate
65
+ emit('ItemSelected')
66
+ end
67
+ end
68
+ end
@@ -13,15 +13,13 @@ module TkComponent
13
13
  @trees = []
14
14
  end
15
15
 
16
- def generate(parent_component, options = {})
17
- parse_component(parent_component, options) do |p|
18
- partial_path = []
19
- @trees = []
20
- p.vframe(sticky: 'nsew', x_flex: 1, y_flex: 1) do |vf|
21
- command = @paned ? :hpaned : :hframe
22
- @trees_container = vf.send(command, sticky: 'nsew', x_flex: 1, y_flex: 1) do |f|
23
- generate_from_level(f, 0)
24
- end
16
+ def render(p, parent_component)
17
+ partial_path = []
18
+ @trees = []
19
+ p.vframe(sticky: 'nsew', x_flex: 1, y_flex: 1) do |vf|
20
+ command = @paned ? :hpaned : :hframe
21
+ @trees_container = vf.send(command, sticky: 'nsew', x_flex: 1, y_flex: 1) do |f|
22
+ generate_from_level(f, 0)
25
23
  end
26
24
  end
27
25
  end
@@ -16,16 +16,14 @@ module TkComponent
16
16
  @max_columns = options[:max_columns]
17
17
  end
18
18
 
19
- def generate(parent_component, options = {})
20
- parse_component(parent_component, options) do |p|
21
- p.insert_component(TkComponent::BrowserColumnComponent, self,
22
- browser: self,
23
- column_index: 0,
24
- sticky: 'nsew', x_flex: 1, y_flex: 1) do |bc|
25
- bc.on_event 'ItemSelected', ->(e) do
26
- puts "ItemSelected"
27
- emit('PathChanged')
28
- end
19
+ def render(p, parent_component)
20
+ p.insert_component(TkComponent::BrowserColumnComponent, self,
21
+ browser: self,
22
+ column_index: 0,
23
+ sticky: 'nsew', x_flex: 1, y_flex: 1) do |bc|
24
+ bc.on_event 'ItemSelected', ->(e) do
25
+ puts "ItemSelected"
26
+ emit('PathChanged')
29
27
  end
30
28
  end
31
29
  end
@@ -17,15 +17,13 @@ module TkComponent
17
17
  @to_load = {}
18
18
  end
19
19
 
20
- def generate(parent_component, options = {})
20
+ def render(p, parent_component)
21
21
  @to_load = {}
22
- parse_component(parent_component, options) do |p|
23
- @tree = p.tree(sticky: 'nsew', x_flex: 1, y_flex: 1, scrollers: @scrollers,
24
- column_defs: columns,
25
- on_item_open: :item_open,
26
- on_select: :item_selected
27
- )
28
- end
22
+ @tree = p.tree(sticky: 'nsew', x_flex: 1, y_flex: 1, scrollers: @scrollers,
23
+ column_defs: columns,
24
+ on_item_open: :item_open,
25
+ on_select: :item_selected
26
+ )
29
27
  end
30
28
 
31
29
  def component_did_build
@@ -0,0 +1 @@
1
+ require_relative 'extras/turtle'
@@ -1,3 +1,3 @@
1
1
  module TkComponent
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tk_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Egea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-28 00:00:00.000000000 Z
11
+ date: 2021-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tk
@@ -98,7 +98,6 @@ files:
98
98
  - ".travis.yml"
99
99
  - CODE_OF_CONDUCT.md
100
100
  - Gemfile
101
- - Gemfile.lock
102
101
  - LICENSE.txt
103
102
  - README.md
104
103
  - Rakefile
@@ -109,21 +108,24 @@ files:
109
108
  - bin/tiles_demo.rb
110
109
  - lib/tk_component.rb
111
110
  - lib/tk_component/base.rb
112
- - lib/tk_component/basic_component.rb
113
- - lib/tk_component/browser_column_component.rb
114
- - lib/tk_component/browser_component.rb
111
+ - lib/tk_component/base/base.rb
112
+ - lib/tk_component/base/basic_component.rb
113
+ - lib/tk_component/base/menu.rb
114
+ - lib/tk_component/base/window.rb
115
115
  - lib/tk_component/builder.rb
116
116
  - lib/tk_component/builder/event.rb
117
117
  - lib/tk_component/builder/event_handler.rb
118
118
  - lib/tk_component/builder/grid_map.rb
119
119
  - lib/tk_component/builder/node.rb
120
120
  - lib/tk_component/builder/tk_item.rb
121
- - lib/tk_component/menu.rb
122
- - lib/tk_component/r_browser_component.rb
123
- - lib/tk_component/table_view_component.rb
124
- - lib/tk_component/turtle.rb
121
+ - lib/tk_component/components.rb
122
+ - lib/tk_component/components/browser_column_component.rb
123
+ - lib/tk_component/components/browser_component.rb
124
+ - lib/tk_component/components/r_browser_component.rb
125
+ - lib/tk_component/components/table_view_component.rb
126
+ - lib/tk_component/extras.rb
127
+ - lib/tk_component/extras/turtle.rb
125
128
  - lib/tk_component/version.rb
126
- - lib/tk_component/window.rb
127
129
  - tk_component.gemspec
128
130
  homepage: https://github.com/josepegea/tk_component
129
131
  licenses:
@@ -1,63 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- tk_component (0.1.2)
5
- activesupport (~> 6.0.3)
6
- tk (~> 0.3.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activesupport (6.0.3.4)
12
- concurrent-ruby (~> 1.0, >= 1.0.2)
13
- i18n (>= 0.7, < 2)
14
- minitest (~> 5.1)
15
- tzinfo (~> 1.1)
16
- zeitwerk (~> 2.2, >= 2.2.2)
17
- byebug (11.1.3)
18
- coderay (1.1.3)
19
- concurrent-ruby (1.1.8)
20
- diff-lcs (1.4.4)
21
- i18n (1.8.7)
22
- concurrent-ruby (~> 1.0)
23
- method_source (1.0.0)
24
- minitest (5.14.3)
25
- pry (0.13.1)
26
- coderay (~> 1.1)
27
- method_source (~> 1.0)
28
- pry-byebug (3.9.0)
29
- byebug (~> 11.0)
30
- pry (~> 0.13.0)
31
- rake (10.5.0)
32
- rspec (3.10.0)
33
- rspec-core (~> 3.10.0)
34
- rspec-expectations (~> 3.10.0)
35
- rspec-mocks (~> 3.10.0)
36
- rspec-core (3.10.0)
37
- rspec-support (~> 3.10.0)
38
- rspec-expectations (3.10.0)
39
- diff-lcs (>= 1.2.0, < 2.0)
40
- rspec-support (~> 3.10.0)
41
- rspec-mocks (3.10.0)
42
- diff-lcs (>= 1.2.0, < 2.0)
43
- rspec-support (~> 3.10.0)
44
- rspec-support (3.10.0)
45
- thread_safe (0.3.6)
46
- tk (0.3.0)
47
- tzinfo (1.2.9)
48
- thread_safe (~> 0.1)
49
- zeitwerk (2.4.2)
50
-
51
- PLATFORMS
52
- ruby
53
-
54
- DEPENDENCIES
55
- bundler (~> 1.16)
56
- pry
57
- pry-byebug
58
- rake (~> 10.0)
59
- rspec (~> 3.0)
60
- tk_component!
61
-
62
- BUNDLED WITH
63
- 1.16.6
@@ -1,70 +0,0 @@
1
- module TkComponent
2
- class BrowserColumnComponent < TkComponent::Base
3
-
4
- attr_accessor :browser
5
- attr_accessor :column_index
6
-
7
- def initialize(options = {})
8
- super
9
- @browser = options[:browser]
10
- @column_index = options[:column_index] || 0
11
- end
12
-
13
- def generate(parent_component, options = {})
14
- parse_component(parent_component, options) do |p|
15
- if @column_index <= @browser.selected_path.size
16
- current_item = @browser.selected_path[@column_index]
17
- path_so_far = @browser.selected_path.slice(0, @column_index)
18
- items = @browser.data_source.items_for_path(path_so_far)
19
- items ||= []
20
- else
21
- items = []
22
- current_item = nil
23
- end
24
- command = @browser.paned ? :hpaned : :hframe
25
- p.send(command, sticky: 'nsew', x_flex: 1, y_flex: 1) do |f|
26
- @tree = f.tree(sticky: 'nsew', x_flex: 1, y_flex: 1,
27
- on_select: :select_item,
28
- scrollers: 'y', heading: @browser.data_source.title_for_path(path_so_far, items)) do |t|
29
- items.each do |item|
30
- t.tree_node(at: 'end',
31
- text: item,
32
- selected: item == current_item)
33
- end
34
- end
35
- if (@browser.max_columns.blank? || @browser.max_columns > @column_index + 1) &&
36
- (@column_index < @browser.selected_path.size || items.present?)
37
- f.hframe(sticky: 'nsew', x_flex: 1, y_flex: 1) do |hf|
38
- @next_column = hf.insert_component(TkComponent::BrowserColumnComponent, self,
39
- browser: @browser,
40
- column_index: @column_index + 1,
41
- sticky: 'nsew', x_flex: 1, y_flex: 1) do |bc|
42
- bc.on_event 'ItemSelected', ->(e) do
43
- emit('ItemSelected')
44
- end
45
- end
46
- end
47
- end
48
- end
49
- end
50
- end
51
-
52
- def component_did_build
53
- show_current_selection
54
- end
55
-
56
- def show_current_selection
57
- @tree.tk_item.scroll_to_selection
58
- end
59
-
60
- def select_item(e)
61
- item = e.sender.native_item.selection&.first.text.to_s
62
- return if @browser.selected_path[@column_index] == item
63
- @browser.selected_path[@column_index] = item
64
- @browser.selected_path.slice!(@column_index + 1..-1) if @column_index < @browser.selected_path.size - 1
65
- puts "New selected path: #{@browser.selected_path}"
66
- @next_column&.regenerate
67
- emit('ItemSelected')
68
- end
69
- end
70
- end