How to detect if passed handle is a handle to an App Designer Application

7 visualizaciones (últimos 30 días)
Background
I have a function which I'm calling from multiple other functions that takes in a Handle to an object, and then returns the properties of that object in a struct to make a copy of it's properties (e.g. the data for a graph in a figure) for later reference in case the handle becomes invalid. Some of these objects may contain large sets of data, and may take a long time to process. The handle it is passed could be almost any object, but if it is a handle to a Figure, a UI Figure, or an App Designer application, I want to be able to use a progress bar.
Issue
If it's a handle to a figure or UI figure, it's easy enough for me to check its class and use the appropriate progress bar with the figure. If it's a handle to an App, however, I have to use the underlying top level UIFigure for the progressbar. The issue is, using class on the App handle returns the name of the App. I intend on making multiple apps that could be referenced, so I don't want to have to keep manually updating the function with each new App I create. Not to mention, I may want to share the code with people / create an internal library where others may have their own Apps with arbitrary names - so it needs to know it's an "App" without knowing what names the App might have. There's no isApp function or equivalent that I'm aware of. I also can't just assume that if it has a UIFigure as a top-level child that it is an App (there are a few odd situations where this may not be the case).
Question
So, the ultimate question here is, how do I test a handle to verify that it is a handle to an App Designer Application?

Respuesta aceptada

Captain Karnage
Captain Karnage el 4 de En. de 2023
Editada: Captain Karnage el 4 de En. de 2023
I just accidentally found out the answer to my own question when troubleshooting a different problem. The following isa command works:
isa(myApp, 'matlab.apps.AppBase')
It was kind of tricky to figure this out as most of the time class will output something like this that I can use. It doesn't do this in the case of a user made class or App - it returns the name of the custom class or app instead. However, I realized after seeing an error message with matlab.apps.AppBase in it meant the App must be a subclass of the superclass matlab.apps.AppBase, I checked the code in App Designer, and sure enough, every App starts with a line like this:
classdef myApp < matlab.apps.AppBase
I felt a little silly that the answer was that easy to find (if I knew where to look), but this confirms that all Apps are subclasses of matlab.apps.AppBase and therefore you can reliably use that with isa to check if it is an App.

Más respuestas (1)

Kevin Holly
Kevin Holly el 4 de En. de 2023
Editada: Kevin Holly el 4 de En. de 2023
metaclass(app).Description
Should return 'Properties that correspond to app components' if it is an app.
where the input "app" in the above function is the handle of the app.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by