Background. See question Moving controls from Manipulate to a Palette ( or similar GUI object ). As suggested in the answer to this question I use a CreateDialog window to group and handle controls and added WindowFloating->True as an option. Clicking a second time on the external button creates an identical copy of the Window.

Question: What it is the best way to enforce that only one CreateDialog window can be created?


1 Answer 1


The simplest that comes to mind is to close it before opening it again.

So, where you had the CreateDialog[...] line, you now put NotebookClose[nb]; nb=CreateDialog[...]

(You can wrap your button in DynamicModule[{nb}, Button[...] to localize the symbol)

A better one, is to put If[FreeQ[Notebooks[], nb], nb=CreateDialog[...]]

Here's the tweaked code taken from the linked answer by @AlbertRetey

     Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},
    {{scx, 0}, {0, scy}}],
   Tuples[{Range[wi], Range[he]}] - 1], ImageSize -> 400 {1, 1}],
     If[FreeQ[Notebooks[], nb],
      nb = CreateDialog[DynamicModule[{},
         Column[{Control[{{scx, 1, "x scale"}, 0, 1}], 
           Control[{{scy, 1, "y scale"}, 0, 1}],
           Control[{{wi, 1, "width"}, 1, 5, 1}],
           Control[{{he, 1, "heigth"}, 1, 5, 1}]}],
         InheritScope -> True]]];SetSelectedNotebook[nb]],
Deinitialization :> (NotebookClose[nb])],
   Column[{Control[{{scx, 1, "x scale"}, 0, 1}],
     Control[{{scy, 1, "y scale"}, 0, 1}],
     Control[{{wi, 1, "width"}, 1, 5, 1}],
     Control[{{he, 1, "heigth"}, 1, 5, 1}]}]}]]
  • $\begingroup$ thanks for citing me :-). You might want to add SetSelectedNotebook[nb] in the else part of the If. Another obvious problem with this (well, my) code is that the dialog will stay open when the Manipulate is removed (or overwritten with the next evaluation). I couldn't get a naive Deinitialization for the DynamicModule[{nb},...] to work, though... $\endgroup$ Commented Jun 20, 2012 at 16:40
  • $\begingroup$ @AlbertRetey, just edited with your suggestions. The Deinitialization doesn't seem to be instantaneous, but it closes the dialog as soon as I type something else in a notebook $\endgroup$
    – Rojo
    Commented Jun 20, 2012 at 16:48
  • $\begingroup$ o.k., very good to know, thanks for that information, Mathematica keeps us all busy with learning new facts :-). Closing the window when the next such Manipulate will be generated is the best I could manage to do with other approaches up to now. So the Deinitialization seems to be the best approach known to me so far. I really wonder if it would be possible to make it "instantaneous", though... $\endgroup$ Commented Jun 20, 2012 at 16:53
  • $\begingroup$ @AlbertRetey I wonder what exactly does this mean: Deinitialization will never be performed unless initialization has previously been performed. $\endgroup$
    – Rojo
    Commented Jun 20, 2012 at 17:02
  • $\begingroup$ you seem to read what I do, wonder, wonder :-). I guess this wants to tell us that the deinitialization can safely assume that the initialization, if given, has been done before the deinitialization will be done. I was wondering whether: Deinitialization may be delayed if, for example, a construct appears in an invisible location such as the clipboard. is an explanation for the delayed NotebookClose. We do show dynamic-module variables in that window that do belong to the manipulate we just deleted, so maybe that's the reason ?!? $\endgroup$ Commented Jun 20, 2012 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.