How to programmatically "click" the block mask Apply or OK button.
Mostrar comentarios más antiguos
I have created a Block Mask with a Text area. A callback is writing a text to this Text area using set_param(gcb,'VariableText_', 'A little house');
The text is written into the Text Area and clicking the Apply button will save the text. That works Ok, off cause.
What I want to do, and is not able to figure out, is how I programmatically can "click" the Apply or the OK button from the callback?
The purpose is to save the contents of the Text area programmatically.
People have been asking this question before, but I have not found any useful answer.
7 comentarios
Mohammad Sami
el 23 de En. de 2020
If you already have a callback to update the text area, can the callback be updated to save the text directly, instead of having to simulate clicking of the UI button ?
Jakob B. Nielsen
el 23 de En. de 2020
I cant attest to simulink as I dont have experience with it, but I have several matlab GUI's with text fields, which I grab user inputs from thusly;
%The comment edit box on the GUI:
CommentEditBox=uicontrol('Style','Edit','Units', 'normalized','string','No comment','Position',[0.075,0.815,0.145,0.02], 'backgroundcolor',[0.931 0.716 0.684],'CallBack', @CommentEditCallBack, 'HorizontalAlignment','center','visible','on','Parent', GUI);
%The edit function, which automatically fires when any input is given to the uicontrol.
function CommentEditCallBack(~,~)
Comment = get(CommentEditBox,'String');
%Optional: change the box color to green so you know something updated ;)
set(CommentEditBox, 'backgroundcolor',[0.731 0.916 0.684],'HorizontalAlignment','center');
drawnow()
end
I dont know if a similar approach will work in simulink?
Petter Gran-Jansen
el 23 de En. de 2020
Editada: Petter Gran-Jansen
el 23 de En. de 2020
Mohammad Sami
el 24 de En. de 2020
You may have to look outside of matlab to accomplish your goal. Matlab can interface with java, you can use java.awt.Robot to do the clicking. If you have multiple screens, you will need to know which screen has a popup. Also you will need to know the position of the buttons on the screen.
Try and get a handle for the simulink window. then you can find the button and its position on the screen. See this answer on how to get the handle. https://www.mathworks.com/matlabcentral/answers/183928-how-to-get-the-handle-of-simulink-window-in-matlab Worst case scenario you will need to do a screen capture and process it to identify the button location.
Note if you have a high res display and the windows 10 is scaling up the size, there may be differences in the position used in java.awt.Robot and matlab. you may have to trial and error.
Petter Gran-Jansen
el 24 de En. de 2020
Editada: Petter Gran-Jansen
el 24 de En. de 2020
Petter Gran-Jansen
el 24 de En. de 2020
Maximilian Panzik
el 17 de Sept. de 2020
A bit late but maybe this helps somebody:
selected_block_handle = get_param(gcb,'Handle');
dlgs = DAStudio.ToolRoot.getOpenDialogs;
for i=1:length(dlgs) %find dialog of selected block
if class(dlgs(i).getSource) == "Simulink.SLDialogSource"
dialog_block_handle = dlgs(i).getSource.getBlock.Handle;
if dialog_block_handle == selected_block_handle
dlgs(i).apply %'click' apply
end
end
end
Respuestas (1)
Fangjun Jiang
el 17 de Sept. de 2020
0 votos
I don't understand the problem.
If the block has a mask of a text area, when user opens the mask by double_clicking the block, the block dialog window opens, the user can type in any text, then, the user can click the "Apply" or "Ok" button, the text is saved with the block.
Running the command "set_param(gcb,'VariableText_', 'A little house')" will do the same. The text 'A little house' is saved with the block afterwards, without the need to worry about clicking the "Apply" or "Ok" button.
Categorías
Más información sobre Interactive Model Editing en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!