Ruby/Tk, TkMessage

Hello,

I need to use a Ruby/Tk widget to display some read-only information,
which can be multi-line. I need the widget to be displayed as a
certain size (say, width=100, height=50) even when it doesn’t have any
text in it. I would use TkText if there is a way to make it read-only.
I was trying to use TkMessage. But I don’t know of a way to set its
size. Following is my code:
msgDisplay = TkMessage.new(lfrm2) do
text "server messages "
relief "sunken"
width 100
#height 15
pack(“side”=>“top”, “padx”=>5, “pady”=>5)
end

Is there a way to achieve what I need to do? Can anyone point me to
the right direction?

Thanks very much,
Dandan

Hello,

I need to use a Ruby/Tk widget to display some read-only information,
which can be multi-line. I need the widget to be displayed as a
certain size (say, width=100, height=50) even when it doesn’t have any
text in it. I would use TkText if there is a way to make it read-only.

This procedure will still allow the text to be selected, but won’t allow
for modifications, or even an insertion cursor.

require ‘tk’
root = TkRoot.new()
text = TkText.new(root){height 10; width 20}.pack
text.insert(‘0.1’, ‘This is my message’)
text.state(‘disabled’)
root.mainloop

Height and width I did not set to 50 and 100, since those attributes for a
TkText widget are in characters rather than pixels (and at least on my
screen that results in a screen-filling widget).

The state attribute/method and the height/width idiosyncrasies are
documented in the Tk documentation for the text command at
http://www.tcl.tk. That’s always the first place I look for stuff like
this.

I’ll have to look into TkMessage before I can comment on that… it’s not a
widget I’ve ever used.

HTH

  • -michael

Michael_C_Libby{x(at)ichimunki(dot)com}__

···

On Tuesday 09 July 2002 00:45, Dandan He wrote:

   my Ruby website: http://www.andsoforth.com/        | 

____ public key at http://www.ichimunki.com/public.key ____|

Hi,

···

From: katiedhe@hotmail.com (Dandan He)
Subject: Ruby/Tk, TkMessage
Date: Tue, 9 Jul 2002 14:45:48 +0900
Message-ID: 5d85b7fe.0207082127.3f806f76@posting.google.com

I need to use a Ruby/Tk widget to display some read-only information,
which can be multi-line. I need the widget to be displayed as a
certain size (say, width=100, height=50) even when it doesn’t have any
text in it. I would use TkText if there is a way to make it read-only.

Use a frame widget with fixed size.
If you want to use Pack geometry manager only,
you must do TkPack.propagate(, false)
to block the propagation of size.
For example,

require ‘tk’
f = TkFrame.new(nil, ‘width’=>100, ‘height’=>50).pack
TkPack.propagate(f,false)
TkMessage.new(f, ‘text’=>‘1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000’).pack
Tk.mainloop

As you see when you run it,
the center part of the message widget is shown.
But if you want to show upper-left corner of the message widget,
probably you must use Place geometry manager.
For example,

require ‘tk’
f = TkFrame.new(nil, ‘width’=>100, ‘height’=>50).pack
TkMessage.new(f, ‘text’=>‘1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000’).place(‘x’=>0, ‘y’=>0)
Tk.mainloop

In this case, no need TkPack.propagate.
The message widget has no influence on the frame widget,
because the message widget is not known by Pack geometry manager.

                              Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

the same thing happend to me with another library, i forget which. i had
to download the ruby source tarball and extract it and copy the missing
file(s) to my distribution. worked.

related to tcltk has anyone gotten the tkext to work? i’m messing with
the installation. i have tix installed. and i’ve edited the Tix.def file
to point to my tix path and ran mk_tkextlib.rb -p Tix. that ran fine,
then i copied the 3 .rb libraries (tkext, tcltkext, tcltkextlib) to my
ruby installtion location. when i test it out i get an error saying it
can’t find the library, but not the library i specified in Tix.def. its
still looking for the default one. any ideas on how to fix this?

~tranasmi

p.s. what’s Tix-for-TkPackage.rb, too?

···

On Thu, 2002-07-11 at 21:51, nagai@ai.kyutech.ac.jp wrote:

Hi,

From: katiedhe@hotmail.com (Dandan He)
Subject: Ruby/Tk, TkMessage
Date: Tue, 9 Jul 2002 14:45:48 +0900
Message-ID: 5d85b7fe.0207082127.3f806f76@posting.google.com

I need to use a Ruby/Tk widget to display some read-only information,
which can be multi-line. I need the widget to be displayed as a
certain size (say, width=100, height=50) even when it doesn’t have any
text in it. I would use TkText if there is a way to make it read-only.

Use a frame widget with fixed size.
If you want to use Pack geometry manager only,
you must do TkPack.propagate(, false)
to block the propagation of size.
For example,

require ‘tk’
f = TkFrame.new(nil, ‘width’=>100, ‘height’=>50).pack
TkPack.propagate(f,false)
TkMessage.new(f, ‘text’=>‘1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000’).pack
Tk.mainloop

