Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to make a browser in Ruby Tk

154 views
Skip to first unread message

sujeet kumar

unread,
Jun 16, 2005, 9:57:40 AM6/16/05
to
Hi
I want to make a web browser in Ruby Tk. I used "net/http" to connect
to net. url is to be given in Tk entry. I am getting data from url
using "response = http.get(url)" . when i printed "response.body" it
gives the HTML source of the given Url. Now I want to display the
content in Ruby Frame. How can i print this ( data of url) in Ruby
Frame.
Please Help
thanks
sujeet


Hidetoshi NAGAI

unread,
Jun 16, 2005, 10:42:35 AM6/16/05
to
From: sujeet kumar <suje...@gmail.com>
Subject: How to make a browser in Ruby Tk
Date: Thu, 16 Jun 2005 22:57:40 +0900
Message-ID: <734fb92405061...@mail.gmail.com>

Probably one of the easiest way is to use TkHTML extension
(see http://www.hwaci.com/sw/tkhtml/index.html).
If you install the extension on your Tcl/Tk environment
(for example, you use ActiveTcl binary package) and use
the Tcl/Tk's library on your Ruby/Tk, please try a browser
example by Ruby/Tk + TkHTML. That is included in Ruby's
source archive ("ext/tk/sample/tkextlib/tkHTML/hv.rb").
If the HTML text which you want to browse is a simple one,
the following may be enough to show the formatted document.
--------------------------------------------------------------
require 'tk'
require 'tkextlib/tkHTML'

.. read a HTML-doc, and set it to the variable 'doc' ...

hv = Tk::HTML_Widget.new.pack
hv.parse(doc)

..
--------------------------------------------------------------
--
Hidetoshi NAGAI (na...@ai.kyutech.ac.jp)


sujeet kumar

unread,
Jun 16, 2005, 6:23:37 PM6/16/05
to
When I run Ruby's source archive ("ext/tk/sample/tkextlib/tkHTML/hv.rb").
I got error
/usr/local/lib/ruby/1.8/tk/package.rb:86:in `require': TkPackage can't
find package Tkhtml (RuntimeError)
from /usr/local/lib/ruby/1.8/tkextlib/tkHTML/htmlwidget.rb:15
from /usr/local/lib/ruby/1.8/tkextlib/tkHTML.rb:13:in `require'
from /usr/local/lib/ruby/1.8/tkextlib/tkHTML.rb:13
from hv.rb:10:in `require'
from hv.rb:10
When i run the program in example given by you it also gives same error.
I want to display HTML text in Ruby widget as the HTML file displays
in web browser.
bye
sujeet


On 6/16/05, Hidetoshi NAGAI <na...@ai.kyutech.ac.jp> wrote:
> From: sujeet kumar <suje...@gmail.com>
> Subject: How to make a browser in Ruby Tk
> Date: Thu, 16 Jun 2005 22:57:40 +0900
> Message-ID: <734fb92405061...@mail.gmail.com>
> > I want to make a web browser in Ruby Tk. I used "net/http" to connect
> > to net. url is to be given in Tk entry. I am getting data from url
> > using "response = http.get(url)" . when i printed "response.body" it
> > gives the HTML source of the given Url. Now I want to display the
> > content in Ruby Frame. How can i print this ( data of url) in Ruby
> > Frame.
>
> Probably one of the easiest way is to use TkHTML extension
> (see http://www.hwaci.com/sw/tkhtml/index.html).
> If you install the extension on your Tcl/Tk environment
> (for example, you use ActiveTcl binary package) and use
> the Tcl/Tk's library on your Ruby/Tk, please try a browser
> example by Ruby/Tk + TkHTML. That is included in Ruby's
> source archive ("ext/tk/sample/tkextlib/tkHTML/hv.rb").
> If the HTML text which you want to browse is a simple one,
> the following may be enough to show the formatted document.
> --------------------------------------------------------------
> require 'tk'
> require 'tkextlib/tkHTML'
>

> ... read a HTML-doc, and set it to the variable 'doc' ...


>
> hv = Tk::HTML_Widget.new.pack
> hv.parse(doc)
>

> ...

Hidetoshi NAGAI

unread,
Jun 16, 2005, 9:05:08 PM6/16/05
to
From: sujeet kumar <suje...@gmail.com>
Subject: Re: How to make a browser in Ruby Tk
Date: Fri, 17 Jun 2005 07:23:37 +0900
Message-ID: <734fb92405061...@mail.gmail.com>
> When I run Ruby's source archive ("ext/tk/sample/tkextlib/tkHTML/hv.rb").
> I got error

I wrote

> If you install the extension on your Tcl/Tk environment
> (for example, you use ActiveTcl binary package) and use
> the Tcl/Tk's library on your Ruby/Tk,

The error which you got shows that Tcl/Tk's TkHTML extension is not
installed (or not ready to use) on your environment.

# Please read "<ruby library>/tkextlib/SUPPORT_STATUS".
--
Hidetoshi NAGAI (na...@ai.kyutech.ac.jp)


sujeet kumar

unread,
Jun 19, 2005, 1:42:09 AM6/19/05
to
Hi,
I am new to ruby. How to install the extension onTcl/Tk
environment and use the Tcl/Tk's library on Ruby/Tk ? My OS is fc3
and I installed everything of the option on fc3 cd. My ruby version is
"ruby 1.8.2 (2004-12-25) [i686-linux]". I tried to install from
http://www.hwaci.com/sw/tkhtml/index.html link but it doesn't work.
ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.2-preview1.tar.gz is
also not working.
What packages do i need for installing the extension? I don't know
about Tcl . How to check it is properly installed? It would be
helpfull if you send me some suitable link for these.
Thanks
sujeet

Hidetoshi NAGAI

unread,
Jun 19, 2005, 11:14:36 AM6/19/05
to
From: sujeet kumar <suje...@gmail.com>
Subject: Re: How to make a browser in Ruby Tk
Date: Sun, 19 Jun 2005 14:42:09 +0900
Message-ID: <734fb92405061...@mail.gmail.com>

> I am new to ruby. How to install the extension onTcl/Tk
> environment and use the Tcl/Tk's library on Ruby/Tk ? My OS is fc3
> and I installed everything of the option on fc3 cd. My ruby version is
> "ruby 1.8.2 (2004-12-25) [i686-linux]". I tried to install from
> http://www.hwaci.com/sw/tkhtml/index.html link but it doesn't work.

I don't know existence of RPM pakage of tkHTML extension for FC3.
If you have development packages of Tcl/Tk and want install tkHTML
from source files, you'll be able to find the compile steps in
COMPILE.txt included in the tkHTML source archive.

If you don't mind to use RPM packages, maybe to use the ActiveTcl
binary package is one of the easiest way to make some extensions
available on your Ruby/Tk.
Then,

* get an ActiveTcl binary package.
(e.g. ActiveTcl8.4.10.0.147113-linux-ix86.tar.gz)

* extract the package.
(e.g. tar xvzf ActiveTcl8.4.10.0.147113-linux-ix86.tar.gz)

* cd to the extracted directory and run ./install.sh.
(e.g. cd ActiveTcl8.4.10.0.147113-linux-ix86; sh ./install.sh).

Assume that ActiveTcl is installed at /usr/local/ActiveTcl.

* Please read 'ext/tcltklib/README.ActiveTcl'(Ruby-1.8)
'ext/tk/README.ActiveTcl'(Ruby-1.9) .

* add ActiveTcl's library directory to your library path.

* extract Ruby source archive and cd to the generated directory.

* run ./configure with options which indicates ActiveTcl libraries.
(e.g. ./configure --with-tcl-dir=/usr/local/ActiveTcl/ \
--with-tk-dir=/usr/local/ActiveTcl/ \
--with-tcllib=tclstub8.4 \
--with-tklib=tkstub8.4 \
--enable-tcltk-stubs )

* make & make install

> What packages do i need for installing the extension? I don't know
> about Tcl . How to check it is properly installed?

On Tcl/Tk, if succeed "package require <package name>",
probably the package is properly installed.
If you want to check whether an extension is ready to use
on Ruby/Tk, please run "<ruby library>/tkextlib/pkg_checker.rb".
It possibly help you to know what kind of extensions are available
on your Ruby/Tk.
When an extension is available on Tcl/Tk but not available on
Ruby/Tk, possibly, the reason of the difference is that
(1) Ruby/Tk use different Tcl/Tk libraries from tested Tcl/Tk, or
(2) Ruby/Tk don't know the library path of the extension.
If (1), maybe remove old(?) library and recompile "tcltklib.so".
If (2), maybe you have to add initialize steps (e.g. add library
path of the extension to AUTO_PATH) to "setup.rb" on the Ruby/Tk's
wrapper library directory for the extension.
--
Hidetoshi NAGAI (na...@ai.kyutech.ac.jp)


sujeet kumar

unread,
Jun 19, 2005, 2:40:43 PM6/19/05
to
Hi
I installed ActiveTcl8.5.0.0b3.121397-linux-ix86.tar.gz in
/usr/local/ActiveTcl.
Now how to " add ActiveTcl's library directory to your library path"
I tried to use

[bash]$ D_LIBRARY_PATH=/usr/local/ActiveTcl/lib:$LD_LIBRARY_PATH \
ruby your-Ruby/Tk-script
it gives "ruby: No such file or directory -- your-Ruby/Tk-script (LoadError)"
how can i find the path of "ruby your-Ruby/Tk-script"? Is it
"/home/sujeet/Soft/ruby-1.8.2/ext/tk" or it is in /usr directory or
else.

[bash]$ _LIBRARY_PATH=/usr/local/ActiveTcl/lib:$LD_LIBRARY_PATH irb
gives "irb(main):001:0> "
what to do next?

or how to use TCLLIBPATH ?
'Tk::AUTO_PATH.value' or 'Tk::AUTO_PATH.list' gives
bash: Tk::AUTO_PATH.value: command not found
bash: Tk::AUTO_PATH.list: command not found

After this in ./configure --with-tcl-dir=/usr/local/ActiveTcl/ \


> --with-tk-dir=/usr/local/ActiveTcl/ \
> --with-tcllib=tclstub8.4 \
> --with-tklib=tkstub8.4 \
> --enable-tcltk-stubs )

step what is tclstub8.4 ? should i replace it with tclstub8.5 as my
package is ActiveTcl8.5.0.0b3.121397-linux-ix86.tar.gz.

Rest steps are clear. This will be a great help for me .
Thanks
sujeet

Hidetoshi NAGAI

unread,
Jun 19, 2005, 10:18:22 PM6/19/05
to
From: sujeet kumar <suje...@gmail.com>
Subject: Re: How to make a browser in Ruby Tk
Date: Mon, 20 Jun 2005 03:40:43 +0900
Message-ID: <734fb92405061...@mail.gmail.com>

> I installed ActiveTcl8.5.0.0b3.121397-linux-ix86.tar.gz in
> /usr/local/ActiveTcl.
> Now how to " add ActiveTcl's library directory to your library path"
> I tried to use
(snip)

> step what is tclstub8.4 ? should i replace it with tclstub8.5 as my
> package is ActiveTcl8.5.0.0b3.121397-linux-ix86.tar.gz.

Hmmm....
I tried on my environment (distribution:: Vine Linux).
ActiveTcl 8.5.0.0b3 was installed at /usr/local/ActiveTcl8.5.0.0b3,
and Ruby configured with ActiveTcl8.5.0.0b3 is installed under /usr/local.
Then,
------------------------------------------------------------------
(bash)$ LD_LIBRARY_PATH=/usr/local/ActiveTcl8.5.0.0b3/lib:$LD_LIBRARY_PATH /usr/local/bin/irb
irb(main):001:0> require 'tk'
=> true
irb(main):002:0> Tk::TK_PATCHLEVEL
=> "8.5a2"
irb(main):003:0> Tk::AUTO_PATH.list
=> ["/usr/local/ActiveTcl8.5.0.0b3/lib/tcl8.5", "/usr/local/ActiveTcl8.5.0.0b3/lib", "/usr/local/lib", "/usr/local/ActiveTcl8.5.0.0b3/lib/tk8.5"]
irb(main):004:0> require 'tkextlib/tkHTML'
=> true
irb(main):005:0>
------------------------------------------------------------------
Please note that "require 'tkextlib/tkHTML'" returns true.
It shows that TkHTML extension is available.

Cannot you get the same result?
If you don't, please check conflict between ActiveTcl and other
versions of Tcl/Tk libraries.

If you succeed, please try
"LD_LIBRARY_PATH=/usr/local/ActiveTcl8.5.0.0b3/lib:$LD_LIBRARY_PATH
/usr/local/bin/ruby /usr/local/lib/ruby/1.8/tkextlib/pkg_checker.rb -v".

--
Hidetoshi NAGAI (na...@ai.kyutech.ac.jp)


sujeet kumar

unread,
Jun 20, 2005, 3:51:07 AM6/20/05
to
Hi,
This is summary of what i did.
I got ActiveTcl8.5.121397-linux-ix86.tar.gz.
1)I used :
tar xvzf ActiveTcl8.5.0.0b3.121397-linux-ix86.tar.gz
2)cd ActiveTcl8.5.0.0b3.121397-linux-ix86.tar.gz
3)sh ./install.sh
Now, ActiveTcl is installed at /usr/local/ActiveTcl
4)add ActiveTcl's library directory to your library path
i used :
export PATH="/usr/local/ActiveTcl/bin:$PATH"
3) i installed ruby
tar xvzf ruby-1.8.2.tar.gz
4)cd ruby-1.8.2
5)./configure --with-tcl-dir=/usr/local/ActiveTcl/ \
--with-tk-dir=/usr/local/ActiveTcl/ \
--with-tcllib=tclstub8.5 \
--with-tklib=tkstub8.5 \
--enable-tcltk-stubs
6)make
7)make install
8) LD_LIBRARY_PATH=/usr/local/ActiveTcl8.5.0.0b3/lib:$LD_LIBRARY_PATH

/usr/local/bin/irb
irb(main):001:0> require 'tk'
=> true
irb(main):002:0> Tk::TK_PATCHLEVEL
=> "8.4.7"

irb(main):003:0> Tk::AUTO_PATH.list
=> ["/usr/share/tcl8.4", "/usr/share", "/usr/local/lib", "/usr/lib",
"/usr/share/tk8.4"]

irb(main):004:0> require 'tkextlib/tkHTML'
RuntimeError: TkPackage can't find package Tkhtml
from /usr/local/lib/ruby/1.8/tk/package.rb:86:in `require'

from /usr/local/lib/ruby/1.8/tkextlib/tkHTML/htmlwidget.rb:15
from /usr/local/lib/ruby/1.8/tkextlib/tkHTML.rb:13:in `require'
from /usr/local/lib/ruby/1.8/tkextlib/tkHTML.rb:13
from (irb):4:in `require'
from (irb):4
9)since i installed ActiveTcl8.5.0.0b3.121397-linux-ix86
but Tk::TK_PATCHLEVEL, gives "8.4.7"
Is this mean I have ActiveTcl"8.4.7" installed?

