Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Calling $listbox->selectionSet($index) does not generate <<ListboxSelect>> event
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Josef Moellers  
View profile  
 More options Apr 3 2012, 9:27 am
Newsgroups: comp.lang.perl.tk
From: Josef Moellers <josef.moell...@ts.fujitsu.com>
Date: Tue, 03 Apr 2012 15:27:03 +0200
Local: Tues, Apr 3 2012 9:27 am
Subject: Calling $listbox->selectionSet($index) does not generate <<ListboxSelect>> event
Hi,

I have an entry widget which has a binding for "<Key-Return>" and I have
a listbox widget which has a bidning for "<<ListboxSelect>>".
Both bindings work OK: if I enter something into the entry widget, it
runs the handler, if I select a listbox entry uwing the mouse, it fires
the handler. However, when I call "selectionSet()" from the entry
widget's "<Key-Return>" handler with the index of an entry in the
listbox, the "<<ListboxSelect>>", the "<<ListboxSelect>>" virtual event
is not generated.

From the man page, I inferred that it should have been: "Any time the
selection changes in the listbox, the virtual event <<ListboxSelect>>
will be generated."

The following shows what I mean:
If you click on an entry in the list, the text appears at the bottom.
If you enter an entry's text, the entry will be selected, but the label
will not be modified.

What am I doing wrong?

Josef

#! /usr/bin/perl

use warnings;
use strict;
use Tk;

my $top = new MainWindow;
my $ent = $top->Entry(-width => 10)->pack(-side => 'top');
my $list = $top->Listbox(-height => 5, -selectmode =>
'browse')->pack(-side => 'top');
my $lab = $top->Label(-text => 'XXX')->pack(-side => 'top');

$ent->bind('<Key-Return>' => [ \&search, $ent, $list ]);
$list->bind('<<ListboxSelect>>' => [ \&show, $list, $lab ]);

$list->insert('end', $_) foreach ('A', 'B', 'C', 'D', 'E', 'F');
MainLoop;

sub search {
    my ($self, $ent, $list) = @_;

    my $listlen = $list->size;
    my $pat = $ent->get();
    for (my $n = 0; $n < $listlen; $n++) {
        my $item = $list->get($n);
        if ($item =~ /$pat/) {
            $list->selectionSet($n);
            last;
        }
    }

}

sub show {
    my ($self, $list, $lab) = @_;

    my $idx = $list->curselection;
    my $text = $list->get($idx);

    $lab->configure(-text => $text);

}

--
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
        If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
$Bill  
View profile  
 More options Apr 3 2012, 10:18 am
Newsgroups: comp.lang.perl.tk
From: "$Bill" <n...@todbe.com>
Date: Tue, 03 Apr 2012 07:18:01 -0700
Local: Tues, Apr 3 2012 10:18 am
Subject: Re: Calling $listbox->selectionSet($index) does not generate <<ListboxSelect>> event
On 04/03/2012 06:27, Josef Moellers wrote:

I'm guessing since you added the return handler, you have to link the
event to the handler yourself (the existing mouse/kybd handlers are
already linked to generate the event).  Note the change to your search
routine(I cleared the selection [just for looks] and left your set, but
followed it with an eventGenerate):

use strict;
use warnings;
use Tk;

my $top = new MainWindow;
my $ent = $top->Entry(-width => 10)->pack(-side => 'top');
my $list = $top->Listbox(-height => 5, -selectmode => 'browse')->pack(
   -side => 'top');
my $lab = $top->Label(-text => 'XXX')->pack(-side => 'top');

$ent->bind('<Key-Return>' => [ \&search, $ent, $list ]);
$list->bind('<<ListboxSelect>>' => [ \&show, $list, $lab ]);

$list->insert('end', $_) foreach ('A', 'B', 'C', 'D', 'E', 'F');
MainLoop;

sub search {
        my ($self, $ent, $list) = @_;

my $listlen = $list->size;
my $pat = $ent->get();
for (my $n = 0; $n < $listlen; $n++) {
        my $item = $list->get($n);
        if ($item =~ /$pat/) {
                $list->selectionClear(0, 'end');
                $list->selectionSet($n);
                $list->eventGenerate("<<ListboxSelect>>");
                last;
        }

}
}

sub show {
        my ($self, $list, $lab) = @_;

my $idx = $list->curselection;
my $text = $list->get($idx);
$lab->configure(-text => $text);

}

