How do i determine if the uiaxes toolbar is active?

15 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.
  2 Comments
Chloe Lynch
Chloe Lynch on 16 Jul 2020
Hello, did you ever solve this? I’m having the same issue! :/
Hugh Stone
Hugh Stone on 17 Jul 2020
Hi Chloe,
I think the only solution is to export the code (I guess once you've finished with everything else in AppDesigner) and add in the "SelectionChangedFcn" callback manually as suggested by Harsha.
Hugh

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
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)

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!