Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Notifying user à la Outlook

Subject: Notifying user à la Outlook

From: Luc Le Blanc

Date: 18 Feb, 2014 16:18:13

Message: 1 of 9

I need to notify the user certain computations need to be re-done after changes he/she made. A message box is annoying because it needs to be dismissed. A message in a status bar at the base of the main window would need to be cleared but relevance is hard to determine. A better option would be a notification à la Outlook, as when you receive a new e-mail: a message pops up and disappears by itself after 1-2 s. Is there such a feature in Matlab?


--
Luc Le Blanc

Subject: Notifying user la Outlook

From: Steven Lord

Date: 18 Feb, 2014 16:54:58

Message: 2 of 9


"Luc Le Blanc" <leblanc.luc@ireq.ca> wrote in message
news:le0145$e5g$1@newscl01ah.mathworks.com...
> I need to notify the user certain computations need to be re-done after
> changes he/she made. A message box is annoying because it needs to be
> dismissed. A message in a status bar at the base of the main window would
> need to be cleared but relevance is hard to determine. A better option
> would be a notification la Outlook, as when you receive a new e-mail: a
> message pops up and disappears by itself after 1-2 s. Is there such a
> feature in Matlab?

Use a non-modal message box and create a TIMER to DELETE it after a few
seconds, or directly email the user using SENDMAIL?

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Notifying user à la Outlook

From: Eric Sampson

Date: 18 Feb, 2014 18:37:08

Message: 3 of 9

"Luc Le Blanc" wrote in message <le0145$e5g$1@newscl01ah.mathworks.com>...
> I need to notify the user certain computations need to be re-done after changes he/she made. A message box is annoying because it needs to be dismissed. A message in a status bar at the base of the main window would need to be cleared but relevance is hard to determine. A better option would be a notification à la Outlook, as when you receive a new e-mail: a message pops up and disappears by itself after 1-2 s. Is there such a feature in Matlab?
>
>
> --
> Luc Le Blanc

