Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Programmatically creating toolbar shortcut - Help !!!

158 views
Skip to first unread message

SJP

unread,
Jun 26, 2007, 10:28:56 PM6/26/07
to
I need some help regarding programmatically creating a toolbar
shortcut in Matlab. The idea is to have a file that I need to run,
very often, create a shortcut programmatically on the matlab toolbar,
so that I can just click it to run it again.

Now I'm using the folowing code:(eg: a shortcut named CLC doing clc
when clicked).
************************************************
awtinvoke(com.mathworks.mlwidgets.shortcuts.ShortcutUtils,'addShortcut
ToBottom', 'CLC', 'clc', [], 'Toolbar Shortcuts', [] );
************************************************
Now awtinvoke is an undocumented function and there's no info that I
could find on it.

The Problem :

When the file is run for the first time, with this code in it, a
shortcut named "CLC" is created. But the problem starts from the
second time the file is run... eventhough the shortcut is already
there, it'll try to create another shortcut of same name, but since
there is already one, it'll come up with a window to give the new
shortcut that's about to be created a new name. And once you do that,
there'll be a second shortcut on the tool bar that does the exact
same thing. Now if I run this file a million times, I'll end up
having a million shortcuts which is the problem.

So, How do I check if a shortcut is already there - so that I can use
that to control running the code ?

One possible solution that I can think of is to parse the
shortcuts.xml(in the prefdir) file to check if the shortcut already
exist. I don't know how to implement that though.

Could any of the matlab gurus here shed some light into this.

Also, I don't know java...just mentioned it as I have a hunch that
this might involve java.

Thanks
SJP

SJP

unread,
Jun 27, 2007, 8:43:12 AM6/27/07
to
Any help on this guys... please.

Additional info:

I opened the shotcuts.xml file and this is how the CLC shortcut in
the above post look like inside it.

************************************
<FAVORITE>
<label>CLC</label>
<icon><icon>/com/mathworks/mlwidgets/shortcuts/resources/s
hortcut.gif</icon></icon>
<callback>clc</callback>
<editable>true</editable>
</FAVORITE>
************************************

Any suggestions or ideas to actually parse the xml file to look for
the "CLC label inside the xml file would also be helpful.

Thanks
SJP

SJP

unread,
Jun 27, 2007, 9:47:48 AM6/27/07
to
Duh...

Sometimes my brain just doesn't turn on.

Here's the solution if anyone's interested.

1)Go to prefdir,
2)open shortcuts.xml like any other file.
3)textread --
xmlData = textread('shortcuts.xml','%s','delimiter','\n');
4)check using regexp - match for "CLC"
5)if found return status 1 else 0
6)create shortcut only if status 0.
** steps 3 and 4, use any other method of your choice.

Hope this helps anyone searching for this in future.

Josh Weiss

unread,
Jan 17, 2008, 10:23:02 AM1/17/08
to
SJP <kidu.N...@gmailNOSPaM.NOSPAMcom> wrote in message
<ef5b...@webcrossing.raydaftYaTP>...

Hi, I tried this to create a shortcut on the MATLAB toolbar
to run a GUI I've created. It works very well, thank you!

However, each time I reopen MATLAB I get the following
error at the command prompt:

Shortcuts.xml file has been regenerated to the default
shortcuts due to a corrupted
shortcuts.xml file. The original file has been saved in
the prefdir as
shortcuts.xml_recovery.

When I open shortcuts.xml the code for my shortcut appears
as the following:

<FAVORITE>
<label>ICPrograms</label>
<icon>/com/mathworks/mlwidgets/shortcuts/resources/shortcut.
gif</icon>
<callback>ICPrograms</callback>
<editable/>
</FAVORITE>


It appears the code is corrupt because of the "editable"
field missing appropriate signatures. (<editable/> does not
look like correct XML code). Any thoughts on why this is
happening?

My .m code looks like this:
shrtCut = awtinvoke
(com.mathworks.mlwidgets.shortcuts.ShortcutUtils,...
'addShortcutToBottom', 'ICPrograms', 'ICPrograms',

[], 'Toolbar Shortcuts', []);


Thanks in advance!

