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

I am trying to set the truncate option to path for a label in my gui. As far as I can tell my code is correct but it is still truncating at the end rather than before the last \ as it should. Any help is greatly appreciated.
$Taskname_label = $Maintab->AddLabel( -text => $taskpath, -left => 75, -top => 45, -width => $Maintab->ScaleWidth - 100, -name => "Tasknamelabel", -truncate => 'path', -font => $font1, );

Replies are listed 'Best First'.
Re: Win32::GUI Addlabel truncate problem
by bsdz (Friar) on Sep 11, 2004 at 13:37 UTC
    The truncate parameter only works when the label rectangle is too small for it's containing text. This is easily demonstrated in Win32::GUI::XMLBuilder: -
    <GUI> <Window name='W1' dim='100, 100, 200, 80' title='truncate test' > <Label text='c:\some\path\notreal.txt' dim='20, $self->{W1}->Height-70, 70, 20' truncate="path" /> </Window> </GUI>
    Using a -truncate of 'path' preserves as much as possible of the text after the last backslash. As an alternative solution you might use the File::Basename module: -
    use File::Basename; use strict; use warnings; print dirname('c:\some\path\notreal.txt');