Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Sorted Realtime Tk Listbox

by Roy Johnson (Monsignor)
on Mar 10, 2008 at 17:48 UTC ( [id://673292]=note: print w/replies, xml ) Need Help??


in reply to Sorted Realtime Tk Listbox

You need to take note of which items are selected (by name), then find those names in the new ordered list, and select them.
use strict; use Tk; use Data::Dumper; my @data = (qw( ccc eee ddd aaa aaa ccc ddd ddd bbb ddd eee ggg fff)); my %seen; # Create & configure text widget... my $top = MainWindow->new; my $list = $top->Scrolled('Listbox')-> pack(-side=>'right', -fill=>'both', -expand =>1); my $ref; $ref = $top->repeat(700, \&addItem); sub addItem { my $item = shift(@data); if(!$item) { $ref->cancel; return }; print STDERR "$item\n"; # Selected items (by name) my @selected_items = map {$list->get($_)} $list->curselection; print "Selected items: @selected_items\n"; if(! $seen{$item}) { my @new_selection_order = sort keys %seen; # Map names to list position my %new_selection = map {($new_selection_order[$_] => $_)} 0.. +$#new_selection_order; $list->delete(0, 'end'); $list->insert('end', @new_selection_order); # Set selection(s) print "New indexes should be @new_selection{@selected_items +}\n"; $list->selectionSet($_) for @new_selection{@selected_items} +; } $seen{$item}++; } MainLoop();

Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2024-04-23 12:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found