Class: TkInspect::Console::RootComponent
- Defined in:
- lib/tk_inspect/console/root_component.rb
Instance Attribute Summary collapse
-
#console ⇒ Object
Returns the value of attribute console.
Instance Method Summary collapse
- #clear_output(e) ⇒ Object
- #focus_on_code ⇒ Object
- #inspect(e) ⇒ Object
- #inspect_selected(e) ⇒ Object
- #open_class_browser(e) ⇒ Object
- #render(p, parent_component) ⇒ Object
- #return_from_modal(e) ⇒ Object
- #run_modal_loop ⇒ Object
- #run_selected(e) ⇒ Object
- #show_output(res) ⇒ Object
- #zoom_by(factor, item) ⇒ Object
- #zoom_in(e) ⇒ Object
- #zoom_out(e) ⇒ Object
Instance Attribute Details
#console ⇒ Object
Returns the value of attribute console.
4 5 6 |
# File 'lib/tk_inspect/console/root_component.rb', line 4 def console @console end |
Instance Method Details
#clear_output(e) ⇒ Object
85 86 87 |
# File 'lib/tk_inspect/console/root_component.rb', line 85 def clear_output(e) @output.tk_item.value = '' end |
#focus_on_code ⇒ Object
34 35 36 |
# File 'lib/tk_inspect/console/root_component.rb', line 34 def focus_on_code @input.tk_item.focus end |
#inspect(e) ⇒ Object
89 90 91 |
# File 'lib/tk_inspect/console/root_component.rb', line 89 def inspect(e) console.open_inspector end |
#inspect_selected(e) ⇒ Object
55 56 57 58 59 60 61 |
# 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) ⇒ Object
93 94 95 |
# File 'lib/tk_inspect/console/root_component.rb', line 93 def open_class_browser(e) console.open_class_browser end |
#render(p, parent_component) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 || .(text: "Run selected", default: "active", on_click: :run_selected) .(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 || .(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) ⇒ Object
97 98 99 |
# File 'lib/tk_inspect/console/root_component.rb', line 97 def return_from_modal(e) @running_modal_loop = false end |
#run_modal_loop ⇒ Object
38 39 40 41 42 43 44 |
# 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) ⇒ Object
46 47 48 49 50 51 52 53 |
# 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) ⇒ Object
63 64 65 |
# 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) ⇒ Object
77 78 79 80 81 82 83 |
# 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) ⇒ Object
67 68 69 70 |
# 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) ⇒ Object
72 73 74 75 |
# 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 |