The question
How may I get the list of events and properties for a handle of double type, as a figure
, axes
?
The issue
Matlab documentation says to you to use the WindowButtonDownFcn
, WindowButtonMotionFcn
, and so on in order to listen to whatever happens at your interface. The issue is that this properties are very limited as the following fact:
Keeping Variables in Scope
When MATLAB evaluates function handles, the same variables are in
scope as when the function handle was created. (In contrast, callbacks
specified as strings are evaluated in the base workspace.) This
simplifies the process of managing global data, such as object
handles, in a GUI.
Yes, this is perfect, if you don't have to redefine, add, or remove callbacks from your ButtonDownFcn, because if you do so, you will lose the other function handles variable scopes, as you are declaring them at a new scope which may will certainly not contain your so needed variables.
So one way would be to listen to the events themselves, not to properties that are called when the events are actived, and by doing so, you will not have to bother to redeclare your ButtonDownFcn and how to keep your variables at scope, because the other solutions are very slow to implement!. If I could listen to the events directly, as I do with handle.listener
or addlistener
matlab listening tools, I would not have to bother with that.
One good approach already known
One of the best solutions it seems is this FEX, which empowers the weak matlab WindowButtonDownFcn
, WindowButtonDownFcn
and whatever properties "listeners" function matlab has, so that you can have any amounts of functions listening to changes at the your graphical interface without having to care if your other functions handles will lose their scope variables.
With this I don't need to get the matlab events as it wrappers everything for me. But it still amuses me that matlab lead your users to use a broken feature instead of documenting the better approach and lead people to wrap everything around so that they can use things as they should be.
Information that may be useful.
I know about the meta.class
that will give me all the properties, events and so on that a class have. For one class I have that inherits from a handle
:
>> EventMeta = ?Event
EventMeta =
class with properties:
Name: 'Event'
Description: ''
DetailedDescription: ''
Hidden: 0
Sealed: 0
Abstract: 0
ConstructOnLoad: 0
HandleCompatible: 1
InferiorClasses: {0x1 cell}
ContainingPackage: []
PropertyList: [64x1 meta.property]
MethodList: [29x1 meta.method]
EventList: [2x1 meta.event]
EnumerationMemberList: [0x1 meta.EnumeratedValue]
SuperclassList: [1x1 meta.class]
with that meta I can get the EventList from my Event
class, which are:
>> EventMeta.EventList.Name
ans =
attemptToClick
ans =
ObjectBeingDestroyed
Well, this is not that great thing in this case, since I have implemented it and I know the events it has because I have the source. The thing is, if I can get the metaclass of a figure
(if that is possible), I could have access to its implemented Events
if they are available at the matlab.
See Question&Answers more detail:
os