Also,Tk::AUTO_PATH.list
doesnot give "/usr/local/ActiveTcl/"

What sould I do?
How to uninstall ActiveTcl"8.4.7"
How to add Path of "/usr/local/ActiveTcl/" in k::AUTO_PATH.list

Thanks
sujeet

Hidetoshi NAGAI

unread,
Jun 20, 2005, 4:23:58 AM6/20/05
to
From: sujeet kumar <suje...@gmail.com>
Subject: Re: How to make a browser in Ruby Tk
Date: Mon, 20 Jun 2005 16:51:07 +0900
Message-ID: <734fb92405062...@mail.gmail.com>

> 3)sh ./install.sh
> Now, ActiveTcl is installed at /usr/local/ActiveTcl
(snip)
> 8) LD_LIBRARY_PATH=/usr/local/ActiveTcl8.5.0.0b3/lib:$LD_LIBRARY_PATH /usr/local/bin/irb

That is a wrong path.
You installed ActiveTcl to "/usr/local/ActiveTcl".
So, you have to use
LD_LIBRARY_PATH=/usr/local/ActiveTcl/lib:$LD_LIBRARY_PATH /usr/local/bin/irb

> 9)since i installed ActiveTcl8.5.0.0b3.121397-linux-ix86
> but Tk::TK_PATCHLEVEL, gives "8.4.7"
> Is this mean I have ActiveTcl"8.4.7" installed?

