Mathematica 中 LocatorPane 图形上的右键单击菜单

发布于 2024-11-10 13:07:27 字数 419 浏览 6 评论 0原文

在 Mathematica 中右键单击图形时,您会看到一个上下文菜单(剪切图形、复制图形、将图形另存为...),但对于 LocatorPane 图形,此右键单击菜单被禁用。 如何在 Mathematica 中使用 EventHandler 或 MouseAction 命令调用 LocatorPane 图形的上下文菜单?什么命令创建这个菜单?

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

我发现这段代码可以在mathematica 中打开“另存为”窗口。

FrontEndExecute[FrontEndToken["SelectionSaveSpecial"]]

我希望当我右键单击 LocatorPane 图形时打开“另存为”窗口。

When graphics are right-clicked in Mathematica you get a context menu (cut graphics, copy graphics, save graphics as,...), but for a LocatorPane Graphic this right click menu is disable.
How can I call a context menu for a LocatorPane graphics with an EventHandler or a MouseAction command in Mathematica? What command creates this menu?

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

I find this code to open "Save as" Window in mathematica.

FrontEndExecute[FrontEndToken["SelectionSaveSpecial"]]

I want when i right click a LocatorPane graphic the "Save As" window open.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九命猫 2024-11-17 13:07:27

不是完整的答案,但 Cell 的上下文菜单由 CellContextMenu 选项控制。您可以为您想要的任何单元格设置样式为 "Graphics"Cell 的默认上下文菜单:

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

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

CellPrint[
 Cell[BoxData[SuperscriptBox["x", "2"]], "Output", 
  ContextMenu -> 
   FEPrivate`FrontEndResource["ContextMenus", "Graphics"]]]
余生再见 2024-11-17 13:07:27

你说:

我想通过右键单击 LocatorPane 图形来调用“图形另存为”。

我还没有找到一种方法来做到这一点,但您可能不知道您可以:

  1. 通过单击右侧的空白区域并向左拖动来选择 LocatorPane 对象。

  2. 使用菜单文件>将所选内容另存为... 以所需格式保存图形。


我认为正确的选项似乎不起作用:

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"]}
  ];

具体来说,"LocatorPaneBox" -> 的值已更改为 "GraphicsBox" 但没有明显效果。

另一方面,更改 "GraphicsBox" -> 的值确实有效果。

我怀疑因为 LocatorPane 使用鼠标输入,所以它捕获右键单击尝试,并且从不将其传递给上下文菜单机制。也许禁用鼠标作为 LocatorPane 的输入设备可以纠正此问题,但这似乎并不实际。


以下是实施您使用 "SelectionSaveSpecial" 的建议的一种方法:

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

You said:

I want to call "save graphic as" by right click on LocatorPane graphics.

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

  1. select the LocatorPane object by clicking in the white-space to the right of it and dragging left.

  2. use menu File > Save Selection As... to save a graphic in your desired format.


What I believe is the correct option does not appear to 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"]}
  ];

Specifically, the value for "LocatorPaneBox" -> was changed to "GraphicsBox" but it has no apparent effect.

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

I suspect that because LocatorPane uses the mouse input, it captures the right-click attempt, and never passes it to the context menu mechanism. Perhaps disabling the mouse as an input device for LocatorPane would correct this, but that does not seem practical.


Here is one way to implement your suggestion of using "SelectionSaveSpecial":

Dynamic[EventHandler[
  LocatorPane[{1, 1}/2, Graphics[{Gray, Disk[]}]],
  {"MouseClicked", 2} :> 
   FrontEndExecute[
     SelectionMove[EvaluationNotebook[], All, GeneratedCell];
     SelectionMove[EvaluationNotebook[], All, CellContents]; 
     FrontEndToken["SelectionSaveSpecial"]
   ]
]]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文