MathGroup Archive 2007

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

Search the Archive

Re: How to make a Button inside Manipulate?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81079] Re: How to make a Button inside Manipulate?
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Mon, 10 Sep 2007 18:59:59 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <fc0i23$c32$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de

Hi,

Manipulate[
  DynamicModule[{i = 0},
   Dynamic@ Plot[
     Sin[2 Pi*\[Omega]*x], {x, 0, 1},
     PlotStyle -> {Switch[i,
        0, RGBColor[0, 0, 0],
        1, RGBColor[1, 0, 0],
        2, RGBColor[0, 1, 0],
        3, RGBColor[0, 0, 1]
        ]},
     Epilog ->
      Inset[Button["Press ..", i = Mod[i + 1, 4]], {0.8, 0.8}]
     ]], {\[Omega], 1, 4}
  ]

Regards
   Jens

Nasser Abbasi wrote:
> "Nasser Abbasi" <nma at 12000.org> wrote in message news:...
>> The basic problem I have is that I want to have a button, in which it is 
>> in a fixed location, and only when clicked will the Manipulate 
>> 'expression' gets evaluated.  The reason I want to do this, is that now I 
>> have number of controls, and I do not want the function called everytime I 
>> adjust one control, because I might have few to adjust before I am ready. 
>> So I want a way to adjust/set the control to some values, and only then 
>> tell manipulate to call the function with the current set of values in the 
>> control.
>>
>> So, I figured I make a button, which I click on when I am ready to do 
>> this.
>>
>> This is the first solution I came up with, using a flag
>>
>> ---------------- code------
>> Remove["Global`*"]
>> flag = True;
>> foo[x_] := Text[x]
>> res = 0;
>> m = Manipulate[If[flag, {flag = False; res = foo[x]}, res], {x, 0, 10}];
>> Column[{m, Button["Press ...", {flag = True; m}]}]
>> ----- end code ------------------
>>
>> The problem with the above is that the button is floating. So if foo[] 
>> generates large output, the button will move lower. I wanted the button to 
>> be fixed, above the controls themselves used by Manipulate.
>>
>> It sounds simple, but I have no idea how to do it. I looked at 2 examples 
>> in demonstration which uses buttons, but the code is too complicated for 
>> me to see the pattern.
>>
>> I tried this:
>>
>> foo[x_] := Module[{}, Print["in foo x=", x]; Text[x]]
>>
>> Manipulate[ Button["press to call foo...", foo[x]], {x, 0, 1}]
>>
>> The problem with the above is that the button goes in the place where the 
>> output from foo[] is supposed to go. I know foo[] is getting called OK, 
>> with the updated x values, but the button is in the way for the any 
>> graphics output to be displayed from foo[].
>>
>> is there a simple solution to this?
>>
>> thanks,
>> Nasser
>>
>>
> 
> I found a way! The trick was to use a Button as a pure function inside 
> Manipulate
> 
> foo[x_] := Text[x]
> 
> Manipulate[If[doIt, {doIt = False; res = foo[x]}, res], {x, 0, 1},
>   {{doIt, True, ""}, Button["RUN", doIt = True] & }
> ]
> 
> I am a happy man now, I got my button where I want it :)
> 
> Nasser 
> 
> 


  • Prev by Date: Re: Labelled matrix plot
  • Next by Date: Re: How to make a Button inside Manipulate?
  • Previous by thread: How to make a Button inside Manipulate?
  • Next by thread: Re: How to make a Button inside Manipulate?