Need help with canvas text and bindings 
Author Message
 Need help with canvas text and bindings


On Tue, 6 Feb 96 9:08:54 CST

Quote:
>Hi,

>   I am tyring to build a graphical drawing app using (mainly) the
>canvas widget. I'm running into 2 small problems which I'm hoping
>someone can help me with.

>   First, I'm using $canvas->scale to emulate zoom in/out. This
>works fine except for text. All the 'graphical' items scale fine
>but the text stays the same size. Is there a way to correct this
>other than dynamically changing the font size? Is there a better
>way to do zooming?

>   Second, I can't get $canvas->bind to work the way I understand
>that it should. I have these two bindings:

>        $parent->bind($canvas, '<B1>' => sub {....

Hey, I that is an imaginative we to get round the $canvas->bind
binding to canvas items. Normally I recommend:

        $canvas->Tk::bind('<B1>' => sub {....} );

But yours has merit..

Quote:
>        $parent->bind($canvas, '<A><B1>' => sub {...

>   I would like the second binding to be activated when the 'A'
>key is pressed and the first mouse button is pressed. However, the
>first binding is always activated when B1 is pressed regardless of
>key 'A' being pressed or not. The second binding never activates. So,
>where am I missing the boat?

This Works for me...  

#!/usr/local/bin/perl -w
use Tk;

my $mw = MainWindow->new;

my $c  = $mw->Canvas(-width => 100, -height => 100, -takefocus => 1);

$mw->bind($c,'<A><1>',sub { print "A,B1\n" });
$mw->bind($c,'<1>',sub { print "B1\n" });

$c->pack;

$mw->update;

$c->focus;

MainLoop;

Does your canvas have the focus ?
Did you remeber to hold down Shift to get 'A' not 'a'?

--




Sat, 25 Jul 1998 03:00:00 GMT  
 Need help with canvas text and bindings
Hi,

   I am tyring to build a graphical drawing app using (mainly) the
canvas widget. I'm running into 2 small problems which I'm hoping
someone can help me with.

   First, I'm using $canvas->scale to emulate zoom in/out. This
works fine except for text. All the 'graphical' items scale fine
but the text stays the same size. Is there a way to correct this
other than dynamically changing the font size? Is there a better
way to do zooming?

   Second, I can't get $canvas->bind to work the way I understand
that it should. I have these two bindings:

        $parent->bind($canvas, '<B1>' => sub {....
        $parent->bind($canvas, '<A><B1>' => sub {...

   I would like the second binding to be activated when the 'A'
key is pressed and the first mouse button is pressed. However, the
first binding is always activated when B1 is pressed regardless of
key 'A' being pressed or not. The second binding never activates. So,
where am I missing the boat?

   BTW, I'm using Tk-b8 on a Sun Sunos 4.1.3.

   Thanks in advance for the help.

Thomas Rock

--




Sat, 25 Jul 1998 03:00:00 GMT  
 Need help with canvas text and bindings
I think the trick is to reverse the order of the bindings.

Thom did

        $parent->bind($canvas, '<B1>' => sub {....
        $parent->bind($canvas, '<A><B1>' => sub {...

Nick did

        $mw->bind($c,'<A><1>',sub { print "A,B1\n" });
        $mw->bind($c,'<1>',sub { print "B1\n" });

In the first case, the any <B1> is acted upon first, in the second,
the <A><1> is checked in the bind list before the <1> is reached (I
forget whether the app will do just the first found (I think so) or
do all of them.

-- Adam
--------------------------------------------------------------

--------------------------------------------------------------

Quote:

> Date: Tue, 6 Feb 96 15:59:16 GMT



> Organization: via, but not speaking for : Texas Instruments Ltd.
> Subject: Re: Need help with canvas text and bindings

> Content-Length: 1657


> On Tue, 6 Feb 96 9:08:54 CST

> >Hi,

> >   I am tyring to build a graphical drawing app using (mainly) the
> >canvas widget. I'm running into 2 small problems which I'm hoping
> >someone can help me with.

> >   First, I'm using $canvas->scale to emulate zoom in/out. This
> >works fine except for text. All the 'graphical' items scale fine
> >but the text stays the same size. Is there a way to correct this
> >other than dynamically changing the font size? Is there a better
> >way to do zooming?

> >   Second, I can't get $canvas->bind to work the way I understand
> >that it should. I have these two bindings:

> >        $parent->bind($canvas, '<B1>' => sub {....

> Hey, I that is an imaginative we to get round the $canvas->bind
> binding to canvas items. Normally I recommend:

>         $canvas->Tk::bind('<B1>' => sub {....} );

> But yours has merit..

> >        $parent->bind($canvas, '<A><B1>' => sub {...

> >   I would like the second binding to be activated when the 'A'
> >key is pressed and the first mouse button is pressed. However, the
> >first binding is always activated when B1 is pressed regardless of
> >key 'A' being pressed or not. The second binding never activates. So,
> >where am I missing the boat?

> This Works for me...  

> #!/usr/local/bin/perl -w
> use Tk;

> my $mw = MainWindow->new;

> my $c  = $mw->Canvas(-width => 100, -height => 100, -takefocus => 1);

> $mw->bind($c,'<A><1>',sub { print "A,B1\n" });
> $mw->bind($c,'<1>',sub { print "B1\n" });

> $c->pack;

> $mw->update;

> $c->focus;

> MainLoop;

> Does your canvas have the focus ?
> Did you remeber to hold down Shift to get 'A' not 'a'?

--




Sun, 26 Jul 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Need help with canvas text and bindings

2. help binding mouse events to canvas

3. newbie help with anonymous subroutine syntax for text widget key binding

4. Problem with binding events on TkPerl canvas

5. Need help w/ binding to NDBM package

6. Binding mouse event to a canvas

7. Binding to whole Canvas

8. Create a key binding on a canvas?

9. problem binding keys on a canvas

10. Binding to items on Scrolled Canvas

11. Binding Canvas Items question

12. Need some helps with binding

 

 
Powered by phpBB® Forum Software