How to delete entries within HLIST and have it update itself? - Perl

This is a discussion on How to delete entries within HLIST and have it update itself? - Perl ; I always have this issue with HLIST where when you delete an entry - it remembers all of the original entry positions. This presents a problem when you have developed a logic for mapping the position in the list when ...

+ Reply to Thread
Results 1 to 4 of 4

How to delete entries within HLIST and have it update itself?

  1. Default How to delete entries within HLIST and have it update itself?

    I always have this issue with HLIST where when you delete an entry - it
    remembers all of the original entry positions. This presents a problem
    when you have developed a logic for mapping the position in the list
    when it was created with some array or other data structure - or to be
    able to add new items to the list -

    Here is a simple example - you can add items by clicking the add button
    - then delete one by selecting the delete button - however the original
    positions are all still associated to the remaining items - even though
    they are now incorrect. Is there a way to re-fresh the entry paths?
    ------------- simple example ---------------
    use Tk;
    use Tk::HList;

    @more_colors = (qw/green magenta orange purple blue
    yellow red white black fuscia brown pink viloet grey indigo/);

    my $mw = MainWindow->new;
    $mw->geometry('300x600');

    my $list = $mw->HList()
    ->pack(qw/-fill both -expand yes/);

    $list->configure(-command=>sub{&show_me});

    my $text = $mw->Text(-width=>60,-height=>10)
    ->pack(qw/-fill both -expand yes/);

    foreach (@more_colors[2..5]) {
    $list_pos = () = $list->info("children");
    $list->add($list_pos, -text => "[$list_pos]".$_);
    } # end foreach

    $button{del_path}= $mw->Button(
    -text => 'Delete selected color ',
    -command => sub{&del_path},
    )->pack(-side=>left);

    $button{add_path}= $mw->Button(
    -text => 'Add new color ',
    -command => sub{&add_path},
    )->pack(-side=>left);

    MainLoop;

    sub show_me {
    my $path = $_[0];
    $text->insert('end',"You selected path $path \n");
    } # end sub

    sub add_path {
    my $list_pos = () = $list->info("children");
    $list->add($list_pos, -text => "[$list_pos]".(&get_color));
    } # end sub

    sub get_color {
    if ($colors >= $#more_colors) {$colors = -1};
    unless ($colors++ >= $#more_colors) {
    return @more_colors[$#more_colors-$colors];
    } # end
    return @more_colors[$colors];
    } # end sub

    sub del_path {
    my @path = $list->selectionGet;
    $list->delete('entry',$path[0]);
    $text->insert('end',"You deleted path $path[0]\n");
    } # end sub


    -------------------------------------

    thanks, john


  2. Default Re: How to delete entries within HLIST and have it update itself?

    In article <1106664657.886790.152550@c13g2000cwb.googlegroups.com>, bayxarea-
    usenet@yahoo.com says...
    > I always have this issue with HLIST where when you delete an entry - it
    > remembers all of the original entry positions. This presents a problem
    > when you have developed a logic for mapping the position in the list
    > when it was created with some array or other data structure - or to be
    > able to add new items to the list -
    >
    > Here is a simple example - you can add items by clicking the add button
    > - then delete one by selecting the delete button - however the original
    > positions are all still associated to the remaining items - even though
    > they are now incorrect. Is there a way to re-fresh the entry paths?


    Thanks for including a small working example. Tk::HList does not have
    a sense of indexes for items as does Tk::Listbox. The paths are named
    and have no implicit order. Perhaps you should use Tk::Listbox?

    --
    Go to http://MarcDashevsky.com to send me e-mail.

  3. Default Re: How to delete entries within HLIST and have it update itself?


    Marc Dashevsky <usenet@MarcDashevsky.com> wrote in message-id:
    <MPG.1c6067c244bf8cfb9896a7@news.comcast.giganews.com>
    >
    >In article <1106664657.886790.152550@c13g2000cwb.googlegroups.com>, bayxarea-
    >usenet@yahoo.com says...
    >> I always have this issue with HLIST where when you delete an entry - it
    >> remembers all of the original entry positions. This presents a problem
    >> when you have developed a logic for mapping the position in the list
    >> when it was created with some array or other data structure - or to be
    >> able to add new items to the list -
    >>
    >> Here is a simple example - you can add items by clicking the add button
    >> - then delete one by selecting the delete button - however the original
    >> positions are all still associated to the remaining items - even though
    >> they are now incorrect. Is there a way to re-fresh the entry paths?

    >
    >Thanks for including a small working example. Tk::HList does not have
    >a sense of indexes for items as does Tk::Listbox. The paths are named
    >and have no implicit order. Perhaps you should use Tk::Listbox?
    >
    >--
    > Go to http://MarcDashevsky.com to send me e-mail.


    Perhaps _hiding_ the entry rather than _deleting_ it would provide a solution
    of sorts.

    gl



  4. Default Re: How to delete entries within HLIST and have it update itself?

    On 25 Jan 2005 06:50:57 -0800, bayxarea-usenet@yahoo.com wrote:

    >I always have this issue with HLIST where when you delete an entry - it
    >remembers all of the original entry positions. This presents a problem
    >when you have developed a logic for mapping the position in the list
    >when it was created with some array or other data structure - or to be
    >able to add new items to the list -
    >
    >Here is a simple example - you can add items by clicking the add button
    >- then delete one by selecting the delete button - however the original
    >positions are all still associated to the remaining items - even though
    >they are now incorrect. Is there a way to re-fresh the entry paths?


    Yeah, that is the biggest hassle with HList, it keeps an internal
    numbering of entries, which just keeps rising for each entry. I was
    often tempted to wonder if this affects performance in long running
    apps, where the internal counter is up into the millions. :-) But I
    guess computers don't really care, a number is a number; 9 is as
    good as 16,000,0009.

    It really becomes a hassle when you want to insert at some position.

    A couple of ways I have dealt with it.....(from memory so I may be off a
    bit) :-)

    1. Only create a set number of entries and reuse them, by reconfiguring
    them. This is what I do when I want to have a "pager mechanism", say
    10 pages of 10 entries each. When you want to change entry2 for
    instance, you don't delete it, you reconfigure it.

    2. The other option is to keep a separate hash of which entries have
    which entry paths.

    So it seems that you are forced to track them yourselves in a separate
    hash.

    A couple of my HList apps have some really wacky insertion subs, where I
    loop thru all entries, testing if the next or previous entry exists,
    (since they may have been deleted earlier)
    then do something accordingly. Like this, where I delete the selected
    entry, and want to find the next available entry to set as selected:

    my $listnum =$h->info('selection');
    $h->delete('entry',$h->info('selection'));
    if($h->info('exists', $listnum + 1)){
    $h->selectionSet($listnum + 1)
    }else{
    while($listnum--){

    if($h->info('exists',$listnum)){

    $h->selectionSet($listnum);last}
    }


    It should be easier than that. I should be able just to select the next
    number, but you risk getting "entry dosn't exist" errors.
    Like you say, if there was an internal
    command to HList, to "refresh" it's internal counter, it would be nice.
    But there probably is some obscure reason why the counter is done
    this way, maybe the author knows? I'm guessing it has something to do
    with making an entry "hidden", then returning it to "normal"...that has
    to be tracked somehow.

    (Just blowing off HList "steam" :-) ).


    --
    I'm not really a human, but I play one on earth.
    http://zentara.net/japh.html

+ Reply to Thread

Similar Threads

  1. SQL Update with a delete / update / insert in one go
    By Application Development in forum Clipper
    Replies: 27
    Last Post: 10-26-2007, 05:23 AM
  2. Bills History Duplicate Entries, How do I delete one
    By Application Development in forum Microsoft Money
    Replies: 0
    Last Post: 11-08-2006, 09:49 AM
  3. Cant delete entries from Inbox
    By Application Development in forum Microsoft Exchange
    Replies: 1
    Last Post: 05-14-2004, 04:25 PM
  4. Replies: 0
    Last Post: 04-18-2004, 02:02 PM
  5. Delete email based on addressbook entries?
    By Application Development in forum Pegasus
    Replies: 3
    Last Post: 09-28-2003, 12:30 PM