Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Right Click Menu Invocation

by socrtwo (Sexton)
on May 01, 2009 at 13:10 UTC ( [id://761277]=perlquestion: print w/replies, xml ) Need Help??

socrtwo has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm using H. Merijn Brand's Notebook and Excel file script ss2tk, to display Excel worksheets. Ss2tk is part of the Spreadsheet::Read package. My version of the script has a working button which allows the saving of all the worksheets as CSV files. My question is how do I write some Perl/Tk code which allows the saving of the current tab in the Notebook via a right click menu, to a CSV file only, not all the worksheets? So in the subroutine called by right clicking on the choice, I need to pass the identity of the current tab displayed worksheet.

Replies are listed 'Best First'.
Re: Right Click Menu Invocation
by zentara (Archbishop) on May 01, 2009 at 16:09 UTC
    I need to pass the identity of the current tab displayed worksheet

    There are a couple of ways, one is to use the raisecmd callback, to set the current page. This will make a callback for the current page, with a right-click release.

    #!/usr/bin/perl use warnings; use strict; use Tk; use Tk::NoteBook; my $current = 0; my $mw=MainWindow->new(-title=>'Notebook tab colors demo'); my $XIMG = <<'EOF'; /* XPM */ static char * x_xpm[] = { "12 12 3 1", " c None", ". c #FF6060", "+ c #8F6060", " . . ", " .+. .+. ", ".+++. .+++. ", "+.+++.+++.+ ", " +.+++++.+ ", " +.+++.+ ", " .+++++. ", " .+++.+++. ", ".+++.+.+++. ", "+.+.+ +.+.+ ", " +.+ +.+ ", " + + "}; EOF my $RED = $mw->Pixmap(-data => $XIMG ); my $BXIMG = $XIMG; $BXIMG =~ s/#FF6060/#6060FF/; $BXIMG =~ s/#8F6060/#60608F/; my $BLUE = $mw->Pixmap(-data => $BXIMG ); my $GXIMG = $XIMG; $GXIMG =~ s/#FF6060/#60FF60/; $GXIMG =~ s/#8F6060/#60FF60/; my $GREEN = $mw->Pixmap(-data => $GXIMG ); my $nb = $mw->NoteBook( -background=> 'white', -inactivebackground => 'black', )->pack(); $nb->bind('<ButtonRelease-3>', sub{ print "$current is being saved\n"; }); my @colors = ($RED,$BLUE,$GREEN); for my $tab (qw/page1 page2 page3 page4 page5 page6/){ my $frame = $nb->add($tab, -raisecmd => sub{ print "@_\n"; print $tab,"\n"; $current = $tab; print "$current is current\n"; }, -image=> $colors[0], ); $frame->Label(-text => $tab)->pack; $frame->Label(-text => 'a Label in '.$tab)->pack; push (@colors,shift(@colors)); #shift colors around } MainLoop;

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-20 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found