File: test-gtkhtml.rb

package info (click to toggle)
ruby-gnome2 0.12.0-2sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,820 kB
  • ctags: 7,421
  • sloc: ansic: 61,387; ruby: 17,307; makefile: 85; xml: 35; sql: 13
file content (52 lines) | stat: -rw-r--r-- 1,257 bytes parent folder | download
1
2
3
4
5
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'gtk2'
require 'gtkhtml2'

Gtk.init

window = Gtk::Window.new

window.signal_connect( "destroy" ) {
   Gtk.main_quit
}

window.border_width = 10
window.set_default_size(200, 200)

htmlview = Gtk::HtmlView.new()
htmlview.show

window.add(htmlview)
window.show_all

doc = Gtk::HtmlDocument.new()
doc.open_stream('text/html')
doc.write_stream('<html><body><h1>TEST 2</h1>HtmlDocument test</br>\
    <a href="foo">link test foo</a>\
    <a href="bar">link test bar</a>\
    </body></html>')
doc.close_stream()

doc.signal_connect( "link_clicked" ) {  |doc,link|
    puts "link_clicked #{link}"
    htmlview.document.clear
    htmlview.document.open_stream("text/html")
    htmlview.document.write_stream( "<html><body><h1>#{link}</h1></body></html>")
    htmlview.document.close_stream()
}

##### sample handler for 'request_url' signal might look like this
##### (you need this to show images inside the widget)
#doc.signal_connect('request_url') { |html_doc, url, stream|
#   puts "request_url #{html_doc} #{url} #{stream}"
#   File.open( File.expand_path(url) ) {|file| #TODO: here add argument for base_url
#     puts "open success"
#     data = file.read()
#     stream.write(data)
#     stream.close()
#   }
#}

htmlview.document = doc

Gtk.main