Re: Possible row selection interfering with Update




On Mar 27, 2010, at 5:19 PM, Zettai Muri wrote:

Hi All,

Please find attached my main.pl file along with the GtkBuilder file I have the gui in.  I couldn't think of 
a great example but it is using the same code and widget types in my main project.

I am running the program on Windows XP with camelbox installed as 'perl main.pl'

The problem is that only the shopper name updates not all of the new information entered into the text 
views.  I have to re-select the line, re-enter the new information in the text views and then it updates 
the second time around.  It's easier to see if you run the program.

To Reproduce:

[snip excellent instructions, thanks]


Hope you can see what I'm talking about.  It only occurs on the first attempted update click.

Is someone able to tell me what I'm doing wrong?  Can't work out why the first time the update click only 
captures the shopper name but then works the second time with the shopper name and the info entered into 
the text views.


I could reproduce the behavior by following the instructions exactly.  Initially, i clicked around a bit 
before following the instructions, and it seemed fine.

You're changing the selection mode on the first update.  By moving the $treeselect->set_mode('single') line 
from update_line() to init(), i could no longer get the "first time it acts weird" behavior.  Doubtless, 
changing the mode causes the iter to be different.

I was also getting some warnings on stdout.

*** unhandled exception in callback:
***   variable not allowed to be undef where GtkTreeIter is wanted at main.pl line 262.
***  ignoring at main.pl line 66.

It's best not to ignore those.  ;-)


After moving the tree selection setup to init, you may be interested in using the two-return form of 
get_selection() and adding error checking:

    my ($model, $iter) = $treeselection->get_selected;
    return unless $iter;

The lines

    # Update the view
    $tv_items->set_model($model);

are not actually necessary; if you were swapping out the model to freeze updates, then that would be 
necessary, but you're not, so it's not.  In fact, the set_value calls immediately above are enough to make 
everything Just Work.


Oh, and in connect_signals(), you have each "clicked" handler getting $widget and $event off the stack; but 
there's no $event parameter to the "clicked" signal.


--
Zella, carrying a kite in a long plastic box:  It's like book!
Yvonne, carrying the wooden kite string spool:  It's like a wood!




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]