Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Simple PerlTk program working slow

by zentara (Archbishop)
on Nov 28, 2017 at 18:33 UTC ( [id://1204461]=note: print w/replies, xml ) Need Help??


in reply to Simple PerlTk program working slow

Hi, I'm not sure what you mean by "working slow"? I ran your code and it built and ran fast enough so that there didn't seem to be a problem. However, alI I got was 4000 squares which didn't have a scrollbar, but scrolled well with my mousewheel.

When I added "use warnings", I got

Argument "5.88383838383838384.0" isn't numeric in division (/) at ./12 +04438.pl line 42
I'm not going to try and figure out what your program does, but you might want to look at Re: I seek illumination and knowledge for a sample canvas program that works.

Or, a simpler version:

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow(); $mw->geometry("600x400+200+200"); #for xscroll, must be packed before midframe to be visible my $botframe = $mw->Frame(-bg=>'grey45') ->pack(-fill=>'x',-side=>'bottom'); my $midframe = $mw->Frame(-bg=>'grey45')->pack(); my $midframel = $midframe->Frame(-bg=>'grey45') ->pack(-side=>'left',-expand=>1,-fill=>'y'); my $midframer = $midframe->Frame(-bg=>'grey45') ->pack(-side=>'right'); my $num_channels = 40; my $canvasp; my $canvast = $midframer->Canvas( -bg =>'pale goldenrod', -width=>2400, -height=>25, #need to set scrollregion with a bit extra to ensure #endpoint accuracy. See xscrollit sub -scrollregion=>[-10,0,7250,25], -xscrollincrement => 1, )->pack(-side=>'top'); #for canvasp and yscroll my $midframer1 = $midframer->Frame(-bg=>'grey45') ->pack(-side=>'top'); my $yscroll = $midframer1->Scrollbar( -orient => 'vertical', -command => \&yscrollit, -troughcolor =>'grey45', -activebackground =>'lightseagreen', -background => 'lightseagreen', )->pack(-side=>'right',-fill=>'y'); my $canvasxsd = $botframe->Canvas( #dummy filler -bg =>'grey45', -width=>75, -height=>25, -borderwidth=>0, ) ->pack(-side=>'left'); my $xscroll = $botframe->Scrollbar( -orient => 'horizontal', -command => \&xscrollit , -troughcolor =>'grey45', -activebackground =>'lightseagreen', -background => 'lightseagreen', )->pack(-side=>'right', -fill=>'x',-expand =>1); $canvasp = $midframer1->Canvas( -bg =>'lightsteelblue', -width=>2400, -height=> 50 * $num_channels, -scrollregion=>[-10,0,7250,(33 * $num_channels)], -xscrollincrement => 1, -yscrollincrement => 1, -xscrollcommand => [ 'set', $xscroll ], -yscrollcommand => [ 'set', $yscroll ], ) ->pack(-side=>'left');#,-fill=>'both'); my $canvasd = $midframel->Canvas( #top of left frame dummy filler -bg =>'grey45', -width=>75, -height=>25, -borderwidth =>0, )->pack(-side=>'top'); my $canvass = $midframel->Canvas( #left frame canvas -bg =>'lightseagreen', -width=>75, -height=> 50 * $num_channels, -scrollregion=>[0,0,75,(33 * $num_channels)], -yscrollincrement => 1, ) ->pack(-side=>'top'); #fill in some sample data to see scrolling action for( 0 .. 33 * $num_channels){ $canvass->createText(38, 10 + $_ * 33, -text => "C $_" , ); } #set up top frame canvas... a timeline for(0..7200){ if( $_ % 50 == 0){ $canvast->createLine($_,0,$_,12,-width=> 4,-tags=>['tick'] ); $canvast->createText($_, 20, -text=> $_,-tags=>['tick'] ); } } #set up main frame some canvas data foreach my $y (0..39){ foreach my $x (0..7200){ next unless ( $x % 5 == 0); next if 20*$x > 7200; $canvasp->createText($x * 20, 8 + $y * 33, -text=> 20*$x.'-'.$y, -tags=>['data'] ); } } my ($xt,$yt,$xt1,$yt1)=$canvast->bbox('all'); my ($xs,$ys,$xs1,$ys1)=$canvass->bbox('all'); my ($xp,$yp,$xp1,$yp1)=$canvasp->bbox('all'); print "t-> $xt,$yt, $xt1,$yt1\n"; print "s-> $xs,$ys, $xs1,$ys1\n"; print "p-> $xp,$yp, $xp1,$yp1\n"; $canvast->configure( -scrollregion=> [$canvasp->bbox('all')] ); MainLoop; ################################### sub xscrollit{ my $fraction = $_[1]; $canvast->xviewMoveto($fraction); $canvasp->xviewMoveto($fraction); } ###################################################################### sub yscrollit{ my $fraction = $_[1]; $canvass->yviewMoveto($fraction); $canvasp->yviewMoveto($fraction); } ####################################################################

I'm not really a human, but I play one on earth. ..... an animated JAPH

Replies are listed 'Best First'.
Re^2: Simple PerlTk program working slow
by dexahex (Novice) on Nov 28, 2017 at 22:53 UTC

    Sorry I didn't give enough details about the issue. Really program starts and runs fast. You can scroll down with mouse wheel. It works fine.

    The problem appears when I change main window size by dragging main window border with mouse. It issues 'Configure' event that is bound to a anonymous subroutine that just calls update_fileview() subroutine. This subroutine redraws canvas with rectangles.

    I must note that in TCL version 'Configure' event is bound on canvas widget and it works rather fine. In Perl when I bind 'Configure' event on canvas it doesn't call the bound subroutine when I change toplevel window size. So I decided to bind 'Configure' event on $top (toplevel) widget, that is a parent of canvas $canv. And it works as expected but redrawing during window resize is very slow.

    Now I know that the slowness is caused by binding to a toplevel ($top) widget instead of canvas ($canv). When I changed binding in TCL from canvas to toplevel ('.') it has shown the same issue.

    So by now I only try to figure out how to force 'Configure' event to come to canvas. Current binding only works for toplevel, that, as we know, shows very slow redraw issue. The main question - how to make canvas to receive 'Configure' event??

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-23 17:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found