in reply to Re: Tk::Columns only 10 lines visible
in thread Tk::Columns only 10 lines visible

WidgetDump is cool! Thanks; but if I change the height of the listboxes, it has no effect. :-( Here is the relevant code of my tool (you need a .csv file with 9 comma separated values):
#!/opt/nokia/oss/perl/bin/perl -w eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' if 0; use strict; use warnings; use Tk; use Tk::Table; use Tk::ProgressBar; use Tk::Columns; use Tk::WidgetDump; my ($mw, $hist_win, $info_history_page, $navi_frame, $history_button, +$list, $hist_frame); my ($first_button, $last_button, $back_button, $next_button); my (%date, %time, %rac_name, %alias, %profile_right, %bearbeiter, %pro +file, %ext_dxt, %ticket_ref); my $history_file = "/tmp/history_dev.csv"; my $last_id = 1; my $shown_on_page = 25; my $show_to = 25; my $show_from = 1; my $page = 1; my $pages = 1; $mw = MainWindow->new; $mw->title("RA-Management"); $mw->WidgetDump; my $mm = $mw->Frame(-relief=>'ridge', -bd=>2, -borderwidth=>2, -visual +=>"truecolor 2")->pack();; $history_button = $mm->Button( -text=>"History anzeigen", -command=>su +b{\&SUB_SHOW_HISTORY()})->pack(); $mw->update; MainLoop; sub SUB_SHOW_HISTORY { &SUB_READ_HISTORY(); $pages = int($last_id/$shown_on_page); $hist_win = $mw->Toplevel(); $hist_win->geometry('1000x760+0+0'); $hist_win->minsize(1000,760); $hist_win->maxsize(1000,760); $hist_win->title("Log History"); $hist_win->Label(-text=>"Änderungshistorie\n")->pack(); $navi_frame = $hist_win->Frame(-borderwidth=>2, -relief=>'sun +ken')->pack( -side=>'top', -fill=>'x' ); $info_history_page = $navi_frame->Label(-text=>"Seite $page vo +n $pages")->grid('-','-','-'); $first_button = $navi_frame->Button( -text=>"<< Erste Seite", +-command=>sub{$page = 1; $show_from = 1; $show_to = $shown_on_page;\& +SUB_REFRESH_HIST()})->grid( $back_button = $navi_frame->Button( -text=>"< Zurück", -comma +nd=>sub{$page = $page-1; $show_from = $show_from-$shown_on_page; $sho +w_to = $show_to-$shown_on_page;\&SUB_REFRESH_HIST()}), $next_button = $navi_frame->Button( -text=>"Vor >", -command=> +sub{$page = $page+1; $show_from = $show_from+$shown_on_page; if ( $sh +ow_to == 25 ) {$show_to = $show_to+1+$shown_on_page} else {$show_to = + $show_to+$shown_on_page}\&SUB_REFRESH_HIST()}), $last_button = $navi_frame->Button( -text=>"Letzte Seite >>", +-command=>sub{$page = $pages; $show_from = $pages*$shown_on_page; $sh +ow_to = $last_id+1;\&SUB_REFRESH_HIST()})); $hist_frame = $hist_win->Frame(-borderwidth=>2, -relief=>'sun +ken', -height=>300)->pack( -side=>'top', -fill=>'both' ); $list = $hist_frame->Columns(-height=>25)->pack(-expand=>1, -f +ill=>'both'); my @columns_desc = ("DB-ID","Datum","Zeit","User Name","User-A +lias","Right","NE-Name","Ticket-Ref","Operator"); $list->ColumnButton( -text=>"$columns_desc[0]", -width=>6); $list->ColumnButton( -text=>"$columns_desc[1]", -width=>9); $list->ColumnButton( -text=>"$columns_desc[2]", -width=>7); $list->ColumnButton( -text=>"$columns_desc[3]", -width=>25); $list->ColumnButton( -text=>"$columns_desc[4]", -width=>10); $list->ColumnButton( -text=>"$columns_desc[5]", -width=>12); $list->ColumnButton( -text=>"$columns_desc[6]", -width=>15); $list->ColumnButton( -text=>"$columns_desc[7]", -width=>14); $list->ColumnButton( -text=>"$columns_desc[8]", -width=>8); &SUB_REFRESH_HIST(); my $button_ok = $hist_win->Button(-text=>'OK', -command=> sub +{$hist_win->destroy();} )->pack(); } sub SUB_REFRESH_HIST { if ( $page == 1 ) { $first_button->configure(-state=>'disabled +'); $back_button->configure(-state=>'disabled'); $show_from = 1; $sho +w_to = 25;} elsif ( $page != 1 ) { $first_button->configure(-state=>'norma +l'); $back_button->configure(-state=>'normal');} if ( $page == $pages ) { $last_button->configure(-state=>'disa +bled'); $next_button->configure(-state=>'disabled'); $show_to = $last +_id;} elsif ( $page == $pages-1 ) { $last_button->configure(-state=> +'normal'); $next_button->configure(-state=>'normal');$show_from = $pa +ge*25; $show_to = $page*25+25;} elsif ( $page != $pages ) { $last_button->configure(-state=>'n +ormal'); $next_button->configure(-state=>'normal');} $list->delete(0,'end'); for ( my $i = $show_from; $i <= $show_to; $i++ ) { my $hist_db_id = sprintf"%06d", $i; my $history_date = $date{$i}; $history_date =~ s/(\d{4})(\d{2})(\d{2})/$1-$2-$3/; my $history_time = $time{$i}; $history_time =~ s/(\d{2})(\d{2})(\d{2})/$1:$2:$3/; $list->insert('end', { 'DB-ID'=>$hist_db_id, 'Datum'=>$history_date, 'Zeit'=>$history_time, 'User Name'=>$rac_name{$i}, 'User-Alias'=>$alias{$i}, 'Right'=>$profile_right{$i}, 'NE-Name'=>$ext_dxt{$i}, 'Ticket-Ref'=>$ticket_ref{$i}, 'Operator'=>$bearbeiter{$i} }); } $list->pack(-side=>'left', -fill=>'both', -expand=>1); $info_history_page->configure(-text=>"Seite $page von $pages") +; $list->update; } sub SUB_READ_HISTORY { if ( ! open ( DATA, '+<', $history_file )) { exit(250); } my $id = 1; while (my $line = <DATA>) { chomp $line; my @fields = split "," , $line; $id = $fields[0]; if ( defined $rac_name{$id} ) { goto BEREITS_GELADEN; } $rac_name{$id} = $fields[1]; $alias{$id} = $fields[2]; if ( $fields[3] =~ m/(NetAct(\d\d)|Unknown)/ ) { my $prof_num = ""; if ( defined $2 ) { $prof_num = $2 } else { $profile_right{$id} = "Unknown"; } $profile{$id} = $fields[3]; if ( $prof_num eq "08" ) { $profile_right{$id} + = "kein";} elsif ( $prof_num eq "98" ) { $profile_right{$ +id} = "lesend"; } elsif ( $prof_num eq "20" ) { $profile_right{$ +id} = "schreibend"; } } $bearbeiter{$id} = $fields[4]; $ticket_ref{$id} = $fields[5]; $date{$id} = $fields[6]; $time{$id} = $fields[7]; $ext_dxt{$id} = $fields[8]; BEREITS_GELADEN: } close DATA; $last_id = $id; }

Replies are listed 'Best First'.
Re^3: Tk::Columns only 10 lines visible
by Anonymous Monk on Apr 18, 2013 at 09:53 UTC

    man, I was scratching my head for a few minute, I couldn't see anything, cause cpan Tk::Columns installs DKWILSON/Tk-DKW-0.01.tar.gz instead of DKWILSON/Tk-DKW-0.03.tar.gz

    So for anyone else looking at this, cpanp -i DKWILSON/Tk-DKW-0.03.tar.gz

Re^3: Tk::Columns only 10 lines visible
by Anonymous Monk on Apr 18, 2013 at 10:06 UTC

    So here it is, without using children, using some Tk::Columns specific methos

    #!/opt/nokia/oss/perl/bin/perl -w -- eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' if 0; ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" use strict; use warnings; use Tk; use Tk::Table; use Tk::ProgressBar; use Tk::Columns; use Tk::WidgetDump; my( $mw, $hist_win, $info_history_page, $navi_frame, $history_button, +$list, $hist_frame ); my( $first_button, $last_button, $back_button, $next_button ); my( %date, %time, %rac_name, %alias, %profile_right, %bearbeiter, %profile, %ext_dxt, %ticket_ref ); my $history_file = \( join '', map { ( join ',', map { rand $_ } 1 .. 9 ) . "\n" } 1 .. 50 ); my $last_id = 1; my $shown_on_page = 25; my $show_to = 25; my $show_from = 1; my $page = 1; my $pages = 1; $mw = MainWindow->new; $mw->title( "RA-Management" ); my $mm = $mw->Frame( -relief => 'ridge', -bd => 2, -borderwidth => 2, -visual => "truecolor 2" )->pack(); $history_button = $mm->Button( -text => "History anzeigen", -command => sub { SUB_SHOW_HISTORY(); } )->pack(); #~ $history_button ->invoke;## $history_button ->click; $mw->update; $mw->WidgetDump; MainLoop; sub SUB_SHOW_HISTORY { &SUB_READ_HISTORY(); $pages = int( $last_id / $shown_on_page ); $hist_win = $mw->Toplevel(); $hist_win->geometry( '1000x760+0+0' ); $hist_win->minsize( 1000, 760 ); $hist_win->maxsize( 1000, 760 ); $hist_win->title( "Log History" ); $hist_win->Label( -text => "Änderungshistorie\n" )->pack(); $navi_frame = $hist_win->Frame( -borderwidth => 2, -relief => 'sun +ken' ) ->pack( -side => 'top', -fill => 'x' ); $info_history_page = $navi_frame->Label( -text => "Seite $page von + $pages" ) ->grid( '-', '-', '-' ); $first_button = $navi_frame->Button( -text => "<< Erste Seite", -command => sub { $page = 1; $show_from = 1; $show_to = $shown_on_page; \&SUB_REFRESH_HIST(); } )->grid( $back_button = $navi_frame->Button( -text => "< Zurück", -command => sub { $page = $page - 1; $show_from = $show_from - $shown_on_page; $show_to = $show_to - $shown_on_page; \&SUB_REFRESH_HIST(); } ), $next_button = $navi_frame->Button( -text => "Vor >", -command => sub { $page = $page + 1; $show_from = $show_from + $shown_on_page; if( $show_to == 25 ) { $show_to = $show_to + 1 + $shown_on_page; } else { $show_to = $show_to + $shown_on_page; } \&SUB_REFRESH_HIST(); } ), $last_button = $navi_frame->Button( -text => "Letzte Seite >>", -command => sub { $page = $pages; $show_from = $pages * $shown_on_page; $show_to = $last_id + 1; \&SUB_REFRESH_HIST(); } ) ); $hist_frame = $hist_win->Frame( -borderwidth => 2, -relief => 'sunken', -height => 300 )->pack( -side => 'top', -fill => 'both' ); $list = $hist_frame->Columns( -height => 25 ) ->pack( -expand => 1, -fill => 'both' ); my @columns_desc = ( "DB-ID", "Datum", "Zeit", "User Name", "User-Alias", "Right", "NE-Name", "Ticket-Ref", "Operator" ); $list->ColumnButton( -text => "$columns_desc[0]", -width => 6 ); $list->ColumnButton( -text => "$columns_desc[1]", -width => 9 ); $list->ColumnButton( -text => "$columns_desc[2]", -width => 7 ); $list->ColumnButton( -text => "$columns_desc[3]", -width => 25 ); $list->ColumnButton( -text => "$columns_desc[4]", -width => 10 ); $list->ColumnButton( -text => "$columns_desc[5]", -width => 12 ); $list->ColumnButton( -text => "$columns_desc[6]", -width => 15 ); $list->ColumnButton( -text => "$columns_desc[7]", -width => 14 ); $list->ColumnButton( -text => "$columns_desc[8]", -width => 8 ); SUB_REFRESH_HIST(); theRealListHeight( $list, 25 ); my $button_ok = $hist_win->Button( -text => 'OK', -command => sub { $hist_win->destroy(); } )->pack(); } ## end sub SUB_SHOW_HISTORY sub SUB_REFRESH_HIST { no warnings qw' uninitialized '; if( $page == 1 ) { $first_button->configure( -state => 'disabled' ); $back_button->configure( -state => 'disabled' ); $show_from = 1; $show_to = 25; } elsif( $page != 1 ) { $first_button->configure( -state => 'normal' ); $back_button->configure( -state => 'normal' ); } if( $page == $pages ) { $last_button->configure( -state => 'disabled' ); $next_button->configure( -state => 'disabled' ); $show_to = $last_id; } elsif( $page == $pages - 1 ) { $last_button->configure( -state => 'normal' ); $next_button->configure( -state => 'normal' ); $show_from = $page * 25; $show_to = $page * 25 + 25; } elsif( $page != $pages ) { $last_button->configure( -state => 'normal' ); $next_button->configure( -state => 'normal' ); } $list->delete( 0, 'end' ); for( my $i = $show_from ; $i <= $show_to ; $i++ ) { my $hist_db_id = sprintf "%06d", $i; my $history_date = $date{$i}; $history_date =~ s/(\d{4})(\d{2})(\d{2})/$1-$2-$3/; my $history_time = $time{$i}; $history_time =~ s/(\d{2})(\d{2})(\d{2})/$1:$2:$3/; $list->insert( 'end', { 'DB-ID' => $hist_db_id, 'Datum' => $history_date, 'Zeit' => $history_time, 'User Name' => $rac_name{$i}, 'User-Alias' => $alias{$i}, 'Right' => $profile_right{$i}, 'NE-Name' => $ext_dxt{$i}, 'Ticket-Ref' => $ticket_ref{$i}, 'Operator' => $bearbeiter{$i} } ); } $list->pack( -side => 'left', -fill => 'both', -expand => 1 ); $info_history_page->configure( -text => "Seite $page von $pages" ) +; $list->update; } ## end sub SUB_REFRESH_HIST sub SUB_READ_HISTORY { if( !open( DATA, '+<', $history_file ) ) { exit( 250 ); } my $id = 1; while( my $line = <DATA> ) { chomp $line; my @fields = split ",", $line; $id = $fields[0]; if( defined $rac_name{$id} ) { goto BEREITS_GELADEN; } $rac_name{$id} = $fields[1]; $alias{$id} = $fields[2]; if( $fields[3] =~ m/(NetAct(\d\d)|Unknown)/ ) { my $prof_num = ""; if( defined $2 ) { $prof_num = $2 } else { $profile_right{$id} = "Unknown"; } $profile{$id} = $fields[3]; if( $prof_num eq "08" ) { $profile_right{$id} = "kein"; + } elsif( $prof_num eq "98" ) { $profile_right{$id} = "lesend +"; } elsif( $prof_num eq "20" ) { $profile_right{$id} = "schrei +bend"; } } $bearbeiter{$id} = $fields[4]; $ticket_ref{$id} = $fields[5]; $date{$id} = $fields[6]; $time{$id} = $fields[7]; $ext_dxt{$id} = $fields[8]; BEREITS_GELADEN: } close DATA; $last_id = $id; } ## end sub SUB_READ_HISTORY sub theRealListHeight { my( $list, $height ) = @_; use Data::Dump qw/ dd pp /; foreach my $l_List ( $list->lists() ) { dd "$l_List"; if( $l_List->isa( 'Tk::Listbox' ) ) { $l_List->Tk::Listbox::configure( -height => $height ); } } } ## end sub theRealListHeight
      Thanks a lot, its working. Now I will try to understand what you are doing :-D
Re^3: Tk::Columns only 10 lines visible
by Anonymous Monk on Apr 18, 2013 at 10:19 UTC

      Thanks a lot. I know my code is ugly; my colleague calls it "kindergarten code". I will take a look into the mentioned resources.

      The sub READ_HISTORY is very shorten in this example. I use the variables global, as in the real tool there is also a current.csv and I work with the informations from both files global in the complete script.

      I forced myself to add SUB in every sub as I started code with subs. It's redundant but for me it was much more easier to understand. I will force myself know to save four characters in every sub in future. ;-)

      Again thanks a lot I spent at least two days try and error and also at least one day reading/searchin the net; You solved the problem within a few minutes!