I am needing to have a timer that will switch to the next tab every 60 seconds, and then continue to loop through the tabs. I am attempting to setup the timer as a Gateway Event, but I feel I am incorrectly calling the tab.
Thanks for any help!
I am needing to have a timer that will switch to the next tab every 60 seconds, and then continue to loop through the tabs. I am attempting to setup the timer as a Gateway Event, but I feel I am incorrectly calling the tab.
Thanks for any help!
I might be misunderstanding the question. Are you attempting to control a userâs browser to switch between tabs or do you have a Tab Container that you would like to switch on a timer?
A tab container. For context, the URL will be opened on a TV monitor without any other interactions. Just need the tab container to switch to the next tab every 60 seconds.
I would recommend using system.util.sendMessage()
(docs) to âbroadcastâ every 60 seconds. Make sure youâre specifying the session scope. You would then configure a Message Handler on the Tab Container (make sure in the handler that youâre specifying the session scope), and whenever it hears the message, just set TabContainer.props.activeTab to the next available tab. Youâll also want a custom property which defines the maximum known number of tabs so that you can loop back to the first.
Something like this in the handler:
self.props.activeTab = (self.props.activeTab + 1) % self.custom.total_tabs
Update:
Thinking about this some more, the system.util.sendMessage will only be heard at the SESSION level, so you will need to have three pieces.
system.util.sendMessage('MyProjectName', 'GATEWAYNEXTTAB',scope='S')
Really appreciate the followup! I feel am very close, but still missing or incorrectly doing something.
Gateway Timer Script
project = 'MyProjectName'
messageHandler = 'GatewayNextTab'
scope = 'S'
system.util.sendMessage(project, messageHandler, scope)
Gateway Message Handler (I also added a Session Event Message Handler with below to try it out)
GatewayNextTab
messageType = 'SessionNextTab'
scope = 'session'
system.perspective.sendMessage(messageType, scope)
Script Config on Tab Container Root
Message Type = SessionNextTab
self.props.activeTab = (self.props.activeTab + 1) % self.custom.total_tabs
Ah, okay. Two mistakes on my part, and sort of one mistake on your part (you didnât double-check my work, so you get some of the blame ).
Iâve updated my post because you do want SESSION Event - not GATEWAY Event (Iâm sorry, Iâm only halfway through my morning coffee).
In your code you removed the keyword designations, so your arguments are being interpreted incorrectly; your use of system.perspective.sendMessage()
will interpret your arguments as the messageHandler
arg and the payload
arg. You need to specify the args in this manner, because you are NOT supplying a payload:
# we need to supply an empty payload arg AND we need to use the "scope" keyword
messageType = 'SessionNextTab'
scope = 'session'
system.perspective.sendMessage(messageType, payload={}, scope=scope)
Not sure why I am unable to get it to work. I feel as if the Gateway Timer isnât reaching the messages arenât reaching the tab container message handler.
What I would recommend is using a line of logging as the first piece of each so that you can see where the messages are being heard. Iâll set up an actual working example and screenshot the settings.
Okay, this works for me:
Gateway Timer Event/Script:
Session Message Event/Script:
Component Message Handler:
Gateway logging:
My Tab Container is successfully flipping to the next tab every five seconds, and goes from the last to the first when after the last has been displayed for five seconds.
I'm getting the confirmations in the Gateway Logger!
I'm also getting an error:
Error running TabTest@C/root/TabContainer.onMessageReceived(self, payload): Traceback (most recent call last): File "function:onMessageReceived", line 3, in onMessageReceived AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'tab_count'
Tried the total_tabs mentioned earlier as well.
Error running TabTest@C/root/TabContainer.onMessageReceived(self, payload): Traceback (most recent call last): File "function:onMessageReceived", line 3, in onMessageReceived AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'total_tabs'
You need to set your own custom property on the Tab Container.