Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

leriksen's scratchpad

by leriksen (Curate)
on Jun 03, 2004 at 20:05 UTC ( [id://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.


Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-17 19:17 GMT
Find Nodes?
    Voting Booth?

    No recent polls found