Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to make a panel look like a ChoiceDialog.

Let's say a have a panel like this:

Panel[Column[{Style["What's the gender?", FontFamily -> "Calibri", 
    FontSize -> 14], PopupMenu[Dynamic[x], optionsGender], " ", 
   Style["What's the academic title?", FontFamily -> "Calibri", 
    FontSize -> 14], PopupMenu[Dynamic[y], optionsTitle], 
   Button["Yeah!", Print[x, " ", y]]}]]

After clicking the button, I want to make the whole panel disappear and only leave the print in the output. Does anyone know how to do that? Thx in advance.

share|improve this question

This does a targeted overwrite of just the Panel...well, technically, of the DynamicModuleBox with which I'm wrapping the PanelBox:

DynamicModule[{box}, 
 Panel[Column[{Style["What's the gender?", FontFamily -> "Calibri", 
     FontSize -> 14], PopupMenu[Dynamic[x], optionsGender], " ", 
    Style["What's the academic title?", FontFamily -> "Calibri", 
     FontSize -> 14], PopupMenu[Dynamic[y], optionsTitle], 
    Button["Yeah!", NotebookWrite[box, ToBoxes@Row[{x, RawBoxes@" ", y}]]]}]], 
 Initialization :> (box = EvaluationBox[])]

So, the idea is that I'm getting the BoxObject which corresponds to the outer DynamicModuleBox. Then, I can pass that to NotebookWrite. This allows me to overwrite the box regardless of what's inside of, and it works without changing the selection.

It does, however, have the side effect of turning the Output cell into an Input cell (assuming this was in an Output cell to begin with). If that's an issue, then you can add this to the DynamicModule's initialization:

CurrentValue[EvaluationCell[], CellEditDuplicate] = False;
share|improve this answer
    
this is a really useful example for the use of EvaluationBox, which I think I just start to appreciate, so thanks for sharing. One thing I think should be noted is that it won't work with the free CDF Player, most probably because of the NotebookWrite (?). As that use case seems to be closer to Dynamic functionality than to programmatically edit notebooks, do you think there is a chance that WRI will allow NotebookWrite in CDF Player when the first argument is a box in future versions? – Albert Retey Mar 18 at 20:23
    
@AlbertRetey Probably not since it would be hard to prevent users from creating notebooks using FreePlayer. In this case PaneSelector should be a good enough alternative. – Kuba Apr 15 at 17:35

When clicked, the panel is replaced by the output.

DynamicModule[{output, x, y},
 output = Panel@Column@{
     "What's the gender?",
     PopupMenu[Dynamic[x], {"Male", "Female", Indeterminate}], 
     Spacer@10,
     "What's the academic title?", 
     PopupMenu[Dynamic[y], {None, "MSc", "PhD", All}],
     Button["Yeah!", output = Row@{x, " ", y}]};
 Dynamic@output]
share|improve this answer
    
This is also a nice option for this. Thx! – 407Peezy Mar 18 at 21:27

This will do it:

Button["Yeah!", NotebookDelete[EvaluationCell[]]; Print[x, " ", y]]
share|improve this answer
    
+1 Just to spell it out, OP can keep the panel and use this method, by just replacing Print[x, " ", y] in the original code with Print[x, " ", y]; NotebookDelete[EvaluationCell[]] – JasonB Mar 18 at 11:24
    
Thank you! That's a nice trick – 407Peezy Mar 18 at 13:55

What about a dialog box outside the current notebook?

DialogInput[
 Column[{Style["What's the gender?", FontFamily -> "Calibri", 
    FontSize -> 14], PopupMenu[Dynamic[x], optionsGender], " ", 
   Style["What's the academic title?", FontFamily -> "Calibri", 
    FontSize -> 14], PopupMenu[Dynamic[y], optionsTitle], 
   Button["Yeah!", DialogReturn[Row[{x, " ", y}]]]}]]

This seems to do the same as your panel, except the panel is outside the notebook, and it closes upon the press of the button. See the documentation for DialogInput and DialogReturn.

share|improve this answer
    
I didn't realize that there is a DialogInput. Thanks for the tips. – 407Peezy Mar 18 at 13:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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