For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > November 2004 > Tk::Text and Callback ???









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Tk::Text and Callback ???
Thorsten Walenzyk

2004-11-24, 4:00 pm

HI All,

is it possible to establish a callback for a Text widget?
I would like to validate and store the text, if the user has modified the
content of the Textbox.

I have tried

$mw->Text(-command => /&somefunc...)

But it does not work :-((((


Thanks a lot, Thorsten


$_@_.%_

2004-11-24, 4:00 pm


"Thorsten Walenzyk" <Thorsten.Walenzyk@nokia.com> wrote in message-id:
<Gz0pd.30943$g4.580315@news2.nokia.com>
>
>HI All,
>
>is it possible to establish a callback for a Text widget?
>I would like to validate and store the text, if the user has modified the
>content of the Textbox.
>
>I have tried
>
>$mw->Text(-command => /&somefunc...)
>
>But it does not work :-((((
>
>
>Thanks a lot, Thorsten


Could probably use some sort of a binding.

psuedoish code:

bind TEXTwidget (anykeystrokes => sub { &callback(params); });




zentara

2004-11-25, 3:56 pm

On Wed, 24 Nov 2004 14:06:30 GMT, "Thorsten Walenzyk"
<Thorsten.Walenzyk@nokia.com> wrote:

>HI All,
>
>is it possible to establish a callback for a Text widget?
>I would like to validate and store the text, if the user has modified the
>content of the Textbox.
>
>I have tried
>$mw->Text(-command => /&somefunc...)
>But it does not work :-((((
>
>Thanks a lot, Thorsten


This was just asked on http://perlmonks.org

at http://perlmonks.org?node_id=409244

Basically you have 2 choices.
You can use the

$text->editModified() flag which gets set to one, when
the text has been modified, but it dosn't work to well for validation
because each keystroke will trigger the callback, if you
reset the flag. There are probably ways you can work around it.

Or you can take md5sums of the file as it's loaded and when the program
exits, you can test it again, if they differ, you can save the file.

If you trap the DIE and INT signals, you can work out
an auto-save for when someone hits control-c or closes the
program thru the window manager controls.

$SIG{__DIE__} = sub {&save_it(); exit};
$SIG{INT} = sub {&save_it(); exit};

#have your exit button call &save_it too

sub save_it{
# do another get('0.0','end')
# take an md5sum of the text and compare
# it to your original md5sum
# save your text if they differ
}



--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com