Thread Überlangen Text darstellen (8 answers)
Opened by TheBigfoot at 2007-11-12 09:35

Spieler
 2007-11-12 15:34
#102261 #102261
User since
2007-09-24
70 Artikel
BenutzerIn
[default_avatar]
Hallo,

was -textvariable betrifft, das kannst du mit einer Tie Klasse machen.

Ich glaube sogar, so etwas gibt es auf CPAN, ich weiss aber nicht, wie es heisst.

Grüße, Christoph

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package TiedText;
use warnings;
use strict;
require Tk;
require Tk::Text;
require Tk::Frame;

our @ISA= qw(Tk::Frame);
Tk::Widget->Construct("TiedText");

sub Populate{
my ($self,$args)=@_;
if (exists ($args->{-variable})){
$self->{inst_data}{tt_variable}=delete($args->{-variable})
}
$self->SUPER::Populate($args);
my $tw = $self->Text()->pack();
$tw ->insert('1.0',${$self->{inst_data}{tt_variable}});
$self->{inst_data}{text_widget}= $tw;
tie ${$self->{inst_data}{tt_variable}} , 'TiedText' , $self;
$self->Delegates(DEFAULT=>$tw);
$self->ConfigSpecs(DEFAULT=>[$tw]);
}


sub TIESCALAR{
my($class,$self)=@_;
return $self;
}

sub FETCH{
my $self = shift;
my $text = $self->{inst_data}{text_widget}->get('0.0','end - 1 chars');
return $text;
}

sub STORE{
my ($self,$value) = @_;
$self->{inst_data}{text_widget}->delete('1.0','end');
$self->{inst_data}{text_widget}->insert('1.0',$value);
}




package main;
use Tk;
my $mw = tkinit;
my $text = 'a teststring ';
my $t = $mw->Scrolled('TiedText',
-wrap => 'word',
-scrollbars => 'oe',
-variable => \$text)->pack;
$mw -> Button (-text => 'print',
-command => sub {print "$text\n"},
)->pack;
$mw -> Button (-text => 'modify',
-command => sub {$text .= $text},
)->pack;

MainLoop();

View full thread Überlangen Text darstellen