Consider the following goal:
* Parse the html "<a href=foo>click me</a>" and display.
* Detect user clicks convert to href.
The following code does *not* work:
----
require 'tk'
require 'tkextlib/tkHTML'
def do_click(s)
puts s + "\n"
end
html = Tk::HTML_Widget.new(TkRoot.new,'hyperlinkcommand'=>proc {|s|
do_click(s)})
html.parse("<a href=foo>click me</a>")
html.pack
Tk.mainloop
----
The following code does work but is rather inelgant (note the Tk.bind):
----
require 'tk'
require 'tkextlib/tkHTML'
def do_click(x,y)
href = $HTML.href(x,y)[0]
print href + "\n" if href
end
$HTML = Tk::HTML_Widget.new(TkRoot.new)
Tk.bind($HTML.path + ".x",'1',proc {|x,y| do_click(x,y)},"%x %y")
$HTML.parse("<a href=foo>click me</a>")
$HTML.pack
Tk.mainloop
----
Does anyone know what the 'hyperlinkcommand' property of HTML_Widget
does? Anyone have other ways to make clicking on hyperlinks work?
BTW, HTML_Widget corresponds (at least on my system) to tkHTML 2.0.
c.