필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Amy
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
Sean de Wolski 2013년 2월 7일
편집: 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
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.

댓글을 달려면 로그인하십시오.

답변 (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?

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
Sean de Wolski
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by