Probably, that is FC3's Tcl/Tk packages.

> What sould I do?

If you fail to load ActiveTcl's libraries instead of FC3's
libraries (even if you use the right LD_LIBRARY_PATH),
you maybe have to remove FC3's Tcl/Tk packages or add
/usr/local/ActiveTcl/lib to /etc/ld.so.conf with
higher priority than FC3's library path.
--
Hidetoshi NAGAI (na...@ai.kyutech.ac.jp)


sujeet kumar

unread,
Jun 20, 2005, 9:24:25 AM6/20/05
to
hi, Firstly i add
/usr/local/ActiveTcl/lib to /etc/ld.so.conf on top
But it didn't work. Then I
i uninstall Tcl package of fc3.
i used " rpm -qa | grep tcl"
rpm -e --nodeps tcl-devel-8.4.7-2
rpm -e --nodeps tk-8.4.7-2
rpm -e --nodeps tcl-8.4.7-2

After this I reinstall ActiveTcl is installed at /usr/local/ActiveTcl
and set path.

Then i used tar xvzf ruby-1.8.2.tar.gz
cd ruby-1.8.2


/configure --with-tcl-dir=/usr/local/ActiveTcl/ \
--with-tk-dir=/usr/local/ActiveTcl/ \
--with-tcllib=tclstub8.5 \
--with-tklib=tkstub8.5 \
--enable-tcltk-stubs

