Please help: Binding mouse click to tree entry. 
Author Message
 Please help: Binding mouse click to tree entry.
Hello all,

  Can I possibly have a popup menu be dependent on the type of entry I choose?
As the attached script is now, my menu pops up wherever I click in the tree widget.
I need to automatically select the entry right-clicked on and distinguish between a
directory and a file so I can modify the options available in the menu.

I hope this kinda-sorta makes sense. ;-)

P.S. Feel free to offer pointers on better coding.

TIA,
Les

-------------------------  CUT  ---------------------------------------------
use Tk;
use Tk::Menu;
use Tk::Tree;

my $root = MainWindow->new();
$root->title("Menu Test");

$root->geometry ('150x225');
my $tree_1 = $root->Tree(
   -columns    => '1',
   -itemtype   => 'text',
   -separator  => '/',
   -selectmode => 'browse',
)->pack(-fill => 'both', -expand => '1');



   my $text = $_;
   my $mode = "close";
   $text =~ /([a-zA-Z0-9]{1,})$/;
   $text = $1;
   if (/file/) {
      $mode  = 'none';
   }
   $tree_1->add($_, -text=>$text);
   $tree_1->setmode( $_, $mode );

Quote:
}

my $menu = $root->Menu(
   -tearoff   => '0',
   -menuitems => [[Button => 'Option 1', -command => sub { print "Option one.\n"; }],
                  [Button => 'Option 2', -command => sub { print "Option two.\n";}],
                 ]
);

$tree_1->bind('<Button-3>',
               sub {
                  $menu->Popup(
                     -popover   => 'cursor',
                     -popanchor => 'nw'
                  );
                  $menu->grabRelease; # Return control to the main window.
               }
);

Tk::MainLoop;
1;

-------------------------  DON'T CUT ---------------------------------------------
==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the




Tue, 04 Sep 2001 03:00:00 GMT  
 Please help: Binding mouse click to tree entry.

Quote:

> Hello all,

>   Can I possibly have a popup menu be dependent on the type of entry I choose?
> As the attached script is now, my menu pops up wherever I click in the tree widget.
> I need to automatically select the entry right-clicked on and distinguish between a
> directory and a file so I can modify the options available in the menu.

> I hope this kinda-sorta makes sense. ;-)

Yes, but it needs a little work. Here are some keywords: bind
ButtonPress-3 to a subroutine, which determines via XEvent and
$tree->nearest($y) the underlying entry path. Then Popup() the menu.

Regards,
        Slaven

--
use Tk;$c=tkinit->Canvas->pack;$x=45;for(split/_/,'KPI1_+09IPK_K;-OA1_+K!;A__1;
Q!7G_1+QK_3CLPI90,_+K!;A_+1!KQ!.N_K+1Q!.F_1+KN.Q__1+KN._K+1Q!.F_1+KN.Q_+1Q__+1!
KQ!.N_1;Q!7G_K3,09Q_+1!K.Q_K+1Q!.F_1+KN.Q'){s/\n//g;for(split/!/){$c->create(
'line',map{$a=-43+ord;($x+($a>>3)*2,123+($a&7)*2)}split//)}$x+=12}MainLoop

==========================================================================
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the



Wed, 05 Sep 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Mouse Click Bind for an Entry Widget

2. binding mouse clicks to Tk::Columns

3. binding right mouse button click to all buttons

4. Binding right mouse button for Tk::Tree items

5. help binding mouse events to canvas

6. simulating a mouse click?

7. Sending keystrokes and mouse click under WinPerl

8. anyone know how to simulate a mouse click?

9. Mouse click location on a scrolled canvas

10. Simulating mouse clicks on other GUI programs

11. left mouse click on HList throws messages when empty

12. A weird one - misguided mouse clicks and all that

 

 
Powered by phpBB® Forum Software