class TkComponent::Builder::TkItem
Attributes
native_item[RW]
Public Class Methods
create(parent_item, name, options = {}, grid = {}, event_handlers = [])
click to toggle source
# 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
new(parent_item, name, options = {}, grid = {}, event_handlers = [])
click to toggle source
# 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
Public Instance Methods
apply_internal_grid(grid_map)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/tk_component/builder/tk_item.rb, line 68 def built end
create_native_item(parent_native_item, name, options = {}, grid = {}, event_handlers = [])
click to toggle source
# 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()
click to toggle source
# 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 = [])
click to toggle source
# 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()
click to toggle source
# File lib/tk_component/builder/tk_item.rb, line 30 def remove @native_item.destroy end
set_event_handler(event_handler)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/tk_component/builder/tk_item.rb, line 44 def set_grid(grid, to_item = self.native_item) to_item.grid(grid) end