As you see when you run it,
the center part of the message widget is shown.
But if you want to show upper-left corner of the message widget,
probably you must use Place geometry manager.
For example,

require ‘tk’
f = TkFrame.new(nil, ‘width’=>100, ‘height’=>50).pack
TkMessage.new(f, ‘text’=>‘1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000’).place(‘x’=>0, ‘y’=>0)
Tk.mainloop

In this case, no need TkPack.propagate.
The message widget has no influence on the frame widget,
because the message widget is not known by Pack geometry manager.

                              Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)


~transami

“They that can give up essential liberty to obtain a little
temporary safety deserve neither liberty nor safety.”
– Benjamin Franklin

okay, for anyone else installing tkext here’s ths scoop.

first you have to install tix (debian testing .deb worked fine although
the .so will be under /usr/lib, not use/local/lib)

then unpack tkext. warning! it extracts directly into the working
directory.

then you need to edit the Tix.def file and make sure the .so library
name is correct and the path is correct.

then run ruby mk_tkextlib.rb -p Tix (i’m not sure what -b does,
somthing about dynamic behavior, but i got the notion that is was
probably undesired) -v is verbose and appears to spit out BASE_INFO, or
a derivation of it. don’t have any clue about -g. note you’ll probably
notice a couple warnings about deprecated functions. these are simply
functions that don’t match up with tkext’s expectations (because tix has
since changed). nothing to worry about, just don’t try to use those.

now, copy the 3 main libraries: tkext.rb, tcltkext.rb, and
tcltkextlib.rb into your ruby installation path. i recommend just
putting it in the main /usr/lib/ruby/1.6/ path along with all the other
tk stuff that’s already there.

also copy Tix.rb and Tix.inf to somewhere in the ruby path. best to put
them with the rest, although they could go else where, but they must be
placed together!

when wirtting your scripts just use require ‘Tix’.

a number of the test apps don’t work! this is beacuse they bypass
require ‘Tix’ and instead require the main libraries directly. this
requires them to manually point to the location of the tix .so. to get
them to work you will have to edit each script and change the name and
path, just like you did with Tix.def.

taht’s it. now if i can just find some api docs…

hope this is helpful.

by the way i’m currently comparing tk+tix to fxruby to see how they
match up.

hey, does anyone want to automate this proc?

~transami

···

On Fri, 2002-07-12 at 00:16, Tom Sawyer wrote:

the same thing happend to me with another library, i forget which. i had
to download the ruby source tarball and extract it and copy the missing
file(s) to my distribution. worked.

related to tcltk has anyone gotten the tkext to work? i’m messing with
the installation. i have tix installed. and i’ve edited the Tix.def file
to point to my tix path and ran mk_tkextlib.rb -p Tix. that ran fine,
then i copied the 3 .rb libraries (tkext, tcltkext, tcltkextlib) to my
ruby installtion location. when i test it out i get an error saying it
can’t find the library, but not the library i specified in Tix.def. its
still looking for the default one. any ideas on how to fix this?

~tranasmi

p.s. what’s Tix-for-TkPackage.rb, too?

On Thu, 2002-07-11 at 21:51, nagai@ai.kyutech.ac.jp wrote:

Hi,

From: katiedhe@hotmail.com (Dandan He)
Subject: Ruby/Tk, TkMessage
Date: Tue, 9 Jul 2002 14:45:48 +0900
Message-ID: 5d85b7fe.0207082127.3f806f76@posting.google.com

I need to use a Ruby/Tk widget to display some read-only information,
which can be multi-line. I need the widget to be displayed as a
certain size (say, width=100, height=50) even when it doesn’t have any
text in it. I would use TkText if there is a way to make it read-only.

Use a frame widget with fixed size.
If you want to use Pack geometry manager only,
you must do TkPack.propagate(, false)
to block the propagation of size.
For example,

require ‘tk’
f = TkFrame.new(nil, ‘width’=>100, ‘height’=>50).pack
TkPack.propagate(f,false)
TkMessage.new(f, ‘text’=>‘1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000’).pack
Tk.mainloop

As you see when you run it,
the center part of the message widget is shown.
But if you want to show upper-left corner of the message widget,
probably you must use Place geometry manager.
For example,

require ‘tk’
f = TkFrame.new(nil, ‘width’=>100, ‘height’=>50).pack
TkMessage.new(f, ‘text’=>‘1111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990000000000’).place(‘x’=>0, ‘y’=>0)
Tk.mainloop

In this case, no need TkPack.propagate.
The message widget has no influence on the frame widget,
because the message widget is not known by Pack geometry manager.

                              Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)


~transami

“They that can give up essential liberty to obtain a little
temporary safety deserve neither liberty nor safety.”
– Benjamin Franklin


~transami

“They that can give up essential liberty to obtain a little
temporary safety deserve neither liberty nor safety.”
– Benjamin Franklin