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

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.

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

2 Likes

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

2 Likes

Hi, i'm new to ignition Perspective so i am currently working on a similar project that involves a main view configured as a tab container, in this view i added in total 4 tabs (0,1,2,3) and in each tab i added a coordinate container for working in it, i am having trouble with the scripting in general, i know how to add all the scripting except the gateway logging, but apart from that, it is not working, so i dont know what to do with the tab timer project.
hoping for the support, looking forward for the help.

Welcome to the forum.
It's going to be hard to debug your problem with the information given. Please confirm with screengrabs that you have done all the steps in cmallonee's post #9.

sure!
the main information described is this:
First pic is the perspective menu
image
Second pic is the arrange of the proyect, with the main view as a tab container and in each tab there is a coordinate container
image

continuation:
Gateway timer script third pic


Session message handlers

another part
Script configuration TabContainer

Also i added in custom properties the "tab_count" property

Hi @Saul_Garcia, I want to make you aware of the Carousel component (which wasn't out when OP posted) that can essentially automatically play through preconfigured panes on a schedule. Check it out to see if it meets your needs - its much easier to set up as you can do most of this configuration right from the Property editor in the designer.

3 Likes

It looks as though you haven't saved it yet.

i took the screenshot as i was typing it, so thats why it looks like it, but here it is


im still struggling with it, cause i dont know if i have to add another custom property or function that is related with the currentTabIndex
thank you all for the support