Automatically change tab after # seconds in a loop [Perspective]

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

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.

  1. The Gateway Timer Script should invoke something like system.util.sendMessage('MyProjectName', 'GATEWAYNEXTTAB',scope='S')
  2. The Project needs to have a Message Handler configured in a SESSION EVENT (in the Menu Toolbar, select Project > Session Events > Message) and named ‘GATEWAYNEXTTAB’. This Handler needs to invoke `system.perspective.sendMessage(‘SESSIONNEXTTAB’, scope=‘session’)
  3. Then the Tab Container itself needs a Handler with a name of ‘SESSIONNEXTTAB’ set to listen at the session scope, and it needs to invoke the code I presented above.
1 Like

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)

    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 :wink: ).

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.

1 Like

Okay, this works for me:

Gateway Timer Event/Script:
Screen Shot 2020-06-25 at 1.39.01 PM

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.
Screen Shot 2020-06-26 at 9.27.16 AM