Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Alright, I think I've almost isolated the problem, but I feel no closer to a solution--without someone else's help, that is. :)

Let me illustrate with 2 contrasting examples. These examples only test ovals because they are the objects that are truly causing me trouble.

========================= Ex. 1 =========================

So first, when I run the whole out of one file, as you did in your example, I have no problem. The ovals scale properly and I get no error messages See code below.

review.pm
use Tk; our $MW = MainWindow->new(-title => " PROXY FOR MW"); $MW->geometry("+4+5"); RC::review($MW); MainLoop; package RC; use Tk; use Tk::PNG; use Tk::LabFrame; use Tk::Radiobutton; use Tk::Pane; use File::Basename; use feature ':5.10'; use strict; sub review { my ($MW) = @_; my ($RW, $FW, $CW) = makeReviewScreen($MW); # Review window has + file & canvas sections paint_Info($MW, $CW, 1); } sub makeReviewScreen { my ($MW) = @_; our $width = $MW->screenwidth - 145; state $zoomLevel = 1; my $RW = $MW->Toplevel(-title => ' Review2'); $RW->geometry("+0+5"); my $LW = $RW->Frame; my $FW = $LW->Scrolled('Frame', -scrollbars => 'e')->pack(-expand +=> '1', -fill => 'y'); my $ZW = $LW->LabFrame(-label => " ZOOM ", -labelside => "acrossto +p", -bg => 'white'); my $CW = $RW->Scrolled('Canvas', -width => $width, -height => '480', -background => 'white', -borderwidth => '3', -scrollbars => 'se', -relief => 'sunken', -scrollregion => [-100,0, 6000,40 +00]); foreach my $zoom (-4, -3, -2, 1, 2, 3) # Make the +diagram zoom buttons here { my $text = ($zoom > 0) ? 100 * $zoom : 100 / $zoom; $text = int($text); $ZW->Radiobutton( -text => "$text Percent", -bg => 'white', -value => $zoom, -variable => \$zoomLevel, -command => sub { zoom($MW, $CW, $zoom); say "make $currentDwg - +$text %"; } )->pack; } $ZW->pack(-pady => 5); $LW->pack(-side => 'left', -fill => 'y', -expand => '1', -ancho +r => 'nw', ); $CW->pack(-side => 'left', -fill => 'both', -expand => '1' ); return( $RW, $FW, $CW); } sub paint_Info # ($MW, $Config) { my ($MW, $CW, $zoom) = @_; $CW->createOval( 30, 30, 15, 15, -outline => 'red', -width => 2, -tags => ['INFO']); my $zfactor = ($zoom > 0) ? $zoom : -1 / $zoom; $CW->scale('all', 0, 0, $zfactor, $zfactor); } sub zoom { my ($MW, $CW, $zoom) = @_; state $already_zoom = 1; my $zoomleft = $zoom / $already_zoom; $already_zoom= $zoom; my $zfactor = ($zoomleft > 0) ? $zoomleft : -1 / $zoomleft; $CW->scale('all', 0, 0, $zfactor, $zfactor); } 1;
========================= Ex. 2 =========================

However, when I have a MW in a separate file which invokes the second window containing the canvas, the ovals don't scale and I get a whole wack of problems, including the original one.

Tk::Error: bad window path name "all" at review2.pm line 97.
Tk callback for .toplevel
Tk callback for .toplevel.frame
Tk callback for .toplevel.frame.frame
Tk callback for .toplevel.frame.frame.pane.frame
Tk callback for .toplevel.frame.frame.pane
Tk callback for .toplevel.frame.frame.ysbslice
Tk callback for .toplevel.frame.frame.ysbslice.corner
Tk callback for .toplevel.frame.labframe.border
Tk callback for .toplevel.frame.labframe.border.frame
Tk callback for .toplevel.frame.labframe.border.frame1
Tk callback for .toplevel.frame1
Tk callback for .toplevel.frame1.ysbslice
Tk callback for .toplevel.frame1.ysbslice.corner
Tk callback for scale
RC::paint_Info at review2.pm line 97
RC::review at review2.pm line 37
main::__ANON__ at Z:\Boolean_OCR_afsheen_3\review_caller.pl line 21
Tk callback for .frame.labframe.border.frame1.button
Tk::__ANON__ at C:/Perl/site/lib/Tk.pm line 250
Tk::Button::butUp at C:/Perl/site/lib/Tk/Button.pm line 175
<ButtonRelease-1>
(command bound to event)
Tk::Error: bad window path name "all" at review2.pm line 110.
Tk callback for scale
Tk callback for .toplevel.frame.labframe.border.frame1.radiobutton
Tk::__ANON__ at C:/Perl/site/lib/Tk.pm line 250
Tk::Radiobutton::Invoke at C:/Perl/site/lib/Tk/Radiobutton.pm line 42
<Button-1>
(command bound to event)
Tk::Error: bad window path name "all" at review2.pm line 110.
Tk callback for scale
Tk callback for .toplevel.frame.labframe.border.frame1.radiobutton1
Tk::__ANON__ at C:/Perl/site/lib/Tk.pm line 250
Tk::Radiobutton::Invoke at C:/Perl/site/lib/Tk/Radiobutton.pm line 42
<Button-1>
(command bound to event)
Tk::Error: bad window path name "all" at review2.pm line 110.
Tk callback for scale
Tk callback for .toplevel.frame.labframe.border.frame1.radiobutton2
Tk::__ANON__ at C:/Perl/site/lib/Tk.pm line 250
Tk::Radiobutton::Invoke at C:/Perl/site/lib/Tk/Radiobutton.pm line 42
<Button-1>
(command bound to event)
Tk::Error: bad window path name "all" at review2.pm line 110.
Tk callback for scale
Tk callback for .toplevel.frame.labframe.border.frame1.radiobutton3
Tk::__ANON__ at C:/Perl/site/lib/Tk.pm line 250
Tk::Radiobutton::Invoke at C:/Perl/site/lib/Tk/Radiobutton.pm line 42
<Button-1>
(command bound to event)

Here is the code:

review_caller.pl
use Tk; use Tk::DialogBox; use Tk::LabEntry; use Tk::Balloon; use Tk::LabFrame; use Tk::Scale; use warnings; use feature ':5.12'; use review2; our $MW = MainWindow->new(-title => 'Title MW'); $MW->geometry("+120+50"); our $FW = $MW->Frame->pack; our $F2 = $FW->LabFrame( -label=> ' This Frame', -relief => 'groove') +->pack( -side => 'left'); our $RC = $F2->Button(-text => 'Review', -command => sub{ RC::review($MW); })->pack(-side => 'left'); MainLoop;
review2.pm (beginning slightly different)
package RC; use Tk; use Tk::PNG; use Tk::LabFrame; use Tk::Radiobutton; use Tk::Pane; use File::Basename; use feature ':5.10'; use strict; our $currentDwg = ''; sub review { my ($MW) = @_; my ($RW, $FW, $CW) = makeReviewScreen($MW); # Review window has + file & canvas sections paint_Info($MW, $CW, 1); } sub makeReviewScreen { my ($MW) = @_; our $width = $MW->screenwidth - 145; state $zoomLevel = 1; my $RW = $MW->Toplevel(-title => ' Review2'); $RW->geometry("+0+5"); my $LW = $RW->Frame; my $FW = $LW->Scrolled('Frame', -scrollbars => 'e')->pack(-expand +=> '1', -fill => 'y'); my $ZW = $LW->LabFrame(-label => " ZOOM ", -labelside => "acrossto +p", -bg => 'white'); my $CW = $RW->Scrolled('Canvas', -width => $width, -height => '480', -background => 'white', -borderwidth => '3', -scrollbars => 'se', -relief => 'sunken', -scrollregion => [-100,0, 6000,40 +00]); foreach my $zoom (-4, -3, -2, 1, 2, 3) # Make the +diagram zoom buttons here { my $text = ($zoom > 0) ? 100 * $zoom : 100 / $zoom; $text = int($text); $ZW->Radiobutton( -text => "$text Percent", -bg => 'white', -value => $zoom, -variable => \$zoomLevel, -command => sub { zoom($MW, $CW, $zoom); say "make $currentDwg - +$text %"; } )->pack; } $ZW->pack(-pady => 5); $LW->pack(-side => 'left', -fill => 'y', -expand => '1', -ancho +r => 'nw', ); $CW->pack(-side => 'left', -fill => 'both', -expand => '1' ); return( $RW, $FW, $CW); } sub paint_Info # ($MW, $Config) { my ($MW, $CW, $zoom) = @_; $CW->createOval( 30, 30, 15, 15, -outline => 'red', -width => 2, -tags => ['INFO']); my $zfactor = ($zoom > 0) ? $zoom : -1 / $zoom; $CW->scale('all', 0, 0, $zfactor, $zfactor); } sub zoom { my ($MW, $CW, $zoom) = @_; state $already_zoom = 1; my $zoomleft = $zoom / $already_zoom; $already_zoom= $zoom; my $zfactor = ($zoomleft > 0) ? $zoomleft : -1 / $zoomleft; $CW->scale('all', 0, 0, $zfactor, $zfactor); } 1;

Any ideas?

Thank you very much for your time,
Perldough

In reply to Re^2: Tk: Scaling canvas objects by perldough
in thread Tk: Scaling canvas objects by perldough

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-19 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found