2
$\begingroup$

This is an offshoot of how to create a menu as the Documentation Center?...

My aim is to build a menu that functions kind of like the documentation center...a grid of rectangles, each with a dropdown menu, which contains various functions (not documentation). After selecting the function, I'd like the window to be replaced with whatever the function calls. Then, upon closing the new window, the original menu interface returns. I've created an extremely rough piece of code to demonstrate:

DynamicModule[{x = {}}, 
 Grid[{{ActionMenu[
     "Sunset", {"Today" :> (x = CreateDocument@Sunset@Today), 
      "Next Week" :> (x = CreateDocument@Sunset@DatePlus@7)}], 
    ActionMenu[
     "Moon Phase", {"Today" :> (x = 
         CreateDocument@MoonPhase[Today, "Icon"]), 
      "Next Week" :> (x = 
         CreateDocument@
          MoonPhase[DatePlus@7, "Icon"])}]}, {ActionMenu[
     "GeoLocation", {"City" :> (x = CreateDocument@$GeoLocationCity), 
      "Country" :> (x = CreateDocument@$GeoLocationCountry)}], 
    ActionMenu[
     "Map", {"Here" :> (x = CreateDocument@GeoGraphics@Here), 
      "Hawaii" :> (x = 
         CreateDocument@
          GeoGraphics@
           Entity["AdministrativeDivision", {"Hawaii", 
             "UnitedStates"}])}], Dynamic@x}}]]  

Which gives the following output:

enter image description here

  1. When I click on an ActionMenu and select one of the functions, a new window opens with the function. How can I have the menu window replaced by the new function, and then when I close the new window, the old menu window returns? I know there is a Deinitialization in the DynamicModule documentation, but I haven't figured that out, and I see that only works once...can it be set to repeat infinitely?

  2. How can I get rid of the {}?

  3. Can I put the entire output in a standalone window/notebook ala CreateDialog?

If there is a better way to do this I'm all ears. I know the output is ugly, I just want to get the basic functionality working first.

$\endgroup$
1
$\begingroup$

Here is a first attempt that should get you started:

action[expr_] := Module[{old},
   old = InputNotebook[];
   SetOptions[old, Visible -> False];
   With[{old = old}, 
     CreateDocument[{expr, 
       Button["Close", {NotebookClose[InputNotebook[]], 
         SetOptions[old, Visible -> True]}]}
      ]]
   ];
DynamicModule[{}, 
 Grid[{{ActionMenu[
     "Sunset", {"Today" :> (action@Sunset@Today), 
      "Next Week" :> (action@Sunset@DatePlus@7)}], 
    ActionMenu[
     "Moon Phase", {"Today" :> (action@MoonPhase[Today, "Icon"]), 
      "Next Week" :> (action@
         MoonPhase[DatePlus@7, "Icon"])}]}, {ActionMenu[
     "GeoLocation", {"City" :> (action@$GeoLocationCity), 
      "Country" :> (action@$GeoLocationCountry)}], 
    ActionMenu[
     "Map", {"Here" :> (action@GeoGraphics@Here), 
      "Hawaii" :> (action@
         GeoGraphics@
          Entity["AdministrativeDivision", {"Hawaii", 
            "UnitedStates"}])}]}}, Frame -> True]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.