make
make install
Then , LD_LIBRARY_PATH=/usr/local/ActiveTcl8.5.0.0b3/lib:$LD_LIBRARY_PATH
=/usr/local/bin/irb


irb(main):001:0> require 'tk'

LoadError: libtk8.4.so: cannot open shared object file: No such file
or directory - /usr/local/lib/ruby/1.8/i686-linux/tcltklib.so
from /usr/local/lib/ruby/1.8/i686-linux/tcltklib.so
from /usr/local/lib/ruby/1.8/tk.rb:7
from (irb):1:in `require'
from (irb):1


irb(main):002:0> Tk::TK_PATCHLEVEL

NameError: uninitialized constant Tk
from (irb):2


irb(main):003:0> Tk::AUTO_PATH.list

NameError: uninitialized constant Tk
from (irb):3


irb(main):004:0> require 'tkextlib/tkHTML'

NameError: uninitialized constant TkPackage


from /usr/local/lib/ruby/1.8/tkextlib/tkHTML/htmlwidget.rb:15
from /usr/local/lib/ruby/1.8/tkextlib/tkHTML.rb:13:in `require'
from /usr/local/lib/ruby/1.8/tkextlib/tkHTML.rb:13
from (irb):4:in `require'
from (irb):4

what should I do?
I want to install it any way. For this i can uninstall and reinstall
all things.Just tell me what to do.?
presently
rpm -qa | grep tcl
gives
tclx-8.3.5-4 db4-tcl-4.2.52-6 tcl-html-8.4.7-2
postgresql-tcl-7.4.6-1.FC3.1
tclx-devel-8.3.5-4
ruby-tcltk-1.8.1-7
tclx-doc-8.3.5-4

Should I erase all the above?
I think problem is that Ruby is not taking the path of Tcl/Tk
extension correctly.
bye
sujeet

On 6/20/05, Hidetoshi NAGAI <na...@ai.kyutech.ac.jp> wrote:

Hidetoshi NAGAI

unread,
Jun 20, 2005, 10:30:49 AM6/20/05
to
From: sujeet kumar <suje...@gmail.com>
Subject: Re: How to make a browser in Ruby Tk
Date: Mon, 20 Jun 2005 22:24:25 +0900
Message-ID: <734fb9240506...@mail.gmail.com>

> hi, Firstly i add
> /usr/local/ActiveTcl/lib to /etc/ld.so.conf on top
> But it didn't work.

Did you execute /sbin/ldconfig after modifying /etc/ld.so.conf?

# On my environment, that works properly.

> After this I reinstall ActiveTcl is installed at /usr/local/ActiveTcl
> and set path.
>
> Then i used tar xvzf ruby-1.8.2.tar.gz
> cd ruby-1.8.2

> ./configure --with-tcl-dir=/usr/local/ActiveTcl/ \


> --with-tk-dir=/usr/local/ActiveTcl/ \
> --with-tcllib=tclstub8.5 \
> --with-tklib=tkstub8.5 \
> --enable-tcltk-stubs
>
> make

Please check that tcltklib.so is really compiled.

> Then , LD_LIBRARY_PATH=/usr/local/ActiveTcl8.5.0.0b3/lib:$LD_LIBRARY_PATH
^^^^^^^^^
???
You installed ActiveTcl at "/usr/local/ActiveTcl", didn't you?
Is that typo? If not, it is no wonder to fail to find libraries.
As I wrote in my last mail, you must add "/usr/local/ActiveTcl/lib".

e.g.
(bash)$ LD_LIBRARY_PATH=/usr/local/ActiveTcl/lib /usr/local/bin/irb

> rpm -qa | grep tcl
> gives
> tclx-8.3.5-4 db4-tcl-4.2.52-6 tcl-html-8.4.7-2
> postgresql-tcl-7.4.6-1.FC3.1
> tclx-devel-8.3.5-4
> ruby-tcltk-1.8.1-7
> tclx-doc-8.3.5-4
>
> Should I erase all the above?

If you erased FC3's Tcl/Tk packages, probably all of them will not
work. Those are fillers of your disk. :-)

# If setting is proper, ActiveTcl can coexistent with FC3's Tcl/Tk.
--
Hidetoshi NAGAI (na...@ai.kyutech.ac.jp)


sujeet kumar

unread,
Jun 20, 2005, 5:43:17 PM6/20/05
to
Hi,
Thanks . It worked now.
Thanks for your kind support.
regards
sujeet

On 6/20/05, Hidetoshi NAGAI <na...@ai.kyutech.ac.jp> wrote:

0 new messages