logo       

Re: Fwd: (fwd) binding to a derived canvas widget: msg#00003

Subject: Re: Fwd: (fwd) binding to a derived canvas widget
Steve Lidie <sol0@xxxxxxxxxx> writes:
>Here's how to do it (in Populate):
>
>    $self->{'real_can'} = $self->{'can'}->Subwidget('scrolled');  
>######## more on this later
>    my( @bindtags ) = $self->{'real_can'}->bindtags;
>    $self->{'real_can'}->bindtags( [ @bindtags, 'CanvasDirTree-B1' ] );
>    $self->{'real_can'}->CanvasBind( 'CanvasDirTree-B1', '<Button-1>'  
>=> [\&pick_one, $self] );

All that is fine. But bindtags includes the name of the class already.
This is so that one can assoicate class bindings with it.

So what I intended for one to do was:

   $self->{'real_can'}->CanvasBind( ref($self), '<Button-1>'  ...);

But that is I hope unnecessarily complicated - see below.

>>
>> sub ClassInit
>> {
>>     my ($class, $mw) = @_;
>>     $class->SUPER::ClassInit($mw);

    What that will do by the way is call Canvas::ClassInit.
    This isn't quite a no-op - it calls XYscrollBind
    Which binds mouse wheel and <Up>, <Down> etc. so that 
    scrolls happen (if widget has the focus for keystroke cases).

    Once that has happened - and of course if you don't want 
    that you don't have to call it! 
    We can now add bindings to the class name.
    Which would look like:

    $mw->bind( $class, '<Button-1>', 'pick_one' );
>> }

At this point $mw is _a_ widget (the MainWindow) which is all we need
to talk to core Tk. It isn't a Canvas so no spurious binds are in scope.
And it is called as a "static" method so 1st arg is the class name.
As 'pick_one' is a sub in our class we treat it as a method just use its 
name in the binding.

When a particular _instance_ of the class gets a Button-1 the class binding
is called and the sub is called (as a method) passing the instance 
widget as 1st arg. This achieves the same as original 

     ... '<Button-1>' => [\&pick_one, $self] );

But with the additional advantage that if someone derives from _your_ 
class they can override the pick_one method if your pick_one isn't 
quite what they want.






-++**==--++**==--++**==--++**==--++**==--++**==--++**==
This message was posted through the Stanford campus mailing list
server.  If you wish to unsubscribe from this mailing list, send the
message body of "unsubscribe ptk" to majordomo@xxxxxxxxxxxxxxxxxx



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
qnx.openqnx.dev...    politics.lenini...    audio.emagic.ex...    tex.texinfo.gen...    handhelds.linux...    ietf.sipping/20...    lang.erlang.gen...    cygwin.talk/200...    yellowdog.gener...    mozilla.devel.l...    xfree86.newbie/...    openbsd.ports/2...    db.oracle.devel...    kde.kalyxo.deve...    user-groups.lin...    bbc.cvs/2003-04...    gnu.libtool.bug...    redhat.k12osn/2...    emulators.wine....    freebsd.devel.d...    search.xapian.g...    java.izpack.use...    network.mrtg.us...    windows.total-c...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe