Forum: Ruby ruby/tk HTML_Widget and href's

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2e34f386b20cb7c11c4204d699babd78?d=identicon&s=25 Chris Alfeld (Guest)
on 2006-04-13 22:37
(Received via mailing list)
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.
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 Hidetoshi NAGAI (Guest)
on 2006-04-14 04:53
(Received via mailing list)
From: "Chris Alfeld" <chris.alfeld@gmail.com>
Subject: ruby/tk HTML_Widget and href's
Date: Fri, 14 Apr 2006 05:34:49 +0900
Message-ID: <b40ff0a0604131334w1d1adfvd4b05ef806eaace2@mail.gmail.com>

> 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:

I'm very sorry, but I don't know why.
Tcl/Tk gives (probably) same result for same operations as your ruby's.
It means that it is not a bug on Ruby/Tk.
Maybe, people who have answers for your question are members of
Tcl/Tk community.
2e34f386b20cb7c11c4204d699babd78?d=identicon&s=25 Chris Alfeld (Guest)
on 2006-04-14 05:17
(Received via mailing list)
Yes, sorry.  I should have said as much.  I've run into similar issues
using Tcl/Tk.

Perhaps it would be worth adding bind_x, bind_append_x, bindtags_x,
etc. to the HTML_Widget class to bind to the .x subwidget.  It is,
incidentally, the only subwidget.  What do you think?

c.
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 Hidetoshi NAGAI (Guest)
on 2006-04-14 05:35
(Received via mailing list)
From: "Chris Alfeld" <chris.alfeld@gmail.com>
Subject: Re: ruby/tk HTML_Widget and href's
Date: Fri, 14 Apr 2006 12:16:10 +0900
Message-ID: <b40ff0a0604132016r4d93a571q46766206599892ec@mail.gmail.com>
> Perhaps it would be worth adding bind_x, bind_append_x, bindtags_x,
> etc. to the HTML_Widget class to bind to the .x subwidget.  It is,
> incidentally, the only subwidget.  What do you think?

I don't think so.
The .x subwidget is a widget of 'HtmlClip' class.
On Ruby/Tk, you can get a Tk::HTML_Widget::ClippingWindow object
for the subwidget.
E4f967492dbd03c526cc9b397e68021d?d=identicon&s=25 Hidetoshi NAGAI (Guest)
on 2006-04-14 05:35
(Received via mailing list)
From: Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
Subject: Re: ruby/tk HTML_Widget and href's
Date: Fri, 14 Apr 2006 12:32:11 +0900
Message-ID: <20060414.123208.112610371.nagai@ai.kyutech.ac.jp>
> -----------------------------------------------
> h = Tk::HTML_Widget.new
> cw = Tk::HTML_Widget::ClippingWindow.new(h)
> cw.bind('2', proc{puts "click Button-2 ! "})
> -----------------------------------------------

Or,
2e34f386b20cb7c11c4204d699babd78?d=identicon&s=25 Chris Alfeld (Guest)
on 2006-04-14 16:04
(Received via mailing list)
Ah, I had not realized.  I saw the ClippingWindow code but hadn't
realized how it related.  Thanks!

c.
2e34f386b20cb7c11c4204d699babd78?d=identicon&s=25 Chris Alfeld (Guest)
on 2006-04-14 16:19
(Received via mailing list)
For anyone following this thread and interested, here's the third
version of the sample code.  This does work:

----
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::HTML_Widget::ClippingWindow.new($HTML).bind('1',
  proc {|x,y| do_click(x,y)},"%x %y")
$HTML.parse("<a href=foo>click me</a>")
$HTML.pack

Tk.mainloop
----
This topic is locked and can not be replied to.