Re: Popup Menu problem while copy and paste..
- From: Ch Lamprecht <ch.l.ngre@xxxxxxxxx>
- Date: Sun, 10 Feb 2008 13:41:49 +0100
nagandla@xxxxxxxxx wrote:
On Feb 8, 9:06 pm, Ch Lamprecht <ch.l.n...@xxxxxxxxx> wrote:
nagan...@xxxxxxxxx wrote:
Hi All,
Here i am creating a popup menu for text widget..It contains
copy ,paste,delete functions..
I am copying & pasting the data in text widget .
After pasting data using popup menu , data is pasting perfectly into
text widget.
After that i am pressing the "DoSomething" button .
but it is not pressing on first click.For Second click its
working.This problem is in only windows but not in linux..
How i have to solve this problem?
Tk version is Tk-804.027.
I added the code $m->focus in paste_data subroutine...Hi,
But unfortunately application is still giving same problem.
Nagandla
yes, you are right. I think there is a grabRelease missing in Tk::Menu::Unpost. Does the code below fix it for you? There are more issues with Tk::Menu on Win32 ( see http://rt.cpan.org/Public/Bug/Display.html?id=28238 )
In the example below, the last print statement will not be reached and you will loose memory with each call to Popup...
Christoph
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new();
my $mnu;
my $txt ;
my $entry = $mw->Entry(-textvariable => \$txt, -background=>'white')->pack();
my $btn = $mw->Button(-text=>'Do Something',-command=>sub {
print "Doing Something bla bla ..\n";
# Doing Something.......
},-activeforeground=>'red')->pack();
$entry->bind("<Button-3>",\&popups);
my $cbm;
MainLoop;
sub copy_data
{
my($m) = @_;
print "Copy Data \n ";
my $cliptxt ;
eval
{
$mw->clipboardClear;
$mw->clipboardAppend($m->get());
};
if($@)
{
print "$@\n";
}
print "$txt Appended to CLIPBOARD\n";
$mnu->grabRelease;
}
sub paste_data
{
my($m) = @_;
print "Past Data \n ";
my $cliptext;
eval
{
$cliptext = $mw->SelectionGet(-selection => "CLIPBOARD");
};
$cliptext |= '';
$m->insert('end',$cliptext);
$mnu->grabRelease;
}
sub delete_data
{
my($m) = @_;
$m->delete('sel.first','sel.last') # Remove Selected text
if($m->selectionPresent()); # if Selection Present
$mnu->grabRelease;
}
sub popups
{
my($w) = @_ ;
$mnu ||= $mw->Menu(-menuitems => [
["command" =>'Copy' , -command => sub{ ©_data($w);} ],
'',
["command" => 'Paste' , -command => sub {&paste_data($w) ;} ],
'',
["command" => 'Delete' , -command => sub {&delete_data($w) ;} ],
],-tearoff=>0);
$mnu->Popup(-popover=>'cursor',-popanchor=>"nw");
print "popup returned\n";
}
--
use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
$c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
.
- Follow-Ups:
- Re: Popup Menu problem while copy and paste..
- From: nagandla
- Re: Popup Menu problem while copy and paste..
- References:
- Popup Menu problem while copy and paste..
- From: nagandla
- Re: Popup Menu problem while copy and paste..
- From: Ch Lamprecht
- Re: Popup Menu problem while copy and paste..
- From: nagandla
- Popup Menu problem while copy and paste..
- Prev by Date: Re: Popup Menu problem while copy and paste..
- Next by Date: 請問
- Previous by thread: Re: Popup Menu problem while copy and paste..
- Next by thread: Re: Popup Menu problem while copy and paste..
- Index(es):
Loading