MATLAB Answers

Amy
0

Create non-editable UI controls in a GUI with the figure toolbar

Amy
さんによって質問されました 2013 年 2 月 6 日
I am trying to create a GUI that contains plots of data and UI controls that control what is plotted. I would like the GUI to include the figure toolbar so that the user can modify the plot annotations and such. The problem I am having is that when the button in the toolbar to edit objects in the plot is pushed, the user can then select the uicontrols and possibly move or delete them corrupting the whole GUI. Is it possible to set the uicontrols up so that they cannot be moved or deleted, using either a mouse click callback or some sort of event listener? The code below will illustrate the problem. Execute the code, then click the toolbar button to edit the plot (white arrow). When you select the popup menu, you can then move it or even delete it. I would like the toolbar to be there so that the user can edit things like the plot title and x/y labels.
h = figure;
x = linspace(0,10,10);
y{1} = sqrt(x);
y{2} = x;
y{3} = x.^2;
plot(x,y{1})
ax = gca;
set(ax,'UserData',{x,y})
F1 = @(h)get(h,'UserData');
extractYval = @(d,I)d{2}{I};
uicontrol('style','popupmenu','String',{'sqrt(x)','x','x^2'},'Value',1,...
'Callback',@(hObject,eventdata)set(get(ax,'Children'),'ydata',extractYval(get(ax,'UserData'),get(hObject,'Value'))))
set(h,'toolbar','figure')

  2 件のコメント

Sean de Wolski
2013 年 2 月 7 日
Oh, so your opening plot tools and moving it inside of there?
Do you want the user to be able to edit the plot period? It migth just be easier to turn plottools off.
Amy
2013 年 2 月 7 日
I would like the user to have the ability to edit the plot, add x-y labels, zoom and rotate, and such. My workaround is to have a button that will extract the plot to a new figure window for editing once the user has the desired data plotted.

サインイン to comment.

2 件の回答

Image Analyst
回答者: Image Analyst
2013 年 2 月 7 日

I'm not sure I know what you're talking about. I have GUIs on all my applications and it's not possible for the user to move the control to a different location, or to remove the control from the GUI. They can only interact with them in the manner in which they were designed. How are your users able to move or delete things like buttons, checkboxes, sliders, listboxes, axes, etc. from your GUI while it's running and "corrupt" it?

  1 件のコメント

Amy
2013 年 2 月 7 日
I've just edited my question to include sample code.

サインイン to comment.


Sean de Wolski
回答者: Sean de Wolski
2013 年 2 月 6 日
編集済み: Sean de Wolski
2013 年 2 月 7 日

Just set their 'enable' property to 'inactive'.
More per clarifications.
Your event listener idea and current workaround are certainly good. There are a few more possibilities I can think of.
  • One is to modify the toolbar so that you wrap around plottools. Right now if the user clicks the plottools toggle button, the default behavior occurs. What you could do is have toggle on button store information about what you care about and then make it invisible etc and then call plottools. The toggle off button would restore it etc.
  • The other option is to use a 'PreSet' addlistener to listen to changes in the WindowButton_xfcns.
When plottools is enabled they become something like this:
get(gcf,'WindowButtonUpFcn')
ans =
@localModeWindowButtonUpFcn
[1x1 uitools.uimode]
{2x1 cell }
So you could detect when this change is going to occur and uicontrols, etc.

  3 件のコメント

Amy
2013 年 2 月 7 日
If the enable property is 'inactive', the user can't interact with them.
Sean de Wolski
2013 年 2 月 7 日
I guess I ask the same question as IA then. What do you want? Shwo a picture and code example. Typically the user can't move things unless you give them a really generous callback.
Sean de Wolski
2013 年 2 月 7 日
See More

サインイン to comment.



Translated by