bug in Tk::Tree ? 
Author Message
 bug in Tk::Tree ?

Hello All,

        Ive been working with the Tk::Tree class and I think there is a bug in
the keyboard handling - just wondering if anyone else has come across
this / has a fix for it. Since I would like to get it working.

        It occurs when you are moving the cursor up/down with the arrow keys
over the tree. Most of the time it works and moves to the next visible
node, sometimes the cursor disappears.

        It happens when you are on a contracted node (one with a "+" next to
it) which contains sub nodes which themselves are expanded (but not
visible since their parent is contracted). If you then press the down
key, the cursor will "disappear" and then re-appear again later after
more key presses.

        I think what is happening is that Tk::Tree is traversing the contained
expanded nodes but should not be since they aren't visible.

        You can see what I mean by running the included code and doing the
following:

1. Contract the node labelled "top level item 1".
2. Select the first node with the keyboard then press the down arrow
key. The cursor will disappear.
3. Keep hitting the down array key and the cursor will eventually
re-appear on "top level item 2".

-- 8< --

#!/usr/bin/perl -w

use Tk;
use Tk::Tree;

my $mw = MainWindow->new();

my $tree = $mw->Tree()->pack();

$tree->add('1', -text => "top level item 1");
$tree->add('1.1', -text => "medium level 1");
$tree->add('1.1.1', -text => "low level 1");
$tree->add('1.1.2', -text => "low level 2");
$tree->add('1.1.3', -text => "low level 3");
$tree->add('2', -text => "top level item 2");

$tree->setmode('1', 'close');
$tree->setmode('1.1', 'close');
$tree->setmode('2', 'close');

MainLoop;

-- 8< --

bye
Andrew



Sat, 24 Apr 2004 12:17:50 GMT  
 bug in Tk::Tree ?
Thanks for the test case.

The code for this is in HList.pm - the UpDown subroutine.

The sub _does_ check to see if an element is
hidden or not, but does not check if any of it's
parent/s are hidden.

So when you level the 3rd level list open, but close
the 2nd level, when the entries are checked to see
if they are hidden, they are not - or at least their
state doesn't reflect it, so they don't get skipped
as they should. It is their parent which is hidden.

That's why it takes 3 presses to get to the next
element.

One possible fix:

add another method to HList that checks to
see if any of an elements parents are hidden.
Something like this perhaps:

sub _parentHidden {

    my $hidden = 0;
    my $parent = $w->infoParent($ent);  

    while ($hidden == 0 && $parent ne "") {
        $hidden = 1 if $w->infoHidden($parent);
        $parent = $w->infoParent($parent);
    }
    return $hidden;

Quote:
}

and in the HList UpDown subroutine, after
the line where the entry is checked to see if
it is hidden or not, add a check to see if the
parent's are hidden. Like I did below.

 while(!$done)
  {
   $ent = $w->info($spec, $ent);
   last unless( defined $ent );
   next if( $w->entrycget($ent, '-state') eq 'disabled' );
   next if( $w->info('hidden', $ent) );
   next if( $w->_parentHidden($ent) );
   last;
  }

This fixes it for me, and I'm sure if I gave it
more than a few minutes thought I'd could
make it cleaner than that, but it's a start.

Rob



Sat, 24 Apr 2004 14:46:02 GMT  
 bug in Tk::Tree ?
Let me try again:

What I meant to say, is when the 3rd level elements
are not hidden, but are not visible because their
parent (or parent's parent) is hidden, they don't get
skipped because strictly speaking, their state is
_not_ hidden - Their parent is. This is necessary,
because once the parent is made visible, then the
other elements still reflect their open/visible state.

So the good news  is that during the UpDown routine,
the next or previous non-hidden/non-disabled element
_is_ being looked for, but the bad news is that because
the parents of an entry are not checked then sometimes
the next "visible" entry is hidden by it's parent.

Close _all_ levels and try it. It will work fine.

Rob

Quote:
>So when you level the 3rd level list open, but close
>the 2nd level, when the entries are checked to see
>if they are hidden, they are not - or at least their
>state doesn't reflect it, so they don't get skipped
>as they should. It is their parent which is hidden.



Sat, 24 Apr 2004 15:03:48 GMT  
 bug in Tk::Tree ?
After closer examination of my "solution" I've found that it's flawed because I
was counting on infoParent returning an empty string ("") when the entry was a
top level entry.

It seems like thats not the case... so with in mind,
here's corrections to the sub to prevent it from causing
problems.

sub _parentHidden {

    my $hidden = 0;
    my $parent = $w->infoParent($ent) || "";
    while ($hidden == 0 && $parent ne "") {
        $hidden = 1 if $w->infoHidden($parent);
        $parent = $w->infoParent($parent) || "";
    }
    return $hidden;

Quote:
}

Here's to hoping that at least some of these late
night ramblings made sense to someone out there...

Rob



Sat, 24 Apr 2004 15:37:19 GMT  
 bug in Tk::Tree ?
thanks for that - i was wondering whether I needed to modify the
HList/Tree source code, looks like that is the best bet after all.

now all i need to do is figure out how to get the changes to
be put in the next release of perl/tk :)

bye
Andrew

Quote:
> top level entry.

> It seems like thats not the case... so with in mind,
> here's corrections to the sub to prevent it from causing
> problems.

> sub _parentHidden {

>     my $hidden = 0;
>     my $parent = $w->infoParent($ent) || "";
>     while ($hidden == 0 && $parent ne "") {
>         $hidden = 1 if $w->infoHidden($parent);
>         $parent = $w->infoParent($parent) || "";
>     }
>     return $hidden;
> }

> Here's to hoping that at least some of these late
> night ramblings made sense to someone out there...

> Rob



Sun, 25 Apr 2004 06:31:43 GMT  
 bug in Tk::Tree ?
You could always derive your own class from Tree, and just write your own
UpDown method and any other fixes you desire. This would give you a temporary
work around
for now.

Rob



Sun, 25 Apr 2004 07:25:59 GMT  
 bug in Tk::Tree ?
Thanks, I actually did that for other reasons so now I might see how I
go overriding the keyboard control.

bye
Andrew

Quote:
> You could always derive your own class from Tree, and just write your own
> UpDown method and any other fixes you desire. This would give you a temporary
> work around
> for now.

> Rob



Mon, 26 Apr 2004 06:30:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Is there a Tree widget in perlTk that resembles the Tree widget in Tk

2. deleting items in Tk::Tree / Tk::HList

3. Tk::Tree / Tk::HList - prune and graft at runtime

4. Tk::Tree changing Tk::Text

5. Bug: Menu popup on NT (Was: Tk::Pod bug)

6. Two bugs in HTML-Tree modules?

7. HTML-Tree bug

8. Bug in HTML::Parser or HTML::Tree

9. Bug in Tree widget

10. Bug in Tree widget?

11. Bug using Tk::Adjuster with Tk::LabFrame

12. Bug in Tk::Text or Tk::Image

 

 
Powered by phpBB® Forum Software