The Time slider — the red vertical marker that half-hides on the left hand side of the canvas — is a way of turning the canvas into a score: drag the slider around (or set it's position programmatically) and the visual elements that it crosses get executed. The Processing tutorial has some examples, and there are some handy conventions for writing code that starts, continues and stops as this red marker enters and exits boxes.
Sometimes, however, the global, single marker is insufficient — perhaps you'd like to make a little organization in one corner of the sheet out of just a few boxes; perhaps you'd like much more control over the scripting of the slider itself, without having to worry about accidently crossing boxes (and thus executing them) all over the sheet.
The solution is to create your own Time Sliders in code that a) operate only on a subset of the sheet and b) operate only when your code tells them to operate.
The connivence method for creating a slider is simply this:
slider = newSubTimeSlider("sub1", _self)
This makes a new red bar that is called "sub1", thats a sub-element of this element, and is positioned at the left edge of this element. This function has a few options, here's its full signature:
def newSubTimeSlider(name, parent, position=None, predicate=None, exclusive=1):
predicate
is a function that returns all the elements that you want to see executed by this line. By default it's something like this:
def predicate():
return _self.subelements.values()
This just returns all of the elements that are subelements of this one. Remember, you which elements are subelements of what using the "modify dispatch" tool:
Setting exclusive
will main that the main slider no longer executes the boxes that this sub-slider claims to own.
If we make a couple of child elements of this element we'll have something like this:
Note how the red marker in this case tries to indicate, in red, the limited subset of the sheet that it's going to execute when it enters and exits.
If you drag this slider over the boxes 'child' and 'child2' you'll find that nothing happens. To actually get the slider to execute you need to update it by calling it.
slider = newSubTimeSlider("sub1", _self)
_r = slider
That's it, we're basically done. Take a look at VisualElementLifecycles: everything still applies, both to the code that's in the sub-elements and to the code here that you might use to make _self.runner_.update
run repeatedly.