If you emailed Yair Altman, who maintains the excellent 'Undocumented MATLAB' blog (http://undocumentedmatlab.com/), I bet he could give you some example code on how to create a Java balloon tip using MATLAB's ability to create Java components...

Subject: Notifying user à la Outlook

From: Yair Altman

Date: 18 Feb, 2014 19:20:08

Message: 4 of 9

"Eric Sampson" wrote in message <le098k$7o7$1@newscl01ah.mathworks.com>...
> "Luc Le Blanc" wrote in message <le0145$e5g$1@newscl01ah.mathworks.com>...
> > I need to notify the user certain computations need to be re-done after changes he/she made. A message box is annoying because it needs to be dismissed. A message in a status bar at the base of the main window would need to be cleared but relevance is hard to determine. A better option would be a notification à la Outlook, as when you receive a new e-mail: a message pops up and disappears by itself after 1-2 s. Is there such a feature in Matlab?
> >
> >
> > --
> > Luc Le Blanc
>
> If you emailed Yair Altman, who maintains the excellent 'Undocumented MATLAB' blog (http://undocumentedmatlab.com/), I bet he could give you some example code on how to create a Java balloon tip using MATLAB's ability to create Java components...

Thanks for the serve...
Of course it's possible: http://undocumentedmatlab.com/blog/setting-system-tray-popup-messages/
http://mathworks.com/matlabcentral/fileexchange/23299-systray-set-get-system-tray-icons-on-your-computers-desktop

Yair Altman
http://UndocumentedMatlab.com
 

Subject: Notifying user la Outlook

From: Luc Le Blanc

Date: 3 Mar, 2014 21:30:08

Message: 5 of 9

"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <le0390$k0a$1@newscl01ah.mathworks.com>...
>
> "Luc Le Blanc" <leblanc.luc@ireq.ca> wrote in message
> news:le0145$e5g$1@newscl01ah.mathworks.com...
> > I need to notify the user certain computations need to be re-done after
> > changes he/she made. A message box is annoying because it needs to be
> > dismissed. A message in a status bar at the base of the main window would
> > need to be cleared but relevance is hard to determine. A better option
> > would be a notification la Outlook, as when you receive a new e-mail: a
> > message pops up and disappears by itself after 1-2 s. Is there such a
> > feature in Matlab?
>
> Use a non-modal message box and create a TIMER to DELETE it after a few
> seconds, or directly email the user using SENDMAIL?

Back from holidays, with this problem pending. I tried the seemingly simple timed msgbox solution, gleaning partial examples in Mathworks forums.

I first open the msgbox outside the time, because otherwise h is unknown, and thus cannot be passed to the TimerFcn callback. But in any case, Matlab replies that "Undefined function or variable" for both h and t.

function TimedAlert( varargin )
h = msgbox( varargin );
t = timer( 'StartFcn', 'disp([]);', 'TimerFcn', '{@AlertTimeout, h}', 'StopFcn', 'delete(t);', 'Period', 2 );
start(t);

function AlertTimeout( varargin )
% I have yet to determine how to recover h
if ishandle(h)
    delete(h);
end

Subject: Notifying user a la Outlook

From: Luc Le Blanc

Date: 7 Mar, 2014 20:25:08

Message: 6 of 9

I was able to make this work:

function TimedWarning( text )

h = warndlg( text, 'Warning' );

t = timer;
t.StartFcn = @(~,~) disp([]);
t.TimerFcn = @(~,~) delete(h);
t.StopFcn = @(~,~) delete(t);
t.StartDelay = 2;

start(t);

The only problem I have is when the user clicks OK on the warning before the timer ends: i get an error because the handle passed to delete is no longer valid. There's probably a way to prevent that with a callback, but I couldn't figure how.

--
Luc Le Blanc

Subject: Notifying user a la Outlook

From: Steven Lord

Date: 7 Mar, 2014 20:59:28

Message: 7 of 9


"Luc Le Blanc" <leblanc.luc@ireq.ca> wrote in message
news:lfd9v4$bui$1@newscl01ah.mathworks.com...
> I was able to make this work:
>
> function TimedWarning( text )
>
> h = warndlg( text, 'Warning' );
>
> t = timer;
> t.StartFcn = @(~,~) disp([]);
> t.TimerFcn = @(~,~) delete(h);
> t.StopFcn = @(~,~) delete(t);
> t.StartDelay = 2;
>
> start(t);
>
> The only problem I have is when the user clicks OK on the warning before
> the timer ends: i get an error because the handle passed to delete is no
> longer valid. There's probably a way to prevent that with a callback, but
> I couldn't figure how.

Either wrap the DELETE call in a TRY/CATCH (possibly checking to make sure
it was the "there's no such object" error and RETHROWing if it was not) or
use ISHGHANDLE to check if the dialog box's handle is still valid. In either
case you won't be able to specify the TimerFcn as an anonymous function, but
you can specify it as a subfunction inside TimedWarning.m.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Notifying user a la Outlook

From: Luc Le Blanc

Date: 11 Mar, 2014 13:10:16

Message: 8 of 9

"Steven Lord" <Steven_Lord@mathworks.com> wrote in message <lfdbv9$hom$1@newscl01ah.mathworks.com>...
>
> "Luc Le Blanc" <leblanc.luc@ireq.ca> wrote in message
> news:lfd9v4$bui$1@newscl01ah.mathworks.com...
> > I was able to make this work:
> >
> > function TimedWarning( text )
> >
> > h = warndlg( text, 'Warning' );
> >
> > t = timer;
> > t.StartFcn = @(~,~) disp([]);
> > t.TimerFcn = @(~,~) delete(h);
> > t.StopFcn = @(~,~) delete(t);
> > t.StartDelay = 2;
> >
> > start(t);
> >
> > The only problem I have is when the user clicks OK on the warning before
> > the timer ends: i get an error because the handle passed to delete is no
> > longer valid. There's probably a way to prevent that with a callback, but
> > I couldn't figure how.
>
> Either wrap the DELETE call in a TRY/CATCH (possibly checking to make sure
> it was the "there's no such object" error and RETHROWing if it was not) or
> use ISHGHANDLE to check if the dialog box's handle is still valid. In either
> case you won't be able to specify the TimerFcn as an anonymous function, but
> you can specify it as a subfunction inside TimedWarning.m.

t.TimerFcn = @(~,~) [ try delete(h); catch end]

and such variants reports an illegal use of reserved keyword "try". Any suggestion on syntax? Passing h to a callback fails if h no longer exists.


--
Luc Le Blanc

Subject: Notifying user a la Outlook

From: Steven Lord

Date: 11 Mar, 2014 13:51:37

Message: 9 of 9


"Luc Le Blanc" <leblanc.luc@ireq.ca> wrote in message
news:lfn1vo$ejq$1@newscl01ah.mathworks.com...
> "Steven Lord" <Steven_Lord@mathworks.com> wrote in message
> <lfdbv9$hom$1@newscl01ah.mathworks.com>...
>>
>> "Luc Le Blanc" <leblanc.luc@ireq.ca> wrote in message
>> news:lfd9v4$bui$1@newscl01ah.mathworks.com...
>> > I was able to make this work:
>> >
>> > function TimedWarning( text )
>> >
>> > h = warndlg( text, 'Warning' );
>> >
>> > t = timer;
>> > t.StartFcn = @(~,~) disp([]);
>> > t.TimerFcn = @(~,~) delete(h);
>> > t.StopFcn = @(~,~) delete(t);
>> > t.StartDelay = 2;
>> >
>> > start(t);
>> >
>> > The only problem I have is when the user clicks OK on the warning
>> > before the timer ends: i get an error because the handle passed to
>> > delete is no longer valid. There's probably a way to prevent that with
>> > a callback, but I couldn't figure how.
>>
>> Either wrap the DELETE call in a TRY/CATCH (possibly checking to make
>> sure it was the "there's no such object" error and RETHROWing if it was
>> not) or use ISHGHANDLE to check if the dialog box's handle is still
>> valid. In either case you won't be able to specify the TimerFcn as an
>> anonymous function, but you can specify it as a subfunction inside
>> TimedWarning.m.
>
> t.TimerFcn = @(~,~) [ try delete(h); catch end]
>
> and such variants reports an illegal use of reserved keyword "try". Any
> suggestion on syntax? Passing h to a callback fails if h no longer exists.

Yes. As I said:

> > In either case you won't be able to specify the TimerFcn as an anonymous
> > function, but you can specify it as a subfunction inside TimedWarning.m.

Although now that I reread that it's a bit misleading. You _can_ use an
anonymous function, but it will need to call a subfunction.


t.TimerFcn = @(~, ~) tryToDeleteDialog(h);

function tryToDeleteDialog(dialogHandle)
try
    delete(dialogHandle)
catch % May want to catch the exception and check that its identifier is
what you expect
end

% or
if ishghandle(dialogHandle)
    delete(dialogHandle)
end

The latter does have a potential race condition; if the user were able to
close the dialog between the ISHGHANDLE call returning true and the DELETE
call, it would error. I wouldn't worry, though, as there's going to be only
an extremely short window (if a window at all) where this could occur. But
for the former you should really check and make sure that the exception you
receive is because the dialog has already been closed and not because of
some unrelated cause.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

No tags are associated with this thread.

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.

Contact us