class TkInspect::Console::RootComponent

Attributes

console[RW]

Public Instance Methods

clear_output(e) click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 85
def clear_output(e)
  @output.tk_item.value = ''
end
focus_on_code() click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 34
def focus_on_code
  @input.tk_item.focus
end
inspect(e) click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 89
def inspect(e)
  console.open_inspector
end
inspect_selected(e) click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 55
def inspect_selected(e)
  code = @input.tk_item.selected_text
  code = @input.tk_item.current_line if code.blank?
  return unless code.present?

  res = console.open_inspector(code)
end
open_class_browser(e) click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 93
def open_class_browser(e)
  console.open_class_browser
end
render(p, parent_component) click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 6
def render(p, parent_component)
  p.vframe(sticky: 'nsew', x_flex: 1, y_flex: 1) do |r|
    r.hframe(sticky: 'new', padding: '8', x_flex: 0) do |hf|
      hf.label(text: "Write Ruby code here", sticky: 'w')
      hf.hframe(sticky: 'ne', x_flex: 1) do |buttons|
        buttons.button(text: "Run selected", default: "active", on_click: :run_selected)
        buttons.button(text: "Return", on_click: :return_from_modal) if console.modal
      end
    end
    r.vpaned(sticky: 'nswe', x_flex: 1, y_flex: 1) do |vp|
      @input = vp.text(sticky: 'nswe', scrollers: 'y',
                       highlightthickness: 0,
                       x_flex: 1, y_flex: 1)
      vp.vframe(padding: "0 0 0 0", sticky: 'nswe', x_flex: 1, y_flex: 1) do |vf|
        vf.hframe(sticky: 'new', padding: '8', x_flex: 0) do |hf|
          hf.label(text: "Output", padding: '8', sticky: 'w')
          hf.hframe(sticky: 'ne', x_flex: 1) do |buttons|
            buttons.button(text: "Clear", on_click: :clear_output)
          end
        end
        @output = vf.text(sticky: 'nswe', scrollers: 'y',
                          background: 'systemSheetBackgroundOpaque', highlightthickness: 0,
                          x_flex: 1, y_flex: 1)
      end
    end
  end
end
return_from_modal(e) click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 97
def return_from_modal(e)
  @running_modal_loop = false
end
run_modal_loop() click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 38
def run_modal_loop
  @running_modal_loop = true
  while @running_modal_loop
    Tk.update
    sleep(0.019)
  end
end
run_selected(e) click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 46
def run_selected(e)
  code = @input.tk_item.selected_text
  code = @input.tk_item.current_line if code.blank?
  return unless code.present?

  res = console.execute(code)
  show_output(res)
end
show_output(res) click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 63
def show_output(res)
  @output.tk_item.append_text(res.to_s + "\n");
end
zoom_by(factor, item) click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 77
def zoom_by(factor, item)
  font = item.native_item.font
  new_font = TkFont.new(family: font.family, weight: font.weight, size: (font.size * factor).ceil)
  geom = console.tk_root.tk_item.native_item['geometry']
  item.native_item.font(new_font)
  console.tk_root.tk_item.native_item['geometry'] = geom
end
zoom_in(e) click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 67
def zoom_in(e)
  zoom_by(1.1, @input)
  zoom_by(1.1, @output)
end
zoom_out(e) click to toggle source
# File lib/tk_inspect/console/root_component.rb, line 72
def zoom_out(e)
  zoom_by(0.9091, @input)
  zoom_by(0.9091, @output)
end