tk_component 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -0
- data/Gemfile.lock +16 -5
- data/bin/browser_demo.rb +49 -0
- data/bin/table_view_demo.rb +66 -0
- data/bin/tiles_demo.rb +48 -0
- data/lib/tk_component.rb +5 -0
- data/lib/tk_component/base.rb +49 -3
- data/lib/tk_component/basic_component.rb +8 -0
- data/lib/tk_component/browser_column_component.rb +70 -0
- data/lib/tk_component/browser_component.rb +66 -0
- data/lib/tk_component/builder/grid_map.rb +4 -4
- data/lib/tk_component/builder/node.rb +35 -11
- data/lib/tk_component/builder/tk_item.rb +354 -18
- data/lib/tk_component/menu.rb +4 -0
- data/lib/tk_component/r_browser_component.rb +33 -0
- data/lib/tk_component/table_view_component.rb +90 -0
- data/lib/tk_component/turtle.rb +100 -0
- data/lib/tk_component/version.rb +1 -1
- data/lib/tk_component/window.rb +4 -4
- metadata +16 -6
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'browser_column_component'
|
2
|
+
|
3
|
+
module TkComponent
|
4
|
+
class RBrowserComponent < TkComponent::Base
|
5
|
+
|
6
|
+
attr_accessor :data_source
|
7
|
+
attr_accessor :selected_path
|
8
|
+
attr_accessor :paned
|
9
|
+
attr_accessor :max_columns
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
super
|
13
|
+
@data_source = options[:data_source]
|
14
|
+
@selected_path = options[:selected_path] || []
|
15
|
+
@paned = !!options[:paned]
|
16
|
+
@max_columns = options[:max_columns]
|
17
|
+
end
|
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
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module TkComponent
|
2
|
+
class TableViewComponent < TkComponent::Base
|
3
|
+
|
4
|
+
attr_accessor :data_source
|
5
|
+
attr_accessor :columns
|
6
|
+
attr_accessor :nested
|
7
|
+
attr_accessor :lazy
|
8
|
+
attr_accessor :scrollers
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
super
|
12
|
+
@data_source = options[:data_source]
|
13
|
+
@columns = options[:columns]
|
14
|
+
@nested = !!options[:nested]
|
15
|
+
@lazy = !!options[:lazy]
|
16
|
+
@scrollers = options[:scrollers] || 'y'
|
17
|
+
@to_load = {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate(parent_component, options = {})
|
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
|
29
|
+
end
|
30
|
+
|
31
|
+
def component_did_build
|
32
|
+
items = data_source.items_for_path(nil)
|
33
|
+
items.each do |item|
|
34
|
+
add_item(@tree, item)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_item(tree, item, parent_items = [], parent_item = nil)
|
39
|
+
tree_item = tree.native_item.insert(parent_item || '', 'end', item_to_options(item))
|
40
|
+
return unless nested && ((sub_path = parent_items + [ item ]) && data_source.has_sub_items?(sub_path))
|
41
|
+
if lazy
|
42
|
+
dummy_item = tree.native_item.insert(tree_item, 'end')
|
43
|
+
@to_load[tree_item] = sub_path
|
44
|
+
else
|
45
|
+
sub_items = data_source.items_for_path(sub_path)
|
46
|
+
sub_items.each do |sub_item|
|
47
|
+
add_item(tree, sub_item, sub_path, tree_item)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def selected_item
|
53
|
+
(tree_item = @tree.native_item.focus_item) && tree_item_to_item(tree_item)
|
54
|
+
end
|
55
|
+
|
56
|
+
def item_to_options(item)
|
57
|
+
{ text: item[text_key], values: item.slice(*values_keys).values }
|
58
|
+
end
|
59
|
+
|
60
|
+
def tree_item_to_item(tree_item)
|
61
|
+
columns.map.with_index do |c, i|
|
62
|
+
[c[:key],
|
63
|
+
i == 0 ? tree_item.text : tree_item.get(c[:key])]
|
64
|
+
end.to_h
|
65
|
+
end
|
66
|
+
|
67
|
+
def item_open(e)
|
68
|
+
open_item = e.sender.native_item.focus_item
|
69
|
+
return unless open_item.present?
|
70
|
+
path = @to_load.delete(open_item)
|
71
|
+
return unless path.present?
|
72
|
+
@tree.native_item.delete(open_item.children)
|
73
|
+
sub_items = data_source.items_for_path(path)
|
74
|
+
sub_items.each do |sub_item|
|
75
|
+
add_item(@tree, sub_item, path, open_item)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def item_selected(e)
|
80
|
+
end
|
81
|
+
|
82
|
+
def text_key
|
83
|
+
@text_key ||= columns.first[:key]
|
84
|
+
end
|
85
|
+
|
86
|
+
def values_keys
|
87
|
+
@values_keys ||= columns[1..-1].map { |c| c[:key] }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module TkComponent
|
2
|
+
class Turtle
|
3
|
+
FULL_CIRCLE = 2 * Math::PI
|
4
|
+
|
5
|
+
attr_accessor :canvas
|
6
|
+
attr_accessor :current_x
|
7
|
+
attr_accessor :current_y
|
8
|
+
attr_accessor :color
|
9
|
+
attr_accessor :width
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
@canvas = options[:canvas]
|
13
|
+
@current_x = 0
|
14
|
+
@current_y = 0
|
15
|
+
@angle_unit = :radians
|
16
|
+
@current_angle = FULL_CIRCLE / 4.0
|
17
|
+
@turtle_down = false
|
18
|
+
@color = options[:color] || 'black'
|
19
|
+
@width = options[:width] || 1
|
20
|
+
end
|
21
|
+
|
22
|
+
def clear
|
23
|
+
@canvas.delete('all')
|
24
|
+
end
|
25
|
+
|
26
|
+
def down
|
27
|
+
@turtle_down = true
|
28
|
+
end
|
29
|
+
|
30
|
+
def up
|
31
|
+
@turtle_down = false
|
32
|
+
end
|
33
|
+
|
34
|
+
def down?
|
35
|
+
@turtle_down
|
36
|
+
end
|
37
|
+
|
38
|
+
def up?
|
39
|
+
!down?
|
40
|
+
end
|
41
|
+
|
42
|
+
def current_point
|
43
|
+
[@current_x, @current_y]
|
44
|
+
end
|
45
|
+
|
46
|
+
def move_to_center
|
47
|
+
@current_x = @canvas.winfo_width / 2
|
48
|
+
@current_y = @canvas.winfo_height / 2
|
49
|
+
end
|
50
|
+
|
51
|
+
def forward(length)
|
52
|
+
new_x = @current_x + length * Math.cos(@current_angle)
|
53
|
+
new_y = @current_y - length * Math.sin(@current_angle)
|
54
|
+
if down?
|
55
|
+
TkcLine.new(@canvas, [current_point, [new_x, new_y]], fill: @color, width: @width)
|
56
|
+
end
|
57
|
+
@current_x = new_x
|
58
|
+
@current_y = new_y
|
59
|
+
end
|
60
|
+
|
61
|
+
def turn_left(angle)
|
62
|
+
@current_angle = (@current_angle + user_angle(angle)) % FULL_CIRCLE
|
63
|
+
end
|
64
|
+
|
65
|
+
def turn_right(angle)
|
66
|
+
@current_angle = (@current_angle - user_angle(angle)) % FULL_CIRCLE
|
67
|
+
end
|
68
|
+
|
69
|
+
def point_north
|
70
|
+
@current_angle = FULL_CIRCLE / 4.0
|
71
|
+
end
|
72
|
+
|
73
|
+
def point_east
|
74
|
+
@current_angle = 0.0
|
75
|
+
end
|
76
|
+
|
77
|
+
def point_south
|
78
|
+
@current_angle = FULL_CIRCLE * 3.0 / 4.0
|
79
|
+
end
|
80
|
+
|
81
|
+
def point_west
|
82
|
+
@current_angle = FULL_CIRCLE / 2.0
|
83
|
+
end
|
84
|
+
|
85
|
+
def degrees
|
86
|
+
@angle_unit = :degrees
|
87
|
+
end
|
88
|
+
alias :deg :degrees
|
89
|
+
|
90
|
+
def radians
|
91
|
+
@angle_unit = :radians
|
92
|
+
end
|
93
|
+
alias :rad :radians
|
94
|
+
|
95
|
+
def user_angle(angle)
|
96
|
+
return angle if @angle_unit == :radians
|
97
|
+
(angle % 360.0) * FULL_CIRCLE / 360.0
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/tk_component/version.rb
CHANGED
data/lib/tk_component/window.rb
CHANGED
@@ -13,10 +13,10 @@ module TkComponent
|
|
13
13
|
component.parent = self
|
14
14
|
component.generate(self)
|
15
15
|
component.build(self)
|
16
|
-
|
17
|
-
|
18
|
-
TkGrid.columnconfigure tk_item.native_item, 0, weight:
|
19
|
-
TkGrid.rowconfigure tk_item.native_item, 0, weight:
|
16
|
+
x_flex = options[:x_flex] || 1
|
17
|
+
y_flex = options[:y_flex] || 1
|
18
|
+
TkGrid.columnconfigure tk_item.native_item, 0, weight: x_flex
|
19
|
+
TkGrid.rowconfigure tk_item.native_item, 0, weight: y_flex
|
20
20
|
add_child(component)
|
21
21
|
end
|
22
22
|
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josep Egea
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tk
|
@@ -97,16 +97,26 @@ files:
|
|
97
97
|
- LICENSE.txt
|
98
98
|
- README.md
|
99
99
|
- Rakefile
|
100
|
+
- bin/browser_demo.rb
|
100
101
|
- bin/console
|
101
102
|
- bin/setup
|
103
|
+
- bin/table_view_demo.rb
|
104
|
+
- bin/tiles_demo.rb
|
102
105
|
- lib/tk_component.rb
|
103
106
|
- lib/tk_component/base.rb
|
107
|
+
- lib/tk_component/basic_component.rb
|
108
|
+
- lib/tk_component/browser_column_component.rb
|
109
|
+
- lib/tk_component/browser_component.rb
|
104
110
|
- lib/tk_component/builder.rb
|
105
111
|
- lib/tk_component/builder/event.rb
|
106
112
|
- lib/tk_component/builder/event_handler.rb
|
107
113
|
- lib/tk_component/builder/grid_map.rb
|
108
114
|
- lib/tk_component/builder/node.rb
|
109
115
|
- lib/tk_component/builder/tk_item.rb
|
116
|
+
- lib/tk_component/menu.rb
|
117
|
+
- lib/tk_component/r_browser_component.rb
|
118
|
+
- lib/tk_component/table_view_component.rb
|
119
|
+
- lib/tk_component/turtle.rb
|
110
120
|
- lib/tk_component/version.rb
|
111
121
|
- lib/tk_component/window.rb
|
112
122
|
- tk_component.gemspec
|
@@ -118,7 +128,7 @@ metadata:
|
|
118
128
|
homepage_uri: https://github.com/josepegea/tk_component
|
119
129
|
source_code_uri: https://github.com/josepegea/tk_component
|
120
130
|
changelog_uri: https://github.com/josepegea/tk_component/releases
|
121
|
-
post_install_message:
|
131
|
+
post_install_message:
|
122
132
|
rdoc_options: []
|
123
133
|
require_paths:
|
124
134
|
- lib
|
@@ -133,9 +143,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
143
|
- !ruby/object:Gem::Version
|
134
144
|
version: '0'
|
135
145
|
requirements: []
|
136
|
-
rubyforge_project:
|
146
|
+
rubyforge_project:
|
137
147
|
rubygems_version: 2.7.8
|
138
|
-
signing_key:
|
148
|
+
signing_key:
|
139
149
|
specification_version: 4
|
140
150
|
summary: Use TK from Ruby in a component oriented fashion
|
141
151
|
test_files: []
|