rgcosma has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

For the dialogues in Tk::Wizard, I'd want to replace the r/o textbox with e.g. a Tk::TextHighlight for which I can write my own syntax rules. I am not sure though if this can be sub-classed or requires going back to basic TK widgets. Just writing

use Tk::Wizard; use Tk::TextHighlight; my $wiz = new Tk::Wizard; $wiz->addPage ( sub { my $aa = q/return $self->parserError($txt); #for debugging/; $wiz->_text_frame( { -title => 'hmm', -boxedtext => \$aa, -syntax => 'Perl' } )->pack(-expand => 1, -fill => "both"); } );
surely doesn't work..

Update: two small changes in Tk/Wizard.pm i.e. require Tk::TextHighlight; and in sub _text_frame

my $t = $frame->Scrolled("TextHighlight" ... syntax => ( $args->{ -syn +tax } || 'Perl' )
and I have syntax coloring! Can't edit though, and not sure if this breaks something else. Same happens with Tx::CodeText

Replies are listed 'Best First'.
Re: editable text + syntax for addTextFramePage
by Khen1950fx (Canon) on Apr 21, 2011 at 01:00 UTC
    Your snippet didn't do anything, so I spruced it up a bit. I'll let you work out the highlighting aspects.
    #!/usr/bin/perl use strict; use warnings; use Tk; use Tk::Wizard; use Tk::TextHighlight; my $mw = new MainWindow; our $wiz; $wiz = $mw->Wizard( -debug => 1, -title => 'Wizard', -style => 'top', -tag_text => 'Wizard', ); $wiz->addPage ( sub { $wiz->_text_frame( -title => 'Highlight', -syntax => 'Perl', -text => "Setup Guide", ); } ); $mw->Label( -text => "MainWindow" )->pack; my $button = $mw->Button( -text => "Start Wizard", -command => sub { $wiz->Show(); } )->pack(); $mw->Button( -text => 'Quit', -command => sub { exit; } )->pack; MainLoop; __END__
Re: editable text + syntax for addTextFramePage
by Anonymous Monk on Apr 21, 2011 at 01:01 UTC
    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 :)
      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 } );