So having been a little let down by the behavior of Gateway Events in V8.0:
And lacking a solution for a few weeks I reverted to the following solution to get the ‘trigger’ property on a Sound Player to toggle on and off: I basically spawn a thread with an enclosed sleep timer, which on initiation sets a property on the SoundPlayer and on conclusion resets it. I have a propertyChanged script which tracks changes in numbers of alarms, as well as the current state of the thread which times out the alarm.
It works as well as the old gateway timer did, and given the divergences (in my opinion) between how Gateway Events work now and how the 8.0 manual says they ought, I’d prefer to leave my solution in place, since I 100% understand how it works and I control how or if its behavior changes. I’m really only looking for serious concerns about possible mismanagement of memory or other resources. This is the first time I’ve mucked around with threads in Python, and I haven’t much experience with them in other languages either. So I can very easily see myself setting up another issue down the road.
Apologies for the unPythonic Grammar and the probably needlessly long code:
import time from threading import Thread def sleepFunc(secs,triggerState): #This function waits, then sets two Sound Player properties time.sleep(secs) event.source.trigger = triggerState event.source.ThreadClear = True if event.propertyName == 'AlarmTotal': #if there are Alarms, turn on RingToggle and set the Sound Player on. #if there aren't, turn off RingToggle and trigger on the Sound Player if event.newValue != 0: event.source.RingToggle = True else: event.source.RingToggle = False event.source.trigger = bool(event.source.AlarmTotal) elif (event.propertyName == 'trigger') or (event.propertyName == 'ThreadClear'): #Once 'Ring Toggle' is on the player will cycle 'trigger' on and off till it is removed #Each cycle will be spawned as a thread, and a new one will not start till the old one #concludes. if event.source.ThreadClear: event.source.ThreadClear = False if ( (event.source.AlarmTotal != 0) and (event.source.trigger) ): alarmThread = Thread(target = sleepfunc, args = (0.25,False) ) alarmThread.start() elif ( (event.source.AlarmTotal != 0) and (not event.source.trigger) ): alarmThread = Thread(target = sleepfunc, args = (1.75,True) ) alarmThread.start() if event.source.AlarmTotal = 0: event.source.trigger = False