Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Test for dialog existence

  • To: mathgroup at
  • Subject: [mg112750] Re: Test for dialog existence
  • From: John Fultz <jfultz at>
  • Date: Wed, 29 Sep 2010 04:14:05 -0400 (EDT)

On Tue, 28 Sep 2010 06:01:47 -0400 (EDT), Chris Degnen wrote:
> Hi. Can anyone suggest how to test for the existence of a dialog?
> In the example below a dialog is created containing a plot which can
> be modified.  However it seems to be difficult to test whether the
> dialog has been closed.
> This creates the dialog:
> BeginPackage["TestExample`TestDialog`"];
> CreateTestDialog::usage = "CreateTestDialog[] creates a test dialog";
> Begin["`Private`"];
> CreateTestDialog[] :=
> Module[{}, n = 4;
> CreateDialog[
> plot = Dynamic[
> ParametricPlot[{Sin[t], Sin[n t]}, {t, 0, 2 Pi}, Ticks -> None,
> ImageSize -> 100]]]];
> End[];
> EndPackage[];
> CreateTestDialog[];
> And the plot can be modified by various means:
> TestExample`TestDialog`Private`n = 8;
> TestExample`TestDialog`Private`n = 2;
> But how can I tell if the dialog has been closed?  The dynamic plot
> object still shows as existing afterwards:
> NameQ["TestExample`TestDialog`Private`plot"]

Yes, the name and even the value remain because they aren't scoped in any way.  
CreateDialog is not a variable scoping construct.

If you want to poll to test whether it's been closed, you can do this using the 
NotebookObject returned by your CreateTestDialog function.  I.e.,


This will return a list of values if the notebook is still open, and $Failed if 
it's been closed.  If you want to be notified as soon as the dialog closes, then 
the best way to do this is to implement a dialog with a DefaultButton[] and/or a 


John Fultz
jfultz at
User Interface Group
Wolfram Research, Inc.

  • Prev by Date: Re: How do I test for existence of a list element? Clarified
  • Next by Date: Re: Defining a function using common notation for absolute value (not Abs[x])
  • Previous by thread: Re: Test for dialog existence
  • Next by thread: Re: Test for dialog existence