class Gtk2HTML::Main
Attributes
doc[RW]
height[R]
html[RW]
layout_instructions[RW]
width[R]
window[R]
Public Class Methods
new(html, irb: false)
click to toggle source
# File lib/gtk2html.rb, line 516 def initialize(html, irb: false) @html = html @doc = Htmle.new(html, callback: self) @area = area = Gtk::DrawingArea.new @layout = layout = Gtk::Layout.new widgets = nil client_code = [] window = Gtk::Window.new @width = 320 @height = 240 @window = window window.set_default_size(@width, @height) @dirty = true layout.signal_connect("expose_event") do width, height = window.size @dirty = true if [@width, @height] != [width, height] if @dirty then @layout_instructions = prepare_layout @doc end drawing = Gtk2HTML::DrawingInstructions.new layout drawing.render @layout_instructions @dirty = false end area.add_events(Gdk::Event::POINTER_MOTION_MASK) area.signal_connect('motion_notify_event') do |item, event| @doc.root.xpath('//*[@onmousemove]').each do |x| eval x.onmousemove() if x.hotspot? event.x, event.y end end area.add_events(Gdk::Event::BUTTON_PRESS_MASK) area.signal_connect "button_press_event" do |item,event| @doc.root.xpath('//*[@onmousedown]').each do |x| eval x.onmousedown() if x.hotspot? event.x, event.y end end layout_instructions = prepare_layout @doc widgets = Gtk2HTML::WidgetInstructions.new layout widgets.render layout_instructions @layout.put area, 0, 0 window.add(@layout).show_all window.show_all.signal_connect("destroy"){Gtk.main_quit} irb ? Thread.new {Gtk.main } : Gtk.main end
Public Instance Methods
html=(html)
click to toggle source
# File lib/gtk2html.rb, line 602 def html=(html) @html = html @doc = Htmle.new(svg, callback: self) end
onmousemove(x,y)
click to toggle source
# File lib/gtk2html.rb, line 593 def onmousemove(x,y) end
refresh()
click to toggle source
# File lib/gtk2html.rb, line 597 def refresh() @dirty = true @area.queue_draw end
Private Instance Methods
prepare_layout(doc)
click to toggle source
# File lib/gtk2html.rb, line 609 def prepare_layout(doc) Thread.new { doc.root.xpath('//script').each {|x| eval x.text.unescape } } @width, @height = window.size instructions = Gtk2HTML::Render.new(doc, @width, @height).to_a Gtk2HTML::Layout.new(instructions).to_a end