Skip Menu |

This queue is for tickets about the Tk CPAN distribution.

Report information
The Basics
Id: 125718
Status: resolved
Priority: 0/
Queue: Tk

People
Owner: ctdean [...] aig.jpl.nasa.gov
Requestors: turnerjw784 [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 804.033
Fixed in: (no value)



Subject: Tk::DirTree
1) Please add a function (or document some other way) to fetch the directory (string) that is currently highlighted in Tk::DirTree. 2) Please add some useful (default) keyboard bindings, for example: [Return] - execute -browsecmd callback on the highlighted directory just as if user had clicked on it with the mouse. [Space] - expand or roll up the subdirectories for the highlighted directory just as if the user clicked the little [+]/[-] icon next to it. Since there is currently no keyboard binding for changing the directory with this widget, I was looking for a way to bind the [Return] key myself and call a function that fetches the highlighted directory and change to it myself, but I can't find a way to get it?! In the example image (attached) of my Tk file-manager, the DirTree widget has keyboard focus, and I want to be able to press [Return] and change to the directory "/home/turnerjw/audacious/" or hit the spacebar (or some other key) and expand to see the subdirectories! Thanks, Jim Turner
Subject: example.png
Download example.png
image/png 941.6k
example.png
RT-Send-CC: SREZIC [...] cpan.org, ctdean [...] aig.jpl.nasa.gov
(bumping) - Slaven, would you mind doing me a favor and take a look at this for me? Is there an existing workaround possible? I looked at it but could not find a way to do it - it appears to need a programming change in the lower-level C-code. Thanks, Jim On Fri Jun 29 19:39:37 2018, TURNERJW wrote: Show quoted text
> 1) Please add a function (or document some other way) to fetch the > directory (string) that is currently highlighted in Tk::DirTree. > > 2) Please add some useful (default) keyboard bindings, for example: > > [Return] - execute -browsecmd callback on the highlighted directory > just as if user had clicked on it with the mouse. > > [Space] - expand or roll up the subdirectories for the highlighted > directory just as if the user clicked the little [+]/[-] icon next to > it. > > Since there is currently no keyboard binding for changing the > directory with this widget, I was looking for a way to bind the > [Return] key myself and call a function that fetches the highlighted > directory and change to it myself, but I can't find a way to get it?! > > In the example image (attached) of my Tk file-manager, the DirTree > widget has keyboard focus, and I want to be able to press [Return] and > change to the directory "/home/turnerjw/audacious/" or hit the > spacebar (or some other key) and expand to see the subdirectories! > > Thanks, > > Jim Turner
RT-Send-CC: ctdean [...] aig.jpl.nasa.gov
On 2018-06-29 19:39:37, TURNERJW wrote: Show quoted text
> 1) Please add a function (or document some other way) to fetch the > directory (string) that is currently highlighted in Tk::DirTree.
The highlighted entry is called "anchor" in Tix. Tk::DirTree is-a Tk::Tree is-a Tk::HList. Tk::HList documents a method $w->info("anchor") which returns the entry name, in this case the file path. Show quoted text
> > 2) Please add some useful (default) keyboard bindings, for example: > > [Return] - execute -browsecmd callback on the highlighted directory > just as if user had clicked on it with the mouse.
Currently <Return> calls the -command callback (see KeyboardActivate in HList.pm), which is the same as if doing a double click. I think it is reasonable to have double click and <Return> behave the same. Show quoted text
> [Space] - expand or roll up the subdirectories for the highlighted > directory just as if the user clicked the little [+]/[-] icon next to > it.
This sounds reasonable. There's an -indicatorcmd callback which is called when the user clicks on +/- or hits <space>. Tk::Tree has the predefined method IndicatorCmd which does opening/closing of subtrees. But for some reason it does not work for keyboard events. Maybe $event has to be provided here? Show quoted text
> Since there is currently no keyboard binding for changing the > directory with this widget, I was looking for a way to bind the > [Return] key myself and call a function that fetches the highlighted > directory and change to it myself, but I can't find a way to get it?!
Binding can be somewhat tricky with Tk. I vaguely remember that class bindings have higher precedence than individual widget bindings in Perl/Tk (unlike Tcl/Tk). So what can you try is one of the following: * Create a subclass, and do the bindings on this subclass. * Use bindtags to reorder the precedence of bindings. For debugging Tk widgets you can also try my Tk::WidgetDump module. This may help on giving information what bindings are active, and other information. Regards, Slaven
RT-Send-CC: SREZIC [...] cpan.org
Thank you, Slaven, that was exactly what I was looking for! For the [Return] key (to select) I was able to do: -command => sub { $selectedPath = $_[$#_]; &myChDirFn($selectedPath); #Do something with it! }, For the [spacebar] (to expand/collapse): $dirtree->bind('<space>', sub { my $self = shift; $self->IndicatorCmd($self->info('anchor'), '<Arm>'); $self->IndicatorCmd($self->info('anchor'), '<Activate>'); }); This seems to work great for me in my file-manager, allowing me to ad the DirTree widget back to the tab-focusing order! I'm still not sure what the "Arm" and "Disarm" options do, but with just the "Activate" call without the "Arm" call, the UP and DOWN arrow-keys seemed to be traversing hidden (collapsed) subdirectories, but now that's no longer a pbm. I'll go ahead and close this ticket (but you might want to add some documentation for this capability in the next Tk release). Thanks again, Jim On Tue Feb 05 17:06:09 2019, SREZIC wrote: Show quoted text
> On 2018-06-29 19:39:37, TURNERJW wrote:
> > 1) Please add a function (or document some other way) to fetch the > > directory (string) that is currently highlighted in Tk::DirTree.
> > The highlighted entry is called "anchor" in Tix. > > Tk::DirTree is-a Tk::Tree is-a Tk::HList. > > Tk::HList documents a method $w->info("anchor") which returns the > entry name, in this case the file path. >
> > > > 2) Please add some useful (default) keyboard bindings, for example: > > > > [Return] - execute -browsecmd callback on the highlighted directory > > just as if user had clicked on it with the mouse.
> > Currently <Return> calls the -command callback (see KeyboardActivate > in HList.pm), which is the same as if doing a double click. I think it > is reasonable to have double click and <Return> behave the same. >
> > [Space] - expand or roll up the subdirectories for the highlighted > > directory just as if the user clicked the little [+]/[-] icon next to > > it.
> > This sounds reasonable. There's an -indicatorcmd callback which is > called when the user clicks on +/- or hits <space>. Tk::Tree has the > predefined method IndicatorCmd which does opening/closing of subtrees. > But for some reason it does not work for keyboard events. Maybe $event > has to be provided here? >
> > Since there is currently no keyboard binding for changing the > > directory with this widget, I was looking for a way to bind the > > [Return] key myself and call a function that fetches the highlighted > > directory and change to it myself, but I can't find a way to get it?!
> > Binding can be somewhat tricky with Tk. I vaguely remember that class > bindings have higher precedence than individual widget bindings in > Perl/Tk (unlike Tcl/Tk). So what can you try is one of the following: > * Create a subclass, and do the bindings on this subclass. > * Use bindtags to reorder the precedence of bindings. > > For debugging Tk widgets you can also try my Tk::WidgetDump module. > This may help on giving information what bindings are active, and > other information. > > Regards, > Slaven