Message Boards Message Boards

0
|
2989 Views
|
6 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Creating a Yes/No dialog?

Posted 1 year ago

I am trying to create dialogs looking something like these (from another piece of software) enter image description here

After much searching the best I can come up with is this:

CreateDialog[
Grid[{
{"Would you like to look for a text file containing dissociation constants?","    "},
{Item[ChoiceButtons[{"Yes","No"}, {DialogReturn["Yes"]; DialogReturn["No"]}],Alignment -> Right],SpanFromLeft}}, Alignment -> Left]]

which shows as

enter image description here

My only problem is in determining which button has been pressed because DialogReturn["Yes"] doesn't work.

I never guessed it would be so difficult to get a simple Yes/No dialog!

POSTED BY: Paul Newton
6 Replies
Posted 1 year ago

Maybe ChoiceDialog?

ChoiceDialog[
  "Would you like to look for a text file containing dissociation constants?", 
  {"Yes, abolutely!" -> True, "I'd rather not" -> False}]

And if you would be satisfied with the standard "OK" and "Cancel" buttons, you could get away with just this:

ChoiceDialog["Would you like to look for a text file containing dissociation constants?"]
POSTED BY: Eric Rimbey
Posted 1 year ago

I believe I looked at ChoiceDialog but could not make it modal - if it can be made modal that would certainly be the way to go.

POSTED BY: Paul Newton
Posted 1 year ago
ChoiceDialog[
  "Would you like to look for a text file containing dissociation constants?", 
  {"Yes, abolutely!" -> True, "I'd rather not" -> False}, 
  Modal -> True]
POSTED BY: Eric Rimbey
Posted 1 year ago

Thank you, Eric. My only excuse is that on this page ChoiceDialog there is no mention of Modal whatsoever. I admit that there is probably something somewhere in the docs about using Modal with dialogs in general, but it is not immediately obvious.

My other gripe would be that, in order to make "No" the default option, you would have to swap the positions of the buttons (unless I am mistaken about that too).

POSTED BY: Paul Newton
Posted 1 year ago

Regarding swapping the buttons, if I understand what you mean, yes, I think think the first button that you specify is the default button. But there may be an option for that.

Which brings us to your other comment. In the documentation, it is standard to find info about the options in the "Details and Options" section. Some options will be explained explicitly, and for others you may be referred to the docs for a different function. I am very surprised that ChoiceDialog didn't mention Modal. But once you're comfortable with the docs and have an intuition for how functions are related to each other, you can sniff out things that maybe aren't obvious. So, I saw that CreateDialog was a related function, and it sounds like it's more general. ChoiceDialog probably "inherits" from it. Indeed, Modal is mentioned in the documentation for CreateDialog.

And then there's the Options function. You can use it to see all the options for a function along with their default values. So, try Options[ChoiceDialog]. Unfortunately, this is something else a bit different for ChoiceDialog: its options list is huge (and maybe that's why options are explicitly discussed in the docs for ChoiceDialog). The reason is because all of these dialog generating functions are really generating whole notebooks, and so you can pass notebook options through them. You can also just take a guess and ask for a specific option: Options[ChoiceDialog, Modal].

You might find an option in there for controlling the default button. Or you might spend some time looking at the documentation for the various dialog functions and see if any of those pages shows a way to change the default. Or you might inspect the actual notebook that gets generated as the dialog and see what the underlying cells/expressions for the buttons look like.

POSTED BY: Eric Rimbey
Posted 1 year ago

I take all your points and I am gradually becoming more comfortable with the docs. I will definitely bear in mind the Options function.

POSTED BY: Paul Newton
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