in reply to Re: Tk::HList selectionClear background problem
in thread Tk::HList selectionClear background problem

Thanks for the reply. Unfortunately, the problem is not the ItemStyle definition. As you can see in my code, I use the Options Database to set the background and foreground colors and I pass the selectbackground settings directly to the Tk::Tree at the time of creation. That's why even after explicitly defining the ItemStyle for my tree items, the behavior is still the same :-/.

my $style = $tree->ItemStyle( 'imagetext', -foreground => 'black', -background => 'white', -selectforeground =>'white', ); for my $top ( 1 .. 3) { $tree->add( $top, -text => $top ); for ( 'A' .. 'C') { my $q = $tree->add( "$top.$_", -text => "$_" ); $tree->entryconfigure("$top.$_", -style => $style); } }

Replies are listed 'Best First'.
Re^3: Tk::HList selectionClear background problem
by zentara (Cardinal) on Dec 28, 2006 at 18:13 UTC
    It gets to be a real juggling act when you try to finesse the colors in these lists. You always run into a situation where one setting interferes with another. You just need to experiment. Try this:
    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Tree; use Tk::ItemStyle; my $fgcolor = "#000000"; # foreground color my $bgcolor = "#FFFFFF"; # background color my $text_font = 'helvetica 12'; # Body text font my $mw = MainWindow->new(); $mw->optionAdd("*background", $bgcolor); $mw->optionAdd("*foreground", $fgcolor); $mw->optionAdd("*rotext*font", $text_font); $mw->optionAdd("*tree*font", $text_font); $mw->optionAdd("*entry*font", $text_font); my $tree; $tree = $mw->Scrolled('Tree', -font=>$text_font, -scrollbars=>'ose', -selectmode=>'extended', -selectbackground=>'white', -highlightcolor=>'white', -highlightthickness => 0, -drawbranch=>0, -browsecmd=>sub { foreach ($tree->selectionGet) { if (/\./) { # do not allow selection of top level i +tems $tree->configure(-selectbackground => 'blue') }else{ # $tree->selectionClear($_); $tree->configure(-selectbackground => 'white') } } $tree->anchorClear() } )->pack(-side=>'top', -fill=>'both', -expand=>1); $tree->columnWidth(0, -char, 90); #get full row color # create style for different colors my $S1 = $tree->ItemStyle( 'imagetext', -foreground => 'black', -background => 'white', -selectforeground =>'black', -selectbackground =>'white', ); my $S2 = $tree->ItemStyle( 'imagetext', -foreground => 'black', -background => 'white', -selectforeground =>'yellow', -selectbackground =>'blue', ); for my $top ( 1 .. 3) { $tree->add( $top, -text => $top, -style=> $S1 ); for ( 'A' .. 'C') { $tree->add( "$top.$_", -text => "$_", -style=> $S2 ); } } MainLoop();

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum
      Again, thank you for the reply. You have an interesting idea. The only problem with what you are suggesting is that it will not work the way I want for the 'extended' mode of selection. In other words, try to select a number and a letter at the same time (hold CTRL down to do that) and you will see that the selectbackground for the entire tree is adjusted based on the bottom-most selected item. Expressed a different way, select 1.A and 2 and both selectbackgrounds will be white, or select 1 and 1.B and both selectbackgrounds will be blue. I am starting to get the impression that what I am trying to is impossible in Tk::HList ...
        I am starting to get the impression that what I am trying to is impossible in Tk::HList

        Yeah, all the list widgets are "convenience widgets", they are not designed for general flexibility. You probably would find the Tk::Canvas will do what you want, and you can make your own custom widget, which is based on a Canvas. See Tk::CanvasDirTree for an example of subclassing a canvas to a custom widget.

        However, one of the list experts may come along and find a hack for you.... it takes alot of experimenting with the browsecmd, etc..... and it may be impossible as you say.


        I'm not really a human, but I play one on earth. Cogito ergo sum a bum