Re: Re: Problems with ChoiceDialog inside a Dynamic: Bug
- To: mathgroup at smc.vnet.net
- Subject: [mg107819] [mg107819] Re: [mg107779] Re: Problems with ChoiceDialog inside a Dynamic: Bug
- From: Adam Griffith <adamg at wolfram.com>
- Date: Sat, 27 Feb 2010 03:14:28 -0500 (EST)
- References: <hm573n$kge$1@smc.vnet.net> <201002252237.RAA17081@smc.vnet.net> <399C2A8F-0FBD-4B52-B366-8E223A6517DF@gtripaldi.it>
Hi Guido, Modality and blocking the kernel are two separate behaviors. Modal simply means that the user cannot access windows beneath the dialog while a blocking dialog holds the kernel evaluation until closed. So for example, the following dialog is modal and does not block: In[9]:= CreateDialog[ Grid[{{"Does the earth has oceans?"}, {ChoiceButtons[{DialogReturn[ answer = True], DialogReturn[answer = False]}]}}], Modal -> True]; In[10]:= answer Out[10]= False As for the Dynamic[], DynamicModule[{planets, x, habitantq}, planets = {"Mercury", "Venus", "Earth"}; x = First[planets]; PopupMenu[Dynamic[x, {x = #; If[StringMatchQ[x, "Earth"], habitantq = CreateDialog[ Column[{"Do you live on earth?", Row[{DefaultButton[ Print["This user has selected earth as their planet of \ residence"]; DialogReturn[True]], CancelButton[DialogReturn[False]]}]}]]]} &, Evaluator -> Automatic, Method -> "Queued"], planets]] again, adding Modal->True if desired. Hope this helps, -Adam Guido Tripaldi wrote: > mmh, I've said "problem solved" too soon in the previous message! So it is NOT possible to use ChoiceDialog inside a Manipulate or more in general inside a Dynamic object, or in nested modal dialogs: very bad! This certainly limits the grade of interactivity with the user that we can put in a program, think for example in cases where it's needed to stop and alert the user before a potentially destructive operations (i.e. deleting data, etc..). > Hoping, as usual, in the next version... > Anyway, thank you Adam and Albert for your hints! > > G > > Il giorno 25/feb/2010, alle ore 23.37, Albert Retey ha scritto: > > >> Hi, >> >> >>> suppose you wanna to display an alert to the user before to continue the >>> execution of your code when some conditions occur : probably you'll use >>> ChoiceDialog[], the useful function that "puts up a standard choice >>> dialog that displays expr together with OK and Cancel buttons, and >>> returns True if OK is clicked, and False if Cancel is clicked.". >>> >>> But if you use this function inside some Dynamic[] object, it hangs the >>> kernel. I've tried to find in the documentation some references to this >>> bad combination without any luck, so I don't understand if this is a bug >>> or there is something missing in the code. >>> >>> To better explain the problem here is a very basic example: >>> >>> (* just a silly example *) >>> Grid[{ >>> {"Choose a dividend: ", >>> PopupMenu[Dynamic[dividend], Table[i, {i, 0, 10}]]}, >>> {"Choose a divisor : ", PopupMenu[Dynamic[divisor], Table[i, {i, 0, 10}]]}, >>> {"Quotient: ", Dynamic[dividend / divisor]} >>> }, Frame -> All] >>> Dynamic[ >>> If[divisor == 0, >>> ChoiceDialog["Uh-oh, you are going to do a division by zero! Please select a different divisor.", {"Ok"}]; >>> ]]; >>> >> It's a deficiency of how the modal dialogs behave. I have encountered >> this about a year ago or more and reported here, but have not yet >> received any answers. You have the same problem when you try to nest >> modal dialogs. In the meantime I just try to avoid modal dialogs where I >> can, which is often possible, but of course not always. >> >> >>> Instead, if you use the MessageDialog[] function to show a message window, all works well, but of course the execution will continue without waiting for the user action (that is not what I want). >>> >>> Same situation if you try to use ChoiceDialog[] inside a TabView, or other kind of Views: >>> >>> (* another silly example *) >>> TabView[{ >>> "Tab1" -> Button["Show ChoiceDialog", result = ChoiceDialog["This hangs.. :-(."];], >>> "Tab2" -> Button["Show MessageDialog", MessageDialog["This works!"];] >>> }] >>> >> In some cases like your second example, where a modal dialog is started >> by a button, the Method->"Queued" trick helps: >> >> TabView[{ >> "Tab1" -> Button["Show ChoiceDialog", >> result = ChoiceDialog["This is ok:-)."], >> Method->"Queued" >> ], >> "Tab2" -> Button["Show MessageDialog", >> MessageDialog["This works!"]; >> ] >> }] >> >> >> hth, >> >> albert >> >> > > --- > Guido Tripaldi > > >
- References:
- Re: Problems with ChoiceDialog inside a Dynamic: Bug or not (well)
- From: Albert Retey <awnl@gmx-topmail.de>
- Re: Problems with ChoiceDialog inside a Dynamic: Bug or not (well)