in reply to editable text + syntax for addTextFramePage

Update: two small changes in Tk/Wizard.pm i.e. require Tk::TextHighlight; and in sub _text_frame .... and I have syntax coloring!

That's not nice :) you're not supposed to edit modules directly. You're supposed to copy _text_frame and change it to suit your needs, one way

$wizard->addPage( sub { MyTextFrame( $wiz ); } ); ... sub MyTextFrame { package Tk::Wizard; ## for DEBUG/WARN/Dumper... my $self = shift; my $args = shift; DEBUG "Enter _text_frame with ", Dumper($args); my $text; my $frame = $self->blank_frame(%$args); if ( $args->{-boxedtext} ) { if ( ref $args->{-boxedtext} eq 'SCALAR' ) { $text = $args->{-boxedtext}; } elsif ( not ref $args->{-boxedtext} ) { open my $in, $args->{-boxedtext} or Carp::croak "Could not read file: $args->{-boxedtex +t}; $!"; read $in, $$text, -s $in; close $in; WARN "Boxedtext file $args->{-boxedtext} is empty." if not + length $text; } } $$text = "" if not defined $text; my $t = $frame->Scrolled( "TextHighlight", -syntax => ( $args->{ -syntax } || 'Perl' ), -background => ( $args->{ -background } || 'white' ), -relief => "sunken", -borderwidth => "1", -font => $self->{defaultFont}, -scrollbars => "osoe", -wrap => "word", )->pack(qw/-expand 1 -fill both -padx 10 -pady 10/); $t->configure( -background => 'green' ) if DEBUG_FRAME; $t->insert( '0.0', $$text ); ## $t->configure( -state => "disabled" ); return $frame; }
the other way is monkeypatching (declaring a subroutine in someone elses package)
$wizard->addPage( sub { $wiz->MyTextFrame; } ); sub Tk::Wizard::MyTextFrame { ...

Can't edit though, and not sure if this breaks something else. Same happens with Tx::CodeText

When a widget is diabled, its disabled :) Remove

$t->configure( -state => "disabled" );
This disabled bit from sub _text_frame looks like a bug in Tk::Wizard, it doesn't make sense to disable ROText, its already read-only :)

Replies are listed 'Best First'.
Re^2: editable text + syntax for addTextFramePage
by rgcosma (Beadle) on May 05, 2011 at 08:17 UTC
    Thank you for the "monkey patching" hint, used it and the solution to make text editable is quite simple:
    use Tk::TextUndo; use Tie::Tk::Text; sub Tk::Wizard::_my_text_frame { #... my $t = $frame->Scrolled( "TextUndo", )->pack; if ( $args->{-variable} ) { tie @{$args->{-variable}}, 'Tie::Tk::Text', $t; } #... }
    which can be called as
    $wiz->_my_text_frame( { -title => 'editable text', -boxedtext => \$originaltext, -variable => \@editedtext } );