Updating the time slider using Python callbacks

The time slider annotation object draws uniform time progress. If you have files whose dT fluctuates a lot then you might expect VisIt's time slider to reflect that when it draws its time progress. That behavior can be accomplished using the following Python function that gets installed as a callback function on the SetTimeSliderState action. This means that whenever the time state changes in VisIt, the Python function will be called to update the time slider according to the custom programmed behavior.

If you want to make VisIt perform these actions by default when you run VisIt, create a file in your home directory's .visit directory called visitrc. The path to the file will be: ~/.visit/visitrc. This is a special file that makes VisIt launch its CLI at startup to execute whatever Python code exists in the file. In this case, we're installing a callback function that will execute when the time slider gets set. The effect of the callback functions here is to set their "percentage complete" based on where the current time or cycle exists in the complete range of times or cycles. The time slider label is also set accordingly.

Showing time

def update_time_slider(newState):
    m = GetMetaData(GetWindowInformation().activeSource)
    tmin = m.times[0]
    tmax = m.times[-1]
    dt = tmax - tmin
    tcur = m.times[newState]
    t = (tcur - tmin) /  dt
    # Update the time slider
    objnames = GetAnnotationObjectNames()
    for name in objnames:
        obj = GetAnnotationObject(name)
        if "TimeSliderObject" in str(type(obj)):
            obj.timeDisplay = obj.UserSpecified
            obj.percentComplete = int(t * 100)
            obj.text = "Time = %g" % tcur
            print "Set time slider position to ",obj.percentComplete
            return

RegisterCallback("SetTimeSliderStateRPC", update_time_slider)

Showing cycles

def update_time_slider(newState):
    m = GetMetaData(GetWindowInformation().activeSource)
    tmin = m.cycles[0]
    tmax = m.cycles[-1]
    dt = tmax - tmin
    tcur = m.cycles[newState]
    t = (tcur - tmin) / float(dt)
    # Update the time slider
    objnames = GetAnnotationObjectNames()
    for name in objnames:
        obj = GetAnnotationObject(name)
        if "TimeSliderObject" in str(type(obj)):
            obj.timeDisplay = obj.UserSpecified
            obj.percentComplete = int(t * 100)
            obj.text = "Cycle = %d" % tcur
            print "Set time slider position to ",obj.percentComplete
            return

def next_time_slider():
    if (GetTimeSliders()):
        currentState = GetTimeSliders()[GetActiveTimeSlider()]
        update_time_slider(currentState+1)

def prev_time_slider():
    if (GetTimeSliders()):
        currentState = GetTimeSliders()[GetActiveTimeSlider()]
        update_time_slider(currentState-1)


RegisterCallback("SetTimeSliderStateRPC", update_time_slider)
RegisterCallback("TimeSliderNextStateRPC", next_time_slider)
RegisterCallback("TimeSliderPreviousStateRPC", prev_time_slider)