Message Boards Message Boards

ActionMenu prints its output on messages window instead of notebook

Posted 2 years ago

Hi,

I am trying to use ActionMenu inside a CreatePalette to Print some text when I select a menu (e.g. Menu 1.1) and to print the result of some computation (e.g. Menu 1.2).

But, instead of printing the result directly into the notebook, it is printed into the "Messages" window.

Is there a way to enforce Mathematica to print the result in a specified notebook (e.g. the current notebook) in order to use it for further computations?

Thank you beforehand for your help.

Kindest regards.

Mario.

CreatePalette[
 Grid[
  {
   {
    ActionMenu[
     "Logo",
     {"About" :> Print["Info"]}
     ],
    ActionMenu[
     "Menu 1",
     {
      "Action 1.1" :> Print["foo"],
      "Action 1.2" :> Print[2 + 2]
      }
     ]
    }
   },
  Frame -> All]
 ]
POSTED BY: Mario Veruete
7 Replies
Posted 2 years ago

Here is a code fragment, a tool to insert a function template, showing one way:

ActionMenu["Plot", 
 ht = gettmp[#] & /@ 
   getUsg3@"Plot"; (# :> NotebookApply[InputNotebook[], #]) & /@ 
  ht, Appearance -> {"Frameles"}]
POSTED BY: Andrew Meit

Dear Andrew,

Could you put your solution doing something very simple (like Plot, Graphics or form) into the hereunder code structure because I tried myself without succeeding?

By the way, we are some people working on the same problem and nobody did yet find a satisfying solution.

I posted myself another question on the community you can consult:

https://community.wolfram.com/groups/-/m/t/2436599

Thank you beforehand for your answer.

Kindest regards.

Gianni Mocellin

PS: I am very proud that you take action in this discussion, because I already red many of your wonderful interventions in the community.

form = FormFunction[{"first" -> "String", "second" -> "Number"}, f];
CreatePalette[Grid[{{
    ActionMenu[
     "LogoMenu",
     {
      "About information" :> 
       NotebookWrite[SelectedNotebook[], 
        Cell["About information", "Text"]],
      "About information bis" :> 
       NotebookWrite[SelectedNotebook[], 
        ToBoxes@"About information bis"]
      }
     ],
    ActionMenu[
     "Menu 1",
     {
      "Action 1.1" :> 
       NotebookWrite[SelectedNotebook[], Cell["foo", "Text"]],
      "Action 1.1 bis" :> 
       NotebookWrite[SelectedNotebook[], ToBoxes@"foo bis"],

      "Action 1.2" :> 
       NotebookWrite[SelectedNotebook[], 
        Cell[ToBoxes[2 + 2], "Output"]],
      "Action 1.2 bis" :> 
       NotebookWrite[SelectedNotebook[], ToBoxes@(2 + 2)],

      "Action 1.3" :> 
       NotebookWrite[SelectedNotebook[], 
        Cell[ToBoxes[N[Sqrt[2]]], "Output"]],
      "Action 1.3 bis" :> 
       NotebookWrite[SelectedNotebook[], ToBoxes@N[Sqrt[2]]],

      "Action 1.4" :> 
       NotebookWrite[SelectedNotebook[], 
        Cell[{ToBoxes[Plot[Sin[x], {x, 0, 6 Pi}]]}, "Output"]],
      "Action 1.4 bis" :> 
       NotebookApply[SelectedNotebook[], 
        ToBoxes@Plot[Sin[x], {x, 0, 6 Pi}]],

      "Action 1.5" :> 
       NotebookWrite[SelectedNotebook[], 
        Cell[{ToBoxes[Graphics[Circle[]]]}, "Output"]],
      "Action 1.5 bis" :> 
       NotebookApply[SelectedNotebook[], ToBoxes@Graphics[Circle[]]],

      "Action 1.6" :> 
       NotebookWrite[SelectedNotebook[], 
        Cell[{ToBoxes[form[]]}, "Output"]], 
      "Action 1.6 bis" :> 
       NotebookApply[SelectedNotebook[], ToBoxes@form[]]
      }
     ]
    }},
  Frame -> All]]
Attachments:
POSTED BY: Gianni Mocellin
Posted 2 years ago

This great NotebookApply feature, combined with the ActionMenu feature, helped me too!

POSTED BY: Daniell Miller

Dear Daniel,

Could you give some examples of the ways you used ActionMenu with NotebookApply?

Thank you beforehand for your answer.

Kindest Regards.

Gianni Mocellin

POSTED BY: Gianni Mocellin
Posted 2 years ago

Hi Mario,

Is this what you are trying to accomplish?

CreatePalette[Grid[{{
    ActionMenu[
     "Logo", {"About" :> NotebookApply[SelectedNotebook[], "Info"]}],
    ActionMenu["Menu 1",
     {"Action 1.1" :> NotebookApply[SelectedNotebook[], "foo"],
      "Action 1.2" :> NotebookApply[SelectedNotebook[], 2 + 2]}]}},
  Frame -> All]]
POSTED BY: Rohit Namjoshi
Posted 2 years ago

Dear Rohit,

Thank you so much for your prompt answer.

I was thinking about something like that but I was not aware of the use of the NotebookApply function in conjunction with the ActionMenu function because in the ActionMenu documentation there is no example for that use.

Kindest regards,

Mario

POSTED BY: Mario Veruete

Dear Rohit,

I am Gianni Mocellin from Geneva, Switzerland, and I took notice of your prompt answer to the very interesting question by Mario Veruete.

I have a similar issue but instead of using Print, I have a FormFunction that does not execute from a menu in a Palette.

Thank you beforehand for your help, if possible.

Kindest regards.

Gianni

createQuantity := FormFunction[
   "quantity list" ->
    RepeatingElement[
     CompoundElement[
      <|
       "Property" -> "String",
       "Unit" -> "Expression",
       "Magnitude" -> "Expression"
       |>
      ]
     ],
   AppearanceRules ->
    <|
     "Title" -> "Enter an quantity"
     |>
   ];
createQuantity[]

CreatePalette[
 Grid[
  {
   {
    ActionMenu[
     "Logo",
     {"About" :> NotebookApply[SelectedNotebook[], "Info"]}
     ],
    ActionMenu[
     "Menu 1",
     {
      "Action 1.1" :> createQuantity[],
      "Action 1.2" :> Print[2 + 2]
      }
     ]
    }
   },
  Frame -> All]
 ]
POSTED BY: Gianni Mocellin
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract