MATLAB Answers

How do i determine if the uiaxes toolbar is active?

12 views (last 30 days)
I am developing an app which grabs points from a uiaxes object based on mouse-clicks within the uiaxes. However, if I select one of the uiaxes toolbar tools (eg zoom or pan) then I need to suspend interpreting mouse clicks for grabbing points until I have stopped using the uiaxes toolbar. How do I do this?
Basically I need to know if the UIAxes toolbar is currently active.
Thanks in advance for any help.

  0 Comments

Sign in to comment.

Accepted Answer

Harsha Priya Daggubati
Harsha Priya Daggubati on 24 Mar 2020
Hi,
I suggest using 'SelectionChangedFcn' callback. This is notified whenever a state button(zoom/pan) is clicked, and you can know which button is clicked. You can also write your custom MATLAB code in the callback associated.
Refer the documentation link for more details:

  3 Comments

Hugh Stone
Hugh Stone on 24 Mar 2020
Thanks Harsha,
That is exactly what I would like to do but when I look in AppDesigner, there is no "ButtonGroup" underneath the UIAxes object (see picture below) and the UIAxes object has no callbacks itself. So... I can't create the callback like I do for other button groups etc., where I add the callback in "Design View" and then fill the code in in "Code View".
I looked at the link you sent and can see how to add a callback to the toolbar purely by coding but don't know how / where to add this code. I thought that callbacks were selected in Design View, which then gave a stub to add code into in Code View.
Can I add a callback directly in Code View without first adding it in Design View?
Thanks in advance for any further help.
Regards,
Hugh
Harsha Priya Daggubati
Harsha Priya Daggubati on 26 Mar 2020
Hi,
Yes you were right about adding callbacks in Appdesigner. As of now, app designer doesnot support 'axtoolbar'. Possible workaround would be to develop you can export your app to MATLAB Code, and add axes toolbar manually. You can check the attached code snippet.
classdef app1_exported < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UIAxes matlab.ui.control.UIAxes
Button matlab.ui.control.Button
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
% Button pushed function: Button
function ButtonPushed(app, event)
end
function myCallback(app,event)
disp('Selection Changed')
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [108 164 300 185];
tb1 = axtoolbar(app.UIAxes,{'zoomin','pan'},'SelectionChangedFcn',@myCallback);
tb1.SelectionChangedFcn = createCallbackFcn(app, @myCallback, true);
% Create Button
app.Button = uibutton(app.UIFigure, 'push');
app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
app.Button.Position = [109 403 100 22];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app1_exported
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
classdef app1_exported < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
UIAxes matlab.ui.control.UIAxes
Button matlab.ui.control.Button
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
end
% Button pushed function: Button
function ButtonPushed(app, event)
end
function myCallback(app,event)
disp('Selection Changed')
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [108 164 300 185];
tb1 = axtoolbar(app.UIAxes,{'zoomin','pan'},'SelectionChangedFcn',@myCallback);
tb1.SelectionChangedFcn = createCallbackFcn(app, @myCallback, true);
% Create Button
app.Button = uibutton(app.UIFigure, 'push');
app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);
app.Button.Position = [109 403 100 22];
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app1_exported
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
% Execute the startup function
runStartupFcn(app, @startupFcn)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
Hope this helps!

Sign in to comment.

More Answers (0)

Sign in to answer this question.