Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

leriksen's scratchpad

by leriksen (Curate)
on Jun 03, 2004 at 20:05 UTC ( #360452=scratchpad: print w/ replies, xml ) Need Help??

I had a problem where I was using an Entry widget, and specifically the -validatecommand option. This takes a callback to a sub that will check that the new data in the Entry widget is OK. Unfortunately, it only calls that callback with data about the change (e.g. the new entry and the original entry), but nothing about which entry widget it came from. And I have dozens of entry widgets in my app, and these changes need to go back to an XML file, and in the right spot in that XML file. A bad solution is to create dozens of callback functions that are all the same, except that they are bound to differnent entry widgets, so I can write to the right part of the XML file.

A better solution was to create a closure that held some info about the piece of XML involved.

sub renderAttribute { my ($self, $xml) = @_; ... # code to create the entry widget for this piece of XML my $entry = $parentFrame->Entry(-textvariable => \$attributeText, -validatecommand => $self->createVal +idateCallback($attributeXML))->pack(); ... } sub createValidateCallback { my ($self, $xmlObj) = @_; return sub { # these params are how Tk will call this callback my ($newValue, $deltaText, $origValue, $deltaIndex, $deltaType) = +@_; return $self->updateXML($xmlObj, $newValue); }; }

Your challenge is that in the closure you have to yield to thread A, and I have no experience in how to do that.

I'll look at that link as soon as I can.

I haven't posted the talk anywhere because it contains a diagram I ripped off verbatim from MJD's new HOP book. I think I'm OK doing a talk with this as a supporting diagram, but a web page is probably just wrong. But I am willing to email it to you, if your willing.

Leif

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2014-08-28 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls