Right-click on the LocatorPane graph in Mathematica

When graphics are called with the right mouse button in Mathematica, you get a context menu (cut graphics, copy graphics, save graphics as ...), but for the LocatorPane graphics card, this right-click menu is disabled. How can I call the context menu for LocatorPane graphics using the EventHandler or MouseAction command in Mathematica? What command does this menu create?

LocatorPane[{1, 1}/2, Graphics[{Gray, Disk[]}]] 

I find this code to open the Save As window in math.

 FrontEndExecute[FrontEndToken["SelectionSaveSpecial"]] 

I want the โ€œSave Asโ€ window to open when I right-click on the LocatorPane graph.

+4
source share
2 answers

You said:

I want to call "save graphics as" by right-clicking on the LocatorPane graphics.

I have not yet found a way to do this, but you may not know that you can:

  • select the LocatorPane object by clicking in the right box to the right of it and dragging it to the left.

  • use the menu File > Save Selection As... to save the graphic in the desired format.


I believe the correct option does not work:

 SetOptions[EvaluationNotebook[], ComponentwiseContextMenu -> {"GraphicsBox" -> FEPrivate`FrontEndResource["ContextMenus", "GraphicsBox"], "Graphics3DBox" -> FEPrivate`FrontEndResource["ContextMenus", "Graphics3DBox"], "LocatorPaneBox" -> FEPrivate`FrontEndResource["ContextMenus", "GraphicsBox"], "CellGroup" -> FEPrivate`FrontEndResource["ContextMenus", "CellGroup"], "CellBracket" -> FEPrivate`FrontEndResource["ContextMenus", "CellBracket"], "CellRange" -> FEPrivate`FrontEndResource["ContextMenus", "CellRange"], "CellInsertionPoint" -> FEPrivate`FrontEndResource["ContextMenus", "CellInsertionPoint"]} ]; 

In particular, the value for "LocatorPaneBox" -> been changed to "GraphicsBox" , but it has no visible effect.

On the other hand, changing the value for "GraphicsBox" -> has an effect.

I suspect that since LocatorPane uses mouse input, it captures an attempt to right-click and never passes it to the context menu mechanism. Perhaps disabling the mouse as an input device for LocatorPane fix this, but it doesn't seem practical.


Here is one way to implement your proposal for using "SelectionSaveSpecial" :

 Dynamic[EventHandler[ LocatorPane[{1, 1}/2, Graphics[{Gray, Disk[]}]], {"MouseClicked", 2} :> FrontEndExecute[ SelectionMove[EvaluationNotebook[], All, GeneratedCell]; SelectionMove[EvaluationNotebook[], All, CellContents]; FrontEndToken["SelectionSaveSpecial"] ] ]] 
+2
source

Not a complete answer, but Cell context menus are controlled by the ContextMenu Cell option. You can set the default context menu Cell with the "Graphics" style for any cell you want:

 CellPrint[ Cell[BoxData[SuperscriptBox["x", "2"]], "Output", ContextMenu -> FEPrivate`FrontEndResource["ContextMenus", "Graphics"]]] 
+4
source

All Articles