Class: TkComponent::Builder::TkItem
- Inherits:
-
Object
- Object
- TkComponent::Builder::TkItem
show all
- Defined in:
- lib/tk_component/builder/tk_item.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#apply_internal_grid(grid_map) ⇒ Object
-
#apply_option(option, value, to_item = self.native_item) ⇒ Object
-
#apply_options(options, to_item = self.native_item) ⇒ Object
-
#built ⇒ Object
-
#create_native_item(parent_native_item, name, options = {}, grid = {}, event_handlers = []) ⇒ Object
-
#focus ⇒ Object
-
#initialize(parent_item, name, options = {}, grid = {}, event_handlers = []) ⇒ TkItem
constructor
A new instance of TkItem.
-
#native_item_class(parent_native_item, name, options = {}, grid = {}, event_handlers = []) ⇒ Object
-
#remove ⇒ Object
-
#set_event_handler(event_handler) ⇒ Object
-
#set_event_handlers(event_handlers) ⇒ Object
-
#set_grid(grid, to_item = self.native_item) ⇒ Object
Constructor Details
#initialize(parent_item, name, options = {}, grid = {}, event_handlers = []) ⇒ TkItem
Returns a new instance of TkItem.
13
14
15
16
17
18
|
# File 'lib/tk_component/builder/tk_item.rb', line 13
def initialize(parent_item, name, options = {}, grid = {}, event_handlers = [])
@native_item = create_native_item(parent_item.native_item, name, options, grid, event_handlers)
apply_options(options)
set_grid(grid)
set_event_handlers(event_handlers)
end
|
Instance Attribute Details
#native_item ⇒ Object
Returns the value of attribute native_item.
5
6
7
|
# File 'lib/tk_component/builder/tk_item.rb', line 5
def native_item
@native_item
end
|
Class Method Details
.create(parent_item, name, options = {}, grid = {}, event_handlers = []) ⇒ Object
7
8
9
10
11
|
# File 'lib/tk_component/builder/tk_item.rb', line 7
def self.create(parent_item, name, options = {}, grid = {}, event_handlers = [])
item_class = ITEM_CLASSES[name.to_sym]
raise "Don't know how to create #{name}" unless item_class
item_class.new(parent_item, name, options, grid, event_handlers)
end
|
Instance Method Details
#apply_internal_grid(grid_map) ⇒ Object
48
49
50
51
|
# File 'lib/tk_component/builder/tk_item.rb', line 48
def apply_internal_grid(grid_map)
grid_map.column_indexes.each { |c| TkGrid.columnconfigure(self.native_item, c, weight: grid_map.column_weight(c)) }
grid_map.row_indexes.each { |r| TkGrid.rowconfigure(self.native_item, r, weight: grid_map.row_weight(r)) }
end
|
#apply_option(option, value, to_item = self.native_item) ⇒ Object
40
41
42
|
# File 'lib/tk_component/builder/tk_item.rb', line 40
def apply_option(option, value, to_item = self.native_item)
to_item.public_send(option, value)
end
|
#apply_options(options, to_item = self.native_item) ⇒ Object
34
35
36
37
38
|
# File 'lib/tk_component/builder/tk_item.rb', line 34
def apply_options(options, to_item = self.native_item)
options.each do |k,v|
apply_option(k, v, to_item)
end
end
|
#built ⇒ Object
68
69
|
# File 'lib/tk_component/builder/tk_item.rb', line 68
def built
end
|
#create_native_item(parent_native_item, name, options = {}, grid = {}, event_handlers = []) ⇒ Object
20
21
22
|
# File 'lib/tk_component/builder/tk_item.rb', line 20
def create_native_item(parent_native_item, name, options = {}, grid = {}, event_handlers = [])
native_item_class(parent_native_item, name, options, grid, event_handlers).new(parent_native_item)
end
|
#focus ⇒ Object
71
72
73
|
# File 'lib/tk_component/builder/tk_item.rb', line 71
def focus
self.native_item.focus
end
|
#native_item_class(parent_native_item, name, options = {}, grid = {}, event_handlers = []) ⇒ Object
24
25
26
27
28
|
# File 'lib/tk_component/builder/tk_item.rb', line 24
def native_item_class(parent_native_item, name, options = {}, grid = {}, event_handlers = [])
tk_class = TK_CLASSES[name.to_sym]
raise "Don't know how to create #{name}" unless tk_class.present?
return tk_class
end
|
#remove ⇒ Object
30
31
32
|
# File 'lib/tk_component/builder/tk_item.rb', line 30
def remove
@native_item.destroy
end
|
#set_event_handler(event_handler) ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/tk_component/builder/tk_item.rb', line 57
def set_event_handler(event_handler)
case event_handler.name
when :click
Event.bind_command(event_handler.name, self, event_handler.options, event_handler.lambda)
when :change
Event.bind_variable(event_handler.name, self, event_handler.options, event_handler.lambda)
else
Event.bind_event(event_handler.name, self, event_handler.options, event_handler.lambda)
end
end
|
#set_event_handlers(event_handlers) ⇒ Object
53
54
55
|
# File 'lib/tk_component/builder/tk_item.rb', line 53
def set_event_handlers(event_handlers)
event_handlers.each { |eh| set_event_handler(eh) }
end
|
#set_grid(grid, to_item = self.native_item) ⇒ Object
44
45
46
|
# File 'lib/tk_component/builder/tk_item.rb', line 44
def set_grid(grid, to_item = self.native_item)
to_item.grid(grid)
end
|