Re: Test for dialog existence
- To: mathgroup at smc.vnet.net
- Subject: [mg112776] Re: Test for dialog existence
- From: David Reiss <dbreiss at gmail.com>
- Date: Thu, 30 Sep 2010 04:50:58 -0400 (EDT)
- References: <i7usfi$rbv$1@smc.vnet.net>
On Sep 29, 4:13 am, John Fultz <jfu... at wolfram.com> wrote: > 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 usi= ng the > NotebookObject returned by your CreateTestDialog function. I.e., > > nb=CreateTestDialog[]; > NotebookInformation[nb] > > This will return a list of values if the notebook is still open, and $Fai= led if > it's been closed. If you want to be notified as soon as the dialog clo= ses, then > the best way to do this is to implement a dialog with a DefaultButton[] a= nd/or a > CancelButton[]. > > Sincerely, > > John Fultz > jfu... at wolfram.com > User Interface Group > Wolfram Research, Inc. Another possibility is to use the WindowClose event specification inclusion in the Dialog's NotebookEventActions. --David