__END__

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Horst-W. Radners  
View profile  
 More options Apr 3 2012, 10:28 am
Newsgroups: comp.lang.perl.tk
From: "Horst-W. Radners" <hSoPrA...@raSdPnAeMrs.de>
Date: Tue, 03 Apr 2012 16:28:05 +0200
Local: Tues, Apr 3 2012 10:28 am
Subject: Re: Calling $listbox->selectionSet($index) does not generate <<ListboxSelect>> event
Josef Moellers schrieb am 03.04.2012 15:27:

> [...]
>  From the man page, I inferred that it should have been: "Any time the
> selection changes in the listbox, the virtual event<<ListboxSelect>>
> will be generated."

IMHO this means 'by the user', not programmatically.

> What am I doing wrong?

Well, you already know that the selection has changed after your
        $list->selectionSet($n);
so trigger that event by yourself:
        $list->eventGenerate('<<ListboxSelect>>');

But note one more thing: you will get errors after the first entry,
since your code generates *multiple selections* this way.
You probably want an addtl.
        $list->selectionClear(0,'end');
before setting the new one.

HTH, Horst
--
<remove S P A M 2x from my email address to get the real one>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josef Moellers  
View profile  
 More options Apr 4 2012, 3:03 am
Newsgroups: comp.lang.perl.tk
From: Josef Moellers <josef.moell...@ts.fujitsu.com>
Date: Wed, 04 Apr 2012 09:03:53 +0200
Local: Wed, Apr 4 2012 3:03 am
Subject: Re: Calling $listbox->selectionSet($index) does not generate <<ListboxSelect>> event
Am 4.4.2012 schrub Horst-W. Radners:

Thanks, also to $Bill.

Strangely, this works in the simple example I provided, but in the
slightly larger one that I am writing (involving database accesses
etc.), I have to pass $list->Subwidget('scrolled') when binding to
<Key-Return> to the entry widget. Passing $list did not work: the
handler was not invoked.

Thanks again to both of you,

Josef
--
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
        If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
$Bill  
View profile  
 More options Apr 4 2012, 6:41 am
Newsgroups: comp.lang.perl.tk
From: "$Bill" <n...@todbe.com>
Date: Wed, 04 Apr 2012 03:41:56 -0700
Local: Wed, Apr 4 2012 6:41 am
Subject: Re: Calling $listbox->selectionSet($index) does not generate <<ListboxSelect>> event
On 04/04/2012 00:03, Josef Moellers wrote:

> Thanks, also to $Bill.

> Strangely, this works in the simple example I provided, but in the
> slightly larger one that I am writing (involving database accesses
> etc.), I have to pass $list->Subwidget('scrolled') when binding to
> <Key-Return>  to the entry widget. Passing $list did not work: the
> handler was not invoked.

It's probably the scoping of $list.  Try using 'our $list = ... ;' and make
sure it's declared prior to the routine you pass to.  I had a similar
scoping problem that I actually wrote an embedded sub in the GUI
definition sub and had it return a ref to the obj/widget.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josef Moellers  
View profile  
 More options Apr 4 2012, 7:41 am
Newsgroups: comp.lang.perl.tk
From: Josef Moellers <josef.moell...@ts.fujitsu.com>
Date: Wed, 04 Apr 2012 13:41:37 +0200
Local: Wed, Apr 4 2012 7:41 am
Subject: Re: Calling $listbox->selectionSet($index) does not generate <<ListboxSelect>> event
Am 4.4.2012 schrub $Bill:

> On 04/04/2012 00:03, Josef Moellers wrote:

>> Thanks, also to $Bill.

>> Strangely, this works in the simple example I provided, but in the
>> slightly larger one that I am writing (involving database accesses
>> etc.), I have to pass $list->Subwidget('scrolled') when binding to
>> <Key-Return>  to the entry widget. Passing $list did not work: the
>> handler was not invoked.

> It's probably the scoping of $list.  Try using 'our $list = ... ;' and make
> sure it's declared prior to the routine you pass to.  I had a similar
> scoping problem that I actually wrote an embedded sub in the GUI
> definition sub and had it return a ref to the obj/widget.

No show :-(

But then ... if it works with the Subwidget call, I'm happy.

Thanks again,

Josef
--
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
        If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »