Re: Test for dialog existence
- To: mathgroup at smc.vnet.net
- Subject: [mg112739] Re: Test for dialog existence
- From: Chris Degnen <degnen at cwgsy.net>
- Date: Wed, 29 Sep 2010 04:12:02 -0400 (EDT)
- References: <i7seje$pl6$1@smc.vnet.net> <i7shar$rmf$1@smc.vnet.net>
On 28 Sep, 11:51, Albert Retey <a... at gmx-topmail.de> wrote: > Hi, > > > > > > > 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 -> N= one, > > 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"] > > Here is one possibility, instead of the WindowTitle you could also use a > certain value in the TaggingRules where you could "hide" the additional > information which would identify the dialog, but it would mean some > extra bits of code: > > 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]],WindowTitle->"TestDialog"] > ]; > End[]; > EndPackage[]; > CreateTestDialog[]; > > (*this will check whether there is an open dialog: *) > Length[Select[Notebooks[],CurrentValue[#,WindowTitle]==="TestDialog= "&]]>0 > > on the other hand, I have a feeling that you might implement something > too complicated for what you really want to achieve. Maybe you would get > some useful tips if you try to give us a bigger picture of what you are > trying to do... > > hth, > > albert Thanks Albert. That will come in very hand for maintaining single instances of dialogs. Also I see, if a dialog exists and it is called again I can raise the existing one: If[Length[Select[Notebooks[], CurrentValue[#, WindowTitle] === "TestDialog" &]] > 0, SetSelectedNotebook[Part[Notebooks[], First[First[Position[ Map[CurrentValue[#, WindowTitle] &, Notebooks[]], "TestDialog"]]]]]];