Shumkar has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks!

I'm constructing a gui with multiple tables (managed by Grid). The largest table consists of headers (Hlist widgets) and cells (Entry widgets). Both (headers and cells) are divided onto 3 different panes. The names of these panes are 'numbers', 'fixed' and 'scrollable'.

Immediately after creating this table, I see that gridInfo() returns wrong row numbers of all Entry widgets situated in the 'numbers' and 'fixed' panes: they are beginning from 1, not 0. Numbers of all Entry widgets situated in the 'scrollable' pane are beginning, as usual, from 0. So, I have cells with different gridInfo() data in one visual row. I don't understand why. Please help...

The piece of code that constructs 'numbers', 'fixed' and 'scrollable' Entry widgets with testing print() calls:

my $data = 0; my $j = 0; my $anykey; $calls->{'call_'.raised_num()}->{'main'}{$_}{'selected'} and $anykey = + $_ for (keys %{$calls->{'call_'.raised_num()}->{'main'}}); foreach (@{$calls->{'call_'.raised_num()}->{'main'}{$anykey}{'value'}} +) { # ... $calls->{'call_'.raised_num()}->{'main_ordered'} my $pane_counter_2 = 0; if ($shown_rows > $j) { foreach my $column (@{$calls->{'call_'.raised_num()}->{'main_o +rdered'}}) { foreach my $hashname (@{$calls->{'call_'.raised_num()}->{' +main_show'}}) { if (defined ($calls->{'call_'.raised_num()}->{$hashnam +e}{$column}{'selected'}) and $calls->{'call_'.raised_num()}->{$hashna +me}{$column}{'selected'}) { if ($pane_counter_2 == 0) { $entries_numbers->[raised_num()]->[$j] = $pane +s->{'pane_fixed_'.raised_num()}->Entry( -text => $j+1, -width => 7 )->grid( -row => $rows->{'pane_fixed_'. +raised_num()}, -column => $data, -sticky => 'w' ); my @numbers_info = $entries_numbers->[raised_n +um()]->[$j]->gridInfo; print 'gridder numbers: all gridInfo:'; print $_." " foreach @numbers_info; print "\n"; $entries_numbers->[raised_num()]->[$j]->bind(" +<MouseWheel>", \&scroller); } elsif ($pane_counter_2 == 1) { $entries_fixed->[raised_num()]->[$j][$pane_cou +nter_2] = $panes->{'pane_fixed_'.raised_num()}->Entry( -text => $calls->{'call_'.rais +ed_num()}->{$hashname}{$column}{'value'}[$j], -width => 22 )->grid( -row => $rows->{'pane_fixed_'. +raised_num()}, -column => $data, -sticky => 'w' ); my @fixed_info = $entries_fixed->[raised_num() +]->[$j][$pane_counter_2]->gridInfo; print 'gridder fixed: all gridInfo:'; print $_." " foreach @fixed_info; print "\n"; $hashname_fixed->[raised_num()]->[$j][$pane_co +unter_2] = $hashname; $column_fixed->[raised_num()]->[$j][$pane_coun +ter_2] = $column; $entries_fixed->[raised_num()]->[$j][$pane_cou +nter_2]->bind("<MouseWheel>", \&scroller); } elsif ($pane_counter_2 > 1) { $entries_scrollable->[raised_num()]->[$j][$pan +e_counter_2] = $panes->{'pane_scrollable_'.raised_num()}->Entry( -text => $calls->{'call_'.rais +ed_num()}->{$hashname}{$column}{'value'}[$j], -width => 22 )->grid( -row => $rows->{'pane_scrollab +le_'.raised_num()}, -column => $data, -sticky => 'w' ); my @scrollable_info = $entries_scrollable->[ra +ised_num()]->[$j][$pane_counter_2]->gridInfo; print 'gridder scrollable: all gridInfo:'; print $_." " foreach @scrollable_info; print "\n"; $hashname_scrollable->[raised_num()]->[$j][$pa +ne_counter_2] = $hashname; $column_scrollable->[raised_num()]->[$j][$pane +_counter_2] = $column; $entries_scrollable->[raised_num()]->[$j][$pan +e_counter_2]->bind("<MouseWheel>", \&scroller); } $data ++; } } $pane_counter_2 ++; } $data = 0; $rows->{'pane_fixed_'.raised_num()} ++; $rows->{'pane_scrollable_'.raised_num()} ++; $j ++; } } $calls->{'call_'.raised_num()}->{'main_delta'} = 0;

The output in the console is:

gridder numbers: all gridInfo:-in Tk::Frame=HASH(0x1ae4e5c) -column 0 -row 1 -co lumnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky w
gridder fixed: all gridInfo:-in Tk::Frame=HASH(0x1ae4e5c) -column 1 -row 1 -colu mnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky w
gridder scrollable: all gridInfo:-in Tk::Frame=HASH(0x227e404) -column 2 -row 0 -columnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky w

As you see: -row 1, -row 1, -row 0.

Replies are listed 'Best First'.
Re: Perl/Tk: gridInfo() returns a wrong row number
by zentara (Cardinal) on Aug 11, 2010 at 17:11 UTC
    they are beginning from 1, not 0.

    Don't that just get you where different people are inconsistent with count start points? Some use 1, some 0. 0 is a great number for being nothing.. :-)


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku
      Yeah, good joke :) But, if about me, in programs I prefer always 0 :) And, considering that I'm the sole author of this code, I expect it to count things so as want I, not others :)

      So, how could I make it to count always from 0?..

        Maybe, ;-)

        my $startpoint = 0; my $endpoint = 99; if ( $type eq 'row ){ $startpoint =1, $endpoint = 100 } foreach my $field ( $startpoint..$endpoint ..... .....
        I was musing over it last night, and guessed it has to do with column headers getting counted as a row, maybe ? :-)

        As to Tk having one author, it's not true IIRC. Tk is just a Perl port of TCL/Tk, and TCL/Tk was a hodgepodge collection of widgets, written by different groups, with no true 1,0 coherence to some programming style standards. So different widgets, can have methods which are not consistent across widget families.

        Tk was just meant to be easy to use. If you want some real consistency in widget design, move up to Perl-Gtk2. All of it's widgets descend from well laid out ancestors, so the style remains the same across widgets.

        Plus, the original author of Tk, Nick Simmons is gone to bit heaven, and Mr. Reszic who knows enough to handle the module, is a very busy man and dosn't support the old Tk with full time vigor. However, he might look at that as a bug, file a bug report. He will probably say that fixing it in the c code, will break something else, so just hack around it, with a few lines of code.


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku
Re: Perl/Tk: gridInfo() returns a wrong row number
by sierpinski (Chaplain) on Aug 11, 2010 at 16:39 UTC
    print 'gridder fixed: all gridInfo:'; print $_." " foreach @fixed_info;
    Looks to me like $_ is empty at this point based on your output. What are you expecting there?

    I usually don't put my foreach pieces at the end, but I don't know that might be a valid syntax, but if $_ is blank, you need to revisit what either how you are processing that foreach loop, or where the values of the array get set, because one of them is wrong.
      That was message from me ^^^; I forgot to log in.
      >you need to revisit what either how you are processing that foreach loop, or where the values of the array get set, because one of them is wrong.

      I did it. I looked deep through my code few times and didn't find nothing. The [0] value of the 'numbers' and 'fixed' arrays return row number 1.

      Ok I misread the output (or the code).... nevermind my previous comment...
      Sorry, I don't understand what you are talking about. How could $_ be blank if there is the text:

      -in Tk::Frame=HASH(0x1ae4e5c) -column 1 -row 1 -colu mnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky w

      I rewrote it as

      foreach (@fixed_info) { print $_." "; }
      - nothing changed.