Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
Your skill will accomplish
what the force of many cannot
 
PerlMonks

Perl/TK trees always start open

by lyle2000 (Initiate)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

on Nov 04, 2009 at 20:48 UTC ( #805053=perlquestion: print w/ replies, xml ) Need Help??
lyle2000 has asked for the wisdom of the Perl Monks concerning the following question:

I have written a perl script that uses the tree widget quite nicley. However I cannot get the tree to initially display with all the nodes closed. I have used the $tree->setmode($path, 'open') but to no avail. When I do this each node starts with the "+" sign but is still open. Is there a flag I am missing?

Comment on Perl/TK trees always start open
Re: Perl/TK trees always start open
by gmargo (Pilgrim) on Nov 04, 2009 at 22:24 UTC

    Can you provide some example code, please?

[reply]
      They system I am writting on is on a isolated network I will see what I can do get a sample over.
[reply]
Re: Perl/TK trees always start open
by llancet (Scribe) on Nov 05, 2009 at 01:56 UTC
    You have to manually write some code to recursively close all nodes. I've been not using Tk for some time, so I can only give you some pseudo-code:
    sub close_all { my $node = shift; foreach my $child ($node->method_to_get_its_children) { close_all($child); } $node->method_to_close_itself; }
[reply]
[d/l]
Re: Perl/TK trees always start open
by lamprecht (Monk) on Nov 05, 2009 at 08:07 UTC
    Hi,
    $tree->hide( entry => 'entry.path' ); $tree->autosetmode;

    should work.


    Cheers, Christoph
[reply]
[d/l]
Re: Perl/TK trees always start open
by zentara (Chancellor) on Nov 05, 2009 at 12:58 UTC
    i think all you need is $t->close('/') before the mainloop

    #!/usr/bin/perl use strict; use Tk; use Tk::Tree; my $mw = tkinit; my $t = $mw->Scrolled( 'Tree', -separator => '/', -scrollbars => 'osoe', )->pack; foreach (qw(/ /a /b /c /a/s /a/s/d /a/s/d/f /b/n /b/n/m)) { my @text = reverse split( /\//, $_ ); $t->add( $_, -text => @text[0] ); } $t->autosetmode; foreach ( $t->info( 'children', '/' ) ) { $t->close($_); } $mw->Button(-text=>'Close nodes', -command => sub{ closeTree($t, '/a') } )->pack(); $t->close('/'); MainLoop; sub closeTree { my $tree = shift; my ($entryPath, $hideChildren) = @_; my @children = $tree->info (children => $entryPath); return if ! @children; for (@children) { closeTree ($tree, $_, 1); $tree->hide ('entry' => $_) if $hideChildren; } $tree->setmode ($entryPath, 'open') if length $entryPath; }

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
[reply]
[d/l]

Back to Seekers of Perl Wisdom


Login:
Password
remember me
What's my password?
Create A New User

Node Status
node history
Node Type: perlquestion [id://805053]
Approved by ikegami
Front-paged by biohisham
help
Community Ads
Chatterbox
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users
Others rifling through the Monastery: (7)
CountZero
atcroft
herveus
Eyck
fauria
biohisham
gnosti
As of 2009-11-21 11:10 GMT
Sections
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth

Future historians will find that the material characteristic of the current era is...

Aluminium
Plastic
Oil
Water
Carbon dioxide
Copper
Iron
Silicon
Salt
Uranium
Hydrogen
Other

Results (730 votes), past polls