Currently with a bidirectional bind on a slider if defer updates is checked it seems to wait around 1 second of not actively changing the value to submit the value.
In the case that my user wants to sit and hold it while deciding or fine tuning the value on the touch screen this can cause unwanted results.
If I understand correctly, you want to wait until the user releases the slider before committing the value?
If there is a debounce on the slider value, then you might want to disable the bi-directional binding and use one of the events (onMouseUp, onPointerUp, onTouchEnd) to trigger a write to the tag/bidirectional param/custom prop
I would make this a two-step process. Do not bind the slider bidirectionally to the target, instead add a submit button that pulls in the slider value then writes it to the tag.
I understand the workarounds being suggested, but there are still some downsides to the proposed suggestions:
Using onMouseUp: When you release your mouse outside the component, no event will be triggered
Using a two-step process: sometimes it really makes no sense to make it a two step process.
Someone from my team came up with a different solutions, but I'd like to verify it's safe to use.
from threading import Timer
from functools import wraps
# Initialize counter
c = 1
# Get logger instance
logger = system.util.getLogger("testdebounce")
def debounce(duration):
"""Decorator to debounce function calls within a given duration."""
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
global c
indx = c # Capture the current counter value
def debounce_msg():
"""Executes the function if it's the last invocation within the debounce period."""
if c - 1 == indx:
func(*args, **kwargs)
# Start the timer to check if this is the last call
Timer(duration, debounce_msg).start()
# Increment the counter
c += 1
return wrapper
return decorator
@debounce(0.3)
def printDebounce(msg, indx):
"""Logs the message with debounce applied."""
logger.info(msg)
# system.perspective.print("MSG:" + str(msg) + ' ind ' + str(indx))
Doing this, makes sure we have a 'defer updates' functionality with the time delay that we want. However, I do wonder if this has the same drawbacks as time.sleep, or if it's just clean to do it like this. Any opinions?
Not so much dangerous, as burdensome. Timer starts a thread that immediately goes to sleep. That's pretty heavy weight. I would focus attention on eliminating the need for the debounce.
(I wouldn't ever use jython's Timer. Don't use stuff from the jython stdlib where java alternatives exist.)