A second thing (i know this is a lot) any way to make the
shortcut label an image as opposed to text? Ive tried using
imread, and setting the shortcut to the image as I do for
pushbuttons on GUIs but that does not appear to work. Any
input would be appreciated. Thanks guys!

-Josh

Josh

unread,
Feb 27, 2008, 2:15:06 PM2/27/08
to

Does anyone have any suggestions for me about creating the
image on the shortcut? Thanks!

Yair Altman

unread,
Feb 27, 2008, 3:56:02 PM2/27/08
to
Simply edit your shortcuts.xml file and set an empty
<label>. Remember to set the <editable> value to either true
or false (the other problem that you had earlier)

Yair Altman
http://ymasoftware.com

Josh

unread,
Feb 29, 2008, 10:25:03 AM2/29/08
to
"Yair Altman" <altma...@gmailDEL.comDEL> wrote in message
<fq4ip2$9ta$1...@fred.mathworks.com>...


Thank you for the response. However, I need this to work on
any computer. Simply editing the xml code will not do the
trick. Basically, I need to edit the startup.m file where I
create the shortcuts to allow for an image on the shortcut.

Thoughts?

Thanks.

Jesse Hopkins

unread,
May 5, 2008, 10:30:22 AM5/5/08
to
I too had the same file corruption problem. The problem is
passing the empty matricies to the awtinvoke function. It
seemed to me that the following syntax worked, and allowed a
selectable icon.

name = 'My New Shortcut'
evalstr = 'disp(''My New Shortcut'')'
iconfile = 'c:\path\to\icon.gif'
isEditable = 'true'

com.mathworks.mlwidgets.shortcuts.ShortcutUtils,'addShortcutToBottom',name,evalstr,iconfile,'Toolbar
Shortcuts',isEditable);

"Josh " <imah...@hotmail.com> wrote in message
<fq984f$6j5$1...@fred.mathworks.com>...

Josh

unread,
May 9, 2008, 10:47:04 AM5/9/08
to
Yes! That works. Thank you so much! I have been trying so
many things but did not think that the empty matrix was the
issue.

Thank you again! Many points for this solution :)

"Jesse Hopkins" <n...@na.com> wrote in message <fvn5lu$350
$1...@fred.mathworks.com>...

Josh

unread,
May 9, 2008, 10:51:02 AM5/9/08
to
ALthough.. any way to resize the icon so it is larger on
the matlab splash window?


"Jesse Hopkins" <n...@na.com> wrote in message <fvn5lu$350
$1...@fred.mathworks.com>...

Josh

unread,
May 13, 2008, 2:48:03 PM5/13/08
to
Anyone tried using this method in a MAC environment? I
tried transferring my startup.m file to a MAC, and although
the creation file reads the startup file (I can tell this
through simple disp('text') statements), it is not
displaying my shortcuts.

Any thoughts? Is it a java:MAC problem? Or something else?

Thanks

Josh

unread,
May 15, 2008, 9:20:19 AM5/15/08
to
OK I know I am discussing this with myself now.

All of a sudden, without changing ANYTHING in my startup
file, the shortcuts are no longer being created. Anyone
else having this problem? If you go into your shorcuts.xml
file and delete the xml code that creates the shortcuts and
try to run startup again, does that still create new
shortcuts?

Mine doesnt anymore :( Any thoughts? Thanks in advance!


"Josh " <imah...@hotmail.com> wrote in message <g0cnp3$i57
$1...@fred.mathworks.com>...

Josh

unread,
May 15, 2008, 9:27:02 AM5/15/08
to
nevermind. I got it.


"Josh " <imah...@hotmail.com> wrote in message <g0hdaj$e91
$1...@fred.mathworks.com>...

Guillaume Perrault Archambault

unread,
Jul 24, 2009, 8:44:02 AM7/24/09
to
"Josh " <imah...@hotmail.com> wrote in message <g01ocm$1r7$1...@fred.mathworks.com>...
Thanks for this thread it was really helpful to me! ..Did you find out how to resize the image?

ali

unread,
Feb 17, 2010, 3:24:06 PM2/17/10
to
how can &#305; callback toolbar shortcut from the gui
is anyone know about there pls help me
sincerely

ali

unread,
Feb 17, 2010, 3:24:05 PM2/17/10
to
0 new messages