Tied variable to write in a text widget. 
Author Message
 Tied variable to write in a text widget.

Hi to everyone,

I have almost finished to write my first perl/tk program with a lot of
specialized packages. Until now, each of them was displaying his
messages
to STDOUT.

Now, I intend to display the messages in a separated central message
window who
only contains a text widget. This window is created at start time by the
main
module.The widget reference is then passed, as needed, to each package
in order
to let him display his messages in the message window.

To reduce the modifications and to reuse the code, I though to tie a
scalar
variable to a package (see code below) who simply receives, at tying
time,
the text widget reference and then, as the variable is assigned, insert
the
text to the end of the message widget.

The tying seems to work but the text insertion makes the application
vanishs
without no error message.

I have always been able to find some example either in the FAQ, the
books or
the newsgroups (here and Dejanews) but none this time. I have already
write
packages to tie variables with but, this time, I am confused. So, I
request
your help.

Is it possible to tie a variable to a widget reference as I intend to
do?
I see no reason why not. What am I doing wrong?

Any help will be greatly appreciated. Thanks in advance.

I am working with perl 5.003 and tk 400,202 on a sparcserver with
solaris 2.5.

Thanks again.

Here is the package code. I have commented it out to reduce space.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
package Afficher;

require 5.003;

use strict;
use Carp;
use Tk;
require '/home/langlois/SGEL/LSGEL__Param.cfg';

sub TIESCALAR {
   my $class  = shift;
   my $fen    = shift || undef;    ### THIS is the reference to message
widget

   defined $fen or die "[ECRAN] :: Fentre d'affichage inconnue : $!\n";

   bless {TEXTE => '', FEN => $fen}, $class;

Quote:
} # end TIESCALAR

sub FETCH {
   my $self = shift;
   return $self->{TEXTE};

Quote:
} # end FETCH

sub STORE {
   my $self  = shift;
   my $texte = shift;
   my $fen;

   $self->{TEXTE} = $texte;
   $fen = $self->{FEN};
   $fen->insert ('end', "$texte");    ### THIS seems to be the faulty
line
   $fen->see    ('end');

Quote:
} # end STORE

sub DESTROY {} # end DESTROY

1;

--
Dominic Langlois                  
Centre d'information topographique / Centre for Topographic Information



Fri, 07 Apr 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Tied text widget contents

2. FileHandle tied to Text Widget

3. tied variables in Label and Button widgets ?

4. BETA TEST: Tk::Tie::MenuHash - Ties a Tk::Menubutton widget to a hash, kinda

5. BETA TEST: Tk::Tie::MenuHash - Ties a Tk::Menubutton widget to a hash, kinda

6. Writing content of a text widget

7. Writing to the same text widget from two modules

8. Q: Changing Text-Color in Text-Widget?

9. text formatting in a Text widget

10. How update text in text widget when executing some other callback

11. Color Coding Text in a Tk::Text Widget

12. Checking for marked or selected text in a Text widget

 

 
Powered by phpBB® Forum Software