Thread Subject: Event queuing , callbacks and buttons

Subject: Event queuing , callbacks and buttons

From: Johannes

Date: 12 Feb, 2008 09:42:01

Message: 1 of 6

Hello,

I've a gui with a button which increases an interpolation
number. The button then calls a plot function which takes
about 2 seconds to draw. So when the user presses the button
several times the value increases and the plot function is
also called several times which takes really a long time.
What I want to do is to only execute the last call of the
interpolation button. In other words the preceeding calls
should be canceled and only the last call should be
processed. I've read a lot in the newsgroup but didn't find
a satisfying answer. I also have no while or for loops in my
plot function. So the question is, how can I stop the
running plot function?

Remarks: I don't want to cancel upcoming events I only want
to process the latest call of the interpolation button.

I hope I made myself clear and would appreciate any answer.

Thanks and greetings,
Johannes.

Subject: Event queuing , callbacks and buttons

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 12 Feb, 2008 17:21:51

Message: 2 of 6

In article <forpl9$8cv$1@fred.mathworks.com>,
Johannes <RudiRocker@gmx.net> wrote:

>I've a gui with a button which increases an interpolation
>number. The button then calls a plot function which takes
>about 2 seconds to draw. So when the user presses the button
>several times the value increases and the plot function is
>also called several times which takes really a long time.
>What I want to do is to only execute the last call of the
>interpolation button.

The thread "callbacks / recursion limit", Jan 14,
roberson@ibd.nrc-cnrc.gc.ca, might provide you with some ideas
on how to handle this.


I see you are using the Mathworks news reader, so the following
link will show up split over two lines for you; you will
need to paste the pieces into your address bar.

http://groups.google.ca/group/comp.soft-sys.matlab/browse_thread/thread/c385540fcf4832e8
--
  "Prevention is the daughter of intelligence."
                                              -- Sir Walter Raleigh

Subject: Event queuing , callbacks and buttons

From: Johannes

Date: 12 Feb, 2008 22:20:18

Message: 3 of 6

> The thread "callbacks / recursion limit", Jan 14,
> roberson@ibd.nrc-cnrc.gc.ca, might provide you with some ideas
> on how to handle this.
>
>
> I see you are using the Mathworks news reader, so the following
> link will show up split over two lines for you; you will
> need to paste the pieces into your address bar.
>
> http://groups.google.ca/group/comp.soft-
sys.matlab/browse_thread/thread/c385540fcf4832e8
> --
> "Prevention is the daughter of intelligence."
> -- Sir Walter Raleigh

Thanks for your answer. But I've already read the thread and I couldn't figure
out how it should help me. What I want to do is that when the button gets hit
twice it should only execute the last callback and the first callback should be
interrupted and never continued again. So wouldn't limitating the recursion
limit cause an interruption of the last callback?

Greetings,
Johannes

 

Subject: Event queuing , callbacks and buttons

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 12 Feb, 2008 22:44:08

Message: 4 of 6

In article <fot632$pgq$1@fred.mathworks.com>,
Johannes <RudiRocker@gmx.net> wrote:
>What I want to do is that when the button gets hit
>twice it should only execute the last callback and the first callback should be
>interrupted and never continued again.

It is easier to arrange it the other way around.

Have a global flag "interrupted" that you clear before any of
the activity begins.

You get a click, you enter the callback
routine. You test the flag: if it is clear, then you fetch
the current parameter values and operate on them, checking
from time to time whether the flag is still clear. If the flag
never becomes set before you have reached the end of the calculation,
then you were not interrupted and you should finish up normally.

When you test the flag the first time upon entry into the routine
and you find it set, then you fetch the current parameter values
(CurrentPoint, gcbo, whatever you need that identifies that
click uniquely) and store them in a global variable, and you leave
the flag set and you exit.

When you test the flag in the middle of the calculation routine
and you find that it has been set, you abandon the current calculation,
head back to the top of the routine, fetch the parameter values
from the global variable, clear the flag, and start the
calculation again.

If you try to do it the other way around, cancelling the
"older" incarnations but continuing to run the newest, I think
you will find it harder to decide whether you are in the "newest"
or not.
--
  "Every intellectual product must be judged from the point of view
  of the age and the people in which it was produced."
                                              -- Walter Horatio Pater

Subject: Event queuing , callbacks and buttons

From: Johannes

Date: 13 Feb, 2008 15:15:28

Message: 5 of 6

Thanks for your answer.

I also thought of a solution like that but I think it's not
a very nice one and has one main problem. My executing
function invokes several other functions and also uses some
toolboxes. So if I would like to implement that solution I
would also have to implement it in the toolboxes, because
they are the ones which need some time to execute.
So I assume there isn't a possibility to control the
callbacks in queue and cancel an executing function?

Greetings,
Johannes

Subject: Event queuing , callbacks and buttons

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 13 Feb, 2008 19:27:05

Message: 6 of 6

In article <fov1ig$enp$1@fred.mathworks.com>,
Johannes <RudiRocker@gmx.net> wrote:

>I also thought of a solution like that but I think it's not
>a very nice one and has one main problem. My executing
>function invokes several other functions and also uses some
>toolboxes. So if I would like to implement that solution I
>would also have to implement it in the toolboxes, because
>they are the ones which need some time to execute.
>So I assume there isn't a possibility to control the
>callbacks in queue and cancel an executing function?

In a number of the internal Matlab functions, the ones
written in something other than Matlab, there are no checks
to see if the user (or anything else) has requested an interruption.
The only way to abort those time-consuming functions is to shoot
the entire Matlab process.
--
  "Beauty, like all other qualities presented to human experience,
  is relative; and the definition of it becomes unmeaning and
  useless in proportion to its abstractness." -- Walter Pater

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com