István Zachar
István Zachar

Reputation: 1344

Dialog manipulation

I want to create a dialog window, where the user can perform various tasks, and would like him to return from the dialog by clicking on the Cancel button with the mouse (i.e. not by hitting Enter). Therefore I do not want to use CreateDialog. However, by creating a less-specific dialog window via CreateWindow, all strings appear unformatted.

expr = Column[{
   Row@{"set variable to: ", InputField["value", String]},
   "Try to hit Enter in any of the dialogs: it closes #2 but not #1.",
   CancelButton[]
   }];

CreateWindow[DialogNotebook[expr], WindowSize -> All, WindowMargins -> {{100, Automatic}, {Automatic, Automatic}}, WindowTitle -> "1. CreateWindow & DialogNotebook"];
CreateDialog[expr, WindowTitle -> "2. CreateDialog"];

dialog windows

Is there any clever way to have the looks of the second dialog window, but the button-behaviour of the first one? Of course, expr here is a simple example, but it can be quite complex in reality, thus it is no option to wrap every string into Cell[string, "Text"], and every other expression into some obscure boxform.

Upvotes: 2

Views: 241

Answers (4)

Chris Degnen
Chris Degnen

Reputation: 8680

This will stop your dialog window closing when Enter is pressed:

CreateDialog[expr, WindowTitle -> "2. CreateDialog", NotebookEventActions -> {}];

It overwrites the default dialog NotebookEventActions.

Upvotes: 6

Pillsy
Pillsy

Reputation: 9901

There are a number of ways to do this, and other folks have posted two good ones, but in my opinion the easiest approach is to set the BaseStyle of the Column expression to match the base style of the dialog, and then use CreateWindow. The style in question is "Panel", so this gets you the result you want:

expr = Column[{Row@{"set variable to: ", InputField["value", String]},
     "Try to hit Enter in any of the dialogs: it closes #2 but not #1.", 
     CancelButton[]}, BaseStyle -> "Panel"];

CreateWindow[DialogNotebook[expr], WindowSize -> All, 
  WindowMargins -> {{100, Automatic}, {Automatic, Automatic}}, 
  WindowTitle -> "1. CreateWindow & DialogNotebook"];

Upvotes: 1

Dr. belisarius
Dr. belisarius

Reputation: 61066

Perhaps using TextCell:

expr = Column[{Row@{TextCell@"set variable to: ", 
                    InputField["value", String]}, 
               TextCell@"Try to hit Enter in any of the dialogs: \
                         it closes #2 but not #1.", 
               CancelButton[]}];

CreateWindow[
 DialogNotebook[expr], WindowSize -> All, 
 WindowMargins -> {{100, Automatic}, {Automatic, Automatic}}, 
 WindowTitle -> "1. CreateWindow & DialogNotebook"]

Edit

Use

 TextCell@Style[" ... blah blah ...", style_opt ]

for formatting.

Upvotes: 2

ragfield
ragfield

Reputation: 2506

Another option:

expr = Style[
   Column[{Row@{"set variable to: ", InputField["value", String]}, 
     "Try to hit Enter in any of the dialogs: it closes #2 but not \
#1.", CancelButton[]}], ShowStringCharacters -> False];

Upvotes: 2

Related Questions