Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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

Manipulate[Graphics[Translate[
   GeometricTransformation[{Blue, 
     Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},
    {{scx, 0}, {0, scy}}],
   Tuples[{Range[wi], Range[he]}] - 1], ImageSize -> 400 {1, 1}],
 OpenerView[{DynamicModule[{nb},
    Button["external",
     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}]}]}]]
share|improve this answer
    
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... –  Albert Retey Jun 20 '12 at 16:40
    
@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 –  Rojo Jun 20 '12 at 16:48
    
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... –  Albert Retey Jun 20 '12 at 16:53
    
@AlbertRetey I wonder what exactly does this mean: Deinitialization will never be performed unless initialization has previously been performed. –  Rojo Jun 20 '12 at 17:02
    
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 ?!? –  Albert Retey Jun 20 '12 at 17:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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