Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Combining Slider and SetterBar in Manipulate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114960] Re: Combining Slider and SetterBar in Manipulate
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Fri, 24 Dec 2010 04:12:17 -0500 (EST)
  • Reply-to: jfultz at wolfram.com

The string is merely a label.  The actual value of qt is the numeric value on 
the lhs of the rules.  So, instead of...

{{qt, 7, "Special"}, {7 -> "Rising", 5 -> "Smile", 20 -> "Saws", 
  12 -> "Falling"}, ControlType -> SetterBar}

it would be something like this...

{{qt, 3}, {7 -> "Rising", 5 -> "Smile", 20 -> "Saws", 
  12 -> "Falling"}, ControlType -> SetterBar}

I.e., the initial value would probably be a number (since you seem to be using 
numbers as values...although that's certainly not required), and it has to be a 
*different* number than any of the ones you're using.

Also...a bit of unsolicited advice.  Your use of Block is a *bad* idea. It's 
always bad to reference Block-scoped or Module-scoped variables declared outside 
of a Manipulate or Dynamic from within that Manipulate/Dynamic.  If you're 
wanting to localize the variable 'someData', then Manipulate offers you an easy 
way to do that.  Add someData as a control variable, but no control appearance.  
I.e.,

{someData, ControlType->None}

So, after my proposed changes, your code looks like:

Manipulate[
 ListLinePlot[someData[[tinx, 2 ;;]]], {{tinx, 1, "Time"}, 1, 25, 
  1}, {{qt, 3}, {7 -> "Rising", 5 -> "Smile", 20 -> "Saws", 
   12 -> "Falling"}, ControlType -> SetterBar}, 
 Pane[Text@Dynamic[tinx]], {someData, ControlType -> None}, 
 ControlPlacement -> Top, 
 Initialization :> (someData = 
    Table[Sin[i j]*Cos[j] // N, {i, 25}, {j, 12}];
   tinx = 1)]

Sincerely,

John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.


On Thu, 23 Dec 2010 03:56:25 -0500 (EST), JohnH wrote:
> I am looking for a solution to what should be a common and simple
> problem. I have a slider to control time, but I also want to use a
> SetterBar to pick out some interesting dates. The bare bones of my
> current attempt is:
>
> Block[{someData},
> Manipulate[
> ListLinePlot[someData[[tinx,2;;]]],
> {{tinx,1,"Time"},1,25,1},
> {{qt,7,"Special"},{7->"Rising",5->"Smile",20->"Saws",12-
>> "Falling"},ControlType->SetterBar},
> Pane[Text@Dynamic[tinx]],
> ControlPlacement->Top,
> Initialization:>(
> someData=Table[Sin[i j]*Cos[j]//N,{i,25},{j,12}];
> tinx=1)
> ]
> ]
>
> Ideally, none of the setter buttons would be selected if the time was
> not one of the special ones.  Clicking on one of the setter buttons
> would set the time to that value.
>
> Any suggestions would be appreciated.




  • Prev by Date: Re: Map function with 2 variables
  • Next by Date: Re: Mathematica daily WTF
  • Previous by thread: Combining Slider and SetterBar in Manipulate
  • Next by thread: Fixing padding inside Inset