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.

I would like to create a Manipulate slider that iterates over a discrete set of items. Something like the following

Manipulate[u, CharacterRange["a","z"]]

produces a drop-down menu, which doesn't have a great interaction style. I must move the mouse back up to the top to get a new item, taking my eyes off the display back to the controls, rather than being able to just slide around without having to look at the controls too often.

Even better would be some kind of keyboard control that would let me left-and-right arrow my way through a collection. Then I'd never have to take my eyes off the target display. But that would be too intuitive [sarcasm].

share|improve this question
2  
Manipulate[u, {u, CharacterRange["a", "g"], ControlType -> Slider}] –  Kuba Jun 26 '13 at 19:43
add comment

1 Answer

up vote 3 down vote accepted

EventHandler

DynamicModule[
 {u = CharacterRange["a", "e"]},
 EventHandler[
  Framed[Dynamic@First@u],
  {
   {"MouseClicked", 1} :> (u = RotateLeft[u, 1]), 
   {"MouseClicked", 2} :> (u = RotateRight[u, 1])
   }
  ]
 ]

enter image description here

But since second button is showing menu it is not very useful :) It is only a method so You can change event trigger.

You can also take a look at NotebookEventActions. Or CellEventActions:

CellEventActions

DynamicModule[{u = CharacterRange["a", "e"]},
  CellPrint[
   TextCell[Dynamic@First@u, "Output", 
    CellEventActions -> {"LeftArrowKeyDown" :> (u = RotateLeft[u, 1]),
                         "RightArrowKeyDown" :> (u = RotateRight[u, 1])}
]]];

This is what I like the most. But then You are not able to move selection cursor with arrows, not so much important but it depends what are You doing. :)


Standard way

Slider

 Manipulate[u, {u, CharacterRange["a", "g"], ControlType -> Slider}]

enter image description here

Manipulator

Edit "StepLeftButton" does not work here how I expected. Anyone has an idea why? (I will remove it till explanation)

Manipulate[u, {u, CharacterRange["a", "g"], ControlType -> Manipulator, 
   AppearanceElements -> {"StepRightButton"}, Appearance -> "Open"}]

enter image description here

share|improve this answer
    
In the "Standard way" Manipulator, answer, the "StepLeftButton" doesn't seem to work :( –  Reb.Cabin Jun 26 '13 at 21:54
    
@Reb.Cabin You are right. I'm not sure why it is so... –  Kuba Jun 26 '13 at 22:01
add comment

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.