Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 436
István Zachar Avatar asked Aug 01 '26 08:08

István Zachar


1 Answers

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

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

It overwrites the default dialog NotebookEventActions.

like image 65
Chris Degnen Avatar answered Aug 04 '26 10:08

Chris Degnen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!