Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Tk: Scaling canvas objects

by zentara (Archbishop)
on Jul 24, 2012 at 16:42 UTC ( [id://983467]=note: print w/replies, xml ) Need Help??


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

When I run your review2.pm, I get your error. But I added a line which shows the problem. I can't figure out why it allowed you to create an Oval to begin with.?
sub paint_Info{ #this shows the problem my ($MW, $CW, $zoom) = @_; print "\n\n@_\n\n"; $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); }
When you print out @_, you get
MainWindow=HASH(0x7b8078) Tk::Frame=HASH(0xe2bfb0) 1
You then take $_1 and try to run Canvas methods on it. Scale will not run on a Frame, that is a Canvas method.

It just dawned on me! Your Frame is the Scrolled Frame the Canvas is in. Try getting the real canvas in your module. This fixes it! :-)

sub paint_Info # ($MW, $Config) { my ($MW, $CW, $zoom) = @_; print "\n\n@_\n\n"; my $canvas = $CW->Subwidget('canvas'); $canvas->createOval( 30, 30, 15, 15, -outline => 'red', -width => 2, -tags => ['INFO']); my $zfactor = ($zoom > 0) ? $zoom : -1 / $zoom; $canvas->scale('all', 0, 0, $zfactor, $zfactor); }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^4: Tk: Scaling canvas objects
by perldough (Sexton) on Jul 24, 2012 at 19:23 UTC

    That fix works for me too! Thanks! =D

    Sorry, but I don't think I understand why this is necessary. Why didn't I have this problem when I had the whole thing running out of a single file?

    Thanks,
    Perldough
      I'm not sure why it works in a monolithic script, but not in your modules. It must have something to do with how the Scrolled widget works, and your module's @ISA. This is not the only time you will encounter this with Scrolled Canveses or Text widgets. Most of the Scrolled widget's internals get passed on, but some don't. The most notable of these is using Balloons on Scrolled widgets.... you most often need to bind to the actual Subwidget, the Scrolled widget is finicky.

      By the way, if you are serious about zooming, rotating, and scaling on a Canvas, you should look at Tk::Zinc, it still works well even if it isn't being maintained.


      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-16 23:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found