Message Boards Message Boards

Why Plot doesn't work when called by ActionMenu?

Posted 2 years ago

Hello All,

I cannot understand why:

"foo" works when called from ActionMenu,

2+2 works when called from ActionMenu,

Sqrt[2] works when called from ActionMenu,and

Plot[Sin[x], {x, 0, 2 Pi}] DOES NOT work when also called from ActionMenu.

(may be I do not understand why all the 4 ActionMenus act one after another into the same Cell...)

Thank you beforehand for some help.

Gianni

CreatePalette[
 Grid[
  {
   {ActionMenu[
     "Menu logo", {"About" :> 
       NotebookApply[SelectedNotebook[], "About info"]}],
    ActionMenu["Menu 1",
     {"Action 1.1" :> NotebookApply[SelectedNotebook[], "foo"],
      "Action 1.2" :> NotebookApply[SelectedNotebook[], 2 + 2],
      "Action 1.3" :> NotebookApply[SelectedNotebook[], N[Sqrt[2]]],
      "Action 1.4" :> 
       NotebookApply[SelectedNotebook[], Plot[Sin[x], {x, 0, 6 Pi}]]
      }]}
   }, Frame -> All]]
POSTED BY: Gianni Mocellin
9 Replies

Dear Rohit,

I have posted a question on WSE right now, 2022.01.06, 08:00.

Kindest regards.

Gianni

POSTED BY: Gianni Mocellin

Dear Rohit,

The chapters 24, 24 and 26 are only in the third edition of the book of Patrick Henry Winston (not in the first and second edition...).

Kindest regards.

Gianni

POSTED BY: Gianni Mocellin

Hi Rohit,

I sent the file "2022.01.05-0500-ActionMenu.nb" also to the Wolfram Support and I am waiting for an answer from them.

As per the interface of the UI for the Expert system, see the attached "Interface du système expert.pdf" file.

As per Lisp code, the Inference engine of the expert system was written in Lisp in 1985.

Roman Maeder from the Swiss Institute of Technology did something quite similar in Mathematica that you can see in his book "The Mathematica Programmer II", Academic Press, 1992, Chapter 2, Logic Programming.

Anyway, I do not want to program again in Lisp because I think that at Wolfram they are showing us the way to go for the future, including using SystemModeler and the Control functions of Mathematica, not forgetting Tracking Control since Mathematica 13.0 (see: Summary of New Features in 13.0 - System Modeling).

As per Jay Sussman, we had a wonderful time at the First Conference on Artificial Intelligence held in Cambridge, UK, I do not remember the year.

Another conference was held latter in the Conference Center of the Twickenham Stadium, UK, a good place to blend artificial intelligence with rugby...

Seeing the picture you attached of the cover of the book of Jay "Structure and Interpretation of Computer Programs" was very emotional for myself, considering the number of hours I spent in trying to understand what he meant in chapter 4, "Metalinguistic Abstraction" and especially in section 4.4 "Logic Programming".

Another very important book preceding the one of Jay was "Lisp", by Patrick Henry Winston, 1981, especially chapter 24 "Symbolic Pattern Matching", chapter 25 "Streams and Delayed Evaluations" and chapter 26 "Rule-Based Expert Systems and Forward Chaining".

So, Rohit, I thank your for your kind suggestions that I will try as soon as I can and compare all that with the solutions provided by the Wolfram Support, if any.

Kindest regards.

Gianni

Attachments:
POSTED BY: Gianni Mocellin

Dear Rohit,

What a pleasure to see your prompt answer and your solution which works perfectly.

I hoped it would also work with a FormFunction as it works with Plot.

Unfortunately I did not succeed in making it work (see here under code).

May be you have a solution also for FormFunction, e.g. with the first Basic Example of the documentation of FormFunction ...

form = FormFunction[{"first" -> "String", "second" -> "Number"}, f];

CreatePalette[
 Grid[{{ActionMenu[
     "Menu logo", {"About" :> 
       NotebookWrite[SelectedNotebook[], 
        Cell["About info", "Text"]]}], 
    ActionMenu[
     "Menu 1", {"Action 1.1" :> 
       NotebookWrite[SelectedNotebook[], Cell["foo", "Text"]], 
      "Action 1.2" :> 
       NotebookWrite[SelectedNotebook[], 
        Cell[ToBoxes[2 + 2], "Output"]], 
      "Action 1.3" :> 
       NotebookWrite[SelectedNotebook[], 
        Cell[ToBoxes[N[Sqrt[2]]], "Output"]], 
      "Action 1.4" :> 
       NotebookWrite[SelectedNotebook[], 
        Cell[{ToBoxes[Plot[Sin[x], {x, 0, 6 Pi}]]}, "Output"]], 
      "Action 1.5" :> 
       NotebookWrite[SelectedNotebook[], 
        Cell[{ToBoxes[form[]]}, "Output"]]}]}}, Frame -> All]]

