Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Tk tree open problem

by simonz (Sexton)
on Mar 12, 2014 at 14:27 UTC ( #1078032=perlquestion: print w/ replies, xml ) Need Help??
simonz has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I am working with a TK tree with some 500 nodes and some 2-3 children hanging from each node. The problem is if I use 'open' function to bring all the collapsed nodes to expand mode by the following code, the it takes lot of time to expand for 500 nodes.
Is there any other mechanism to expand them all in one go without having to iterate on each of them.

map { $tree()->open($_) } @EntryPaths;

Where the @EntryPaths is contaning 0.0.1, 0.0.2, 0.0.3 so on upto 500.0.1, 500.0.2 like this .

Comment on Tk tree open problem
Download Code
Re: Tk tree open problem
by kcott (Abbot) on Mar 12, 2014 at 22:15 UTC

    G'day simonz,

    Changing

    map { $tree()->open($_) } @EntryPaths;

    to

    $tree->open($_) for @EntryPaths;

    will probably get some speed improvements. I can't say how much or whether it would be noticeable.

    Do you have similar code for setmode()? Changing map to for here would proably also help; using autosetmode() might help even more.

    If you can provide an example of your code with a small number of nodes, we'll have a better idea of what's happening and how it might be improved. Please exclude all code that not's directly related to the issue at hand (e.g. colours, fonts, widget decorations, callbacks for unrelated functions, and so on): these are just noise, from a troubleshooting perspective, and don't help in drilling down to the heart of the issue.

    -- Ken

      Hi Ken
      Thanks for the reply, I am working on if I can give a small example of my code to make you understand better about the problem.
      Meanwhile , just need one more help on the following error :
      ## parent element "0.0" does not exist at /usr/lib/perl/Tk.pm line 250 ###
      The background is , I am creating a tree structure of different kinds and combinations in terms of root node and their children. Basically everytime the tree is having different branches and nodes in it. This above error is coming for a particular combination.
      Since the tree is very big, right now I cannot give you an example and unable to find where is the goof up happening.
      If you just tell me which direction I should think or what should I look for to get rid of this error would be very helpful.
      Thanks.

        "Meanwhile , just need one more help on the following error :
        ## parent element "0.0" does not exist at /usr/lib/perl/Tk.pm line 250 ###"

        Without seeing your code, I can't help you with that. You'll need to look in /usr/lib/perl/Tk.pm and see what's happening at line 250. Then try to work out how your code is calling that line.

        In the current version (804.032) of Tk, the source (http://cpansearch.perl.org/src/SREZIC/Tk-804.032/Tk.pm) shows line 250 as a simple assignment (my $name = $meth;): I don't see how that would generate an error about a "parent element". You probably have a different version.

        -- Ken

Re: Tk tree open problem
by zentara (Archbishop) on Mar 13, 2014 at 09:45 UTC
    Hi, one of the drawbacks of some Tk widgets, is that they can get bogged down when you add alot of elements to the widgets. Have you seen the code in a Tree that can fold and unfold.

    If you want to delve a bit deeper into a Tk::Canvas based solution, which handles many changing items without problem, see Tk::CanvasDirTree. It is an educational module I wrote to simulate Gtk2's beautiful Treeview widget. The example I give is for just giving a directory tree, but you could easily modify it to display whatever data structure you wanted. It has a little rotating triangle which is clickable to expand and collapse nodes. The Canvas can handle many items simultaneously, if you do the code properly.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1078032]
Approved by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-09-18 10:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (110 votes), past polls