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

Hello, monks!

Two pieces of code.
Based on Tk::Text widget:
$match_box_wdg = $re_edit_frame_wdg->SearchEntry( -width => 70, -height => 1, -font => "$text_font $text_size", -bg => "#ffffff", )->grid( -sticky => 'w', -row => 1, -column => 0, -padx => 5, -pady => 1, );
And the same but scrolled:
$match_box_wdg = $re_edit_frame_wdg->Scrolled( 'SearchEntry', #custom widget -scrollbars => '', -width => 70, -height => 1, -font => "$text_font $text_size", -bg => "#ffffff", )->grid( -sticky => 'w', -row => 1, -column => 0, -padx => 5, -pady => 1, )->Subwidget('scrolled');
Both are fine. Look and behave quite the same, except.. Except for one thing that drives me crazy. If somewhere I do $match_box_wdg->configure('height => 10'); it works properly for the first case, but doesn't change the appearence for the second one!
Though it changes value of -height actually. print $match_box_wdg->cget('height') shows 10. Both for Scrolled and Subwidget. But still the appearence isn't changed. It still looks like -height == 1.
As for other options, -state works properly in both cases. But -bg or -width behave the same wierd way as -height.

I have ActivePerl 5.8.7.815 on my WinXP SP4 box.

UPDATED:
You may get the whole project from SourceForge:

cvs -z3 -d:pserver:anonymous@refine.cvs.sourceforge.net:/cvsroot/refine co -P refine

The disputable code is located in refine.pl and marked with XXX.

Thanks in advance,
Artem.

Replies are listed 'Best First'.
Re: Perl/Tk Scrolled issue
by graff (Chancellor) on Aug 19, 2006 at 17:33 UTC
    Just guessing here, but maybe the "Scrolled" container object is the one that needs to get the config update, rather than its "scrolled subwidget" (your "SearchEntry" thing that actually ends up with the updated properties).

    I haven't had a lot of practice with this, but IIRC, actions that are invoked on the container object will propagate down to the scrolled subwidgit when appropriate. At worst, you might end up with two separate widget handles to manage: one for the container and one for the subwidget.

    Another guess: have you tried calling the 'update' method on the subwidget and/or the container after a config change?

      Calling update doesn't help. I've tried.
      As for propogation.
      As I mentioned, -height property is changed both for SearchEntry and for Scrolled container.
      The problem is that it dosn't change the appearence as it should.
      Artem.
Re: Perl/Tk Scrolled issue
by jdtoronto (Prior) on Aug 20, 2006 at 01:27 UTC
    Not all widgets can be scrolled, and Tk::SearchEntry certainly is not a widget I have come across, neither is it on CPAN. Is it a mega-widget of your own creation? If so it might help us to see its code.

    jdtoronto

      This one is certainly Scrolled. It appeares as Scrolled. No problems.
      Here is the code:
      use base qw/Tk::Derived Tk::TextUndo/; Construct Tk::Widget 'SearchEntry'; sub ClassInit { my($class, $mw) = @_; $class->SUPER::ClassInit($mw); $mw->bind($class, '<Control-a>', 'selectAll'); $mw->bind($class, '<Key-Tab>', sub { $_[0]->focusNext; Tk->break; +}); } sub Populate { my($self, $args) = @_; $self->menu(undef); }
      Artem.

        I can't reproduce the problem with the colors, but I can for height/width. It isn't so much a problem as a misunderstanding of the Scrolled composite.

        When you use it you are delegating responsibility for displaying the 'scrolled' subwidget to the Scrolled composite. Scrolled allows you to initialize the settings (height/width) of the enclosed subwidget up until all events have been processed by MainLoop the first time.

        So the following will work:

        Updated: caught and corrected a typo in the first example. Added the qw to the configure method params.

        use Tk; use Tk::SearchEntry; my $main = MainWindow->new; $w = $main->Scrolled( 'SearchEntry', #custom widget -scrollbars => '', -width => 70, -height => 1, -bg => "#ffffff", )->grid( -sticky => 'w', -row => 1, -column => 0, -padx => 5, -pady => 1, ); $w->configure(qw/-height 10 -bg blue -fg white/); MainLoop;
        But the next, will not:
        use Tk; use Tk::SearchEntry; my $main = MainWindow->new; $w = $main->Scrolled( 'SearchEntry', #custom widget -scrollbars => '', -width => 70, -height => 1, -bg => "#ffffff", )->grid( -sticky => 'w', -row => 1, -column => 0, -padx => 5, -pady => 1, ); $main->Button( -text => "Change", -command => sub { $w->configure(-width => 10, -height => 10); })->grid; MainLoop;

        This is because by the time the Button has been pressed, sizing control has been yielded to Scrolled. You can take it back using the packPropagate method. Notice how the first Change button makes the change, but then when the second Change button tries, it cannot. The size is being passed, it's just not having any visible effect.

        use Tk; use Tk::SearchEntry; my $main = MainWindow->new; $w = $main->Scrolled( 'SearchEntry', #custom widget -scrollbars => '', -width => 70, -height => 1, -bg => "#ffffff", )->grid( -sticky => 'w', -row => 1, -column => 0, -padx => 5, -pady => 1, ); $main->Button( -text => "Change", -command => sub { ## allow subwidget to exert control over the size $w->packPropagate(1); $w->configure(-width => 10, -height => 10); ## This line resets it back, but only after ## the change has taken place. You don't *have* ## to reset packPropagate to 0, but be aware that ## it will reset itself, each time the widget is ## mapped. $w->afterIdle([$w, 'packPropagate', 0]); })->grid; $main->Button( -text => "Change2", -command => sub { $w->configure(-width => 30, -height => 2); })->grid; MainLoop;

        Another way I have dealt with this in the past is to enclose the Scrolled widget within another Frame, but set it up to expand/shrink as the parent frame resizes. Then I size the Frame instead of the Scrolled widget.

        HTH,

        Rob
      agreed with jdtoronto
      my computer can't locate Tk::SearchEntry on
      either:
      perl v5.6.1 built for MSWin32-x86(Active Perl)
      ->Tk804.027
      or
      perl v5.8.7 built for cygwin
      ->Tk800.024
        That's my custom widget.
        See the code above in the thread.
        Artem.
Re: Perl/Tk Scrolled issue
by aquarium (Curate) on Aug 19, 2006 at 16:37 UTC
    afaik...tk widgets need to be re-packed if you configure.
    the hardest line to type correctly is: stty erase ^H
      Hm.. Well, if I use just Tk::Text rather than Scrolled, no remap is needed. The widget is redrawn as soon as you call configure.
      You do not need to repack widgets following a configure.