BTW, I am an old pilot, also qualified as "Mountain glacier pilot", especially in the "Massif du Mont Blanc ", and nothing would be more pleasant for me to have a nice steak at the Café Restaurant de l'aviation.

Do not hesitate to inform me as soon as you have dates and the pleasure of the invitation will be mine.

Kindest regards.

Gianni

POSTED BY: Gianni Mocellin
Posted 2 years ago

Hi Gianni,

I have not been able to figure out why the FormFunction example does not work. This works fine

form = FormFunction[{"first" -> "String", "second" -> "Number"}, f];
NotebookWrite[SelectedNotebook[], Cell[{ToBoxes[form[]]}, "Input"]]

This does not

ActionMenu["Menu", {"Create Form" :> 
   NotebookWrite[SelectedNotebook[], Cell[{ToBoxes[form[]]}, "Input"]]}]

Can you explain what you are trying to accomplish? Why do you need to create a FormFunction from an ActionMenu? Usually FormFunction is used in conjunction with CloudDeploy. If you just intend to use it to create an interface on the desktop where a user can enter values then there may be better ways of doing that.

Thanks for the invite! Hope to take you up on it soon.

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Hi Gianni,

Figured out part of the problem, the Method -> "Queued" option is needed.

ActionMenu["Menu", {"Create Form" :> 
   NotebookWrite[SelectedNotebook[], Cell[{ToBoxes[form[]]}, "Input"]]}, Method -> "Queued"]

However, it fails when wrapped in CreatePalette. I have no idea why. Will ask the question on MSE.

CreatePalette[
 ActionMenu[
  "Menu", {"Create Form" :> 
    NotebookWrite[SelectedNotebook[], Cell[{ToBoxes[Evaluate@form[]]}, "Input"]]}]]
POSTED BY: Rohit Namjoshi

Dear Rohit,

The interface I am trying to build in Mathematica is a copy of the interface of an Expert system I wrote with a Lisp whose floppy disks where sent to be by mail from the MIT by Jay Sussman.

The system ran in a Mac and was the final project for a postgraduate diploma in Artificial intelligence at the Swiss Institute of Technology in...

1985.

By the way was a user of Mathematica 1.0 since it existed and at the moment I do not need to deploy anything on the cloud.

All I would like to have is a running interface on my desktop, something like the one you can test in evaluating the attached "2022.01.05-0500-ActionMenu.nb".

Thank you beforehand for your attention and your eventual feedbacks.

Kindest regards.

Gianni

Attachments:
POSTED BY: Gianni Mocellin
Posted 2 years ago

Hi Gianni,

Remove all of the Print. ToBoxes@Print@... evaluates to Null because Print evaluates to Null. Do you have an image of the UI for the expert system? Are you able to run the Lisp code?

Pretty cool that you worked with Jay Sussman. Wonderful book.

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Hi Gianni,

My answer to a related question was limited to simple actions, for more complex actions NotebookWrite and ToBoxes have to be used. e.g.

CreatePalette[Grid[{{
    ActionMenu[
     "Menu logo", {"About" :> NotebookWrite[SelectedNotebook[], Cell["About info", "Text"]]}],
    ActionMenu["Menu 1",
     {"Action 1.1" :> NotebookWrite[SelectedNotebook[], Cell["foo", "Text"]],
      "Action 1.2" :> NotebookWrite[SelectedNotebook[], Cell[ToBoxes[2 + 2], "Output"]],
      "Action 1.3" :> NotebookWrite[SelectedNotebook[], Cell[ToBoxes[N[Sqrt[2]]], "Output"]], 
      "Action 1.4" :> NotebookWrite[SelectedNotebook[], Cell[{ToBoxes[Plot[Sin[x], {x, 0, 6 Pi}]]}, "Output"]]}]}}, 
  Frame -> All]]

Each action works now and the output is in a new cell, not at the current cursor position. This might also work for the FormFunction question you asked. I have not tried that.

BTW, my wife's parents, brother, and his family also live in Geneva. We usually visit them once or twice a year. Unfortunately, we have not seen them for over two years because of Covid. Maybe this year. Looking forward to a nice steak at Cafe Restaurant de L'aviation. :-)

POSTED BY: Rohit Namjoshi
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