Discussion:
Disable datacursor context-menu
(too old to reply)
Bobane
2008-07-31 17:30:21 UTC
Permalink
Hi,
I would like to disable the context-menu which appears when
you right-click on a data cursor marker. I am writing an
application for third-party use, and I particularly do not
want the users of my application to be 'editing/selecting
the text update function'. (If it's there, someone will use
it!). Unfortunately, 'datacursormanager' class objects do
not have a 'hittest' property, so I can't use that.
It seems the data cursor object only has 4 properties:
Enable: {}
SnapToDataVertex: {}
DisplayStyle: {2x1 cell}
UpdateFcn: {}
None of these will do what I need.
Does anyone know how to either selectively disable some of
the context-menu items, or disable the whole context menu?

Many thanks in advance.

Bobane
Phil Goddard
2008-08-04 04:34:02 UTC
Permalink
The data cursor is an hggroup object.
So after creating one you could do somthing like

% Get the handle of the created object, using for example:
h = findall(gcf,'Type','hggroup');

% Then clear it's UIContextMenu
set(h,'UIContextMenu',[]);

Right clicking will now do nothing.
Left clicking will continue to move the Data Cursor as
before.

Phil.
redrothko
2008-08-22 16:10:03 UTC
Permalink
Post by Phil Goddard
The data cursor is an hggroup object.
So after creating one you could do somthing like
h = findall(gcf,'Type','hggroup');
Are you absolutely sure that data cursors are hggroup
objects? This is really throwing me off. I tried exactly
what you suggested, but it appears that data cursors are NOT
hggroup objects.

For instance, the following lines return 'false'.

figure;
h = datacursormode(gcf);
isa(h,'hggroup')

Nevertheless, it is true that the data cursor has a property
called 'UIContextMenu'. However, when I set this property to
[], the context menu still appears with the right mouse click.

It would be nice hear a solution to this problem.
Post by Phil Goddard
% Then clear it's UIContextMenu
set(h,'UIContextMenu',[]);
Right clicking will now do nothing.
Left clicking will continue to move the Data Cursor as
before.
Phil.
Walter Roberson
2008-08-22 18:45:09 UTC
Permalink
Post by redrothko
Post by Phil Goddard
The data cursor is an hggroup object.
Are you absolutely sure that data cursors are hggroup
objects?
I don't know about other versions, but in R2007a and R2008a,
a datacursormode object is class graphics.datacursormanager
Post by redrothko
Post by Phil Goddard
h = datacursormode(gcf);
class(h)
ans =

graphics.datacursormanager
Post by redrothko
Post by Phil Goddard
isa(h,'graphics.datacursormanager')
ans =

1
--
Q = quotation(rand);
if isempty(Q); error('Quotation server filesystem problems')
else sprintf('%s',Q), end
redrothko
2008-08-22 19:29:02 UTC
Permalink
Post by Walter Roberson
I don't know about other versions, but in R2007a and R2008a,
a datacursormode object is class graphics.datacursormanager
Hello Walter,

Thank you for confirming that. In my version of Matlab, I also get the result
that a datacursormode object is of type GRAPHICS.DATACURSORMANAGER.

Unfortunately, this class doesn't seem to be documented well. DOC
DATACURSORMODE only discusses the few properties which are returned by
the GET command. In particular, the "UIContextMenu" property which Phil
Goddard suggested above is not mentioned. However, when I type in

figure;
h = datacursormode(gcf);
get(h,'UIContextMenu')

Matlab reports this to me: uicontextmenu.

So apparently, the GRAPHICS.DATACURSORMANAGER class has more
properties than both the GET method and the Matlab documentation let on. Is
there a way to find out which classes the data cursor object inherits from?

On another note, there is a strange key press behavior which figures exhibit
once you turn their data cursor mode on. (Try this with any figure you have.)
All keys except Alt/Shift/Control will minimize the figure. Is there a way to
suppress this? There are even stranger side effects of the data cursor mode
when it is turned on in a GUI. That is an even bigger problem which I have
with the data cursor right now, but I think this is enough for this post.

I am grateful for your pointers.
redrothko
2008-08-25 15:45:04 UTC
Permalink
Ahh here we go!

Create a data cursor:
plot(1,1);
h = datacursormode(gcf);
set(h,'Enable','on')

Now set each context menu item (object of type "uimenu") to
be invisible:
set(get(get(h,'UIContextMenu'),'Children'),'Visible','off')

Loading...