Dynamic go back button Perspective

Hi,

I am new to Ignition and the scripting in this program.
I have a “go back” button in my dockview and i want to make it go back to the previous view.
All my views are in the same page.
So i know what view i want to go back from any view i am in, but because it is in the dockview it has to be dynamic.
I have tried different scripting event, but cant get it to work.
My quenstion: is there a way to make it dynamic.

Ik have to do the same with a text field for showing my status per machine.

Thanks a lot in advance!

Ronnie

Using Perspective to “go back” to different Views instead of using the browser to go back to different Pages is going to be a fairly complex process. I’ve thought a bit about how to set this up in the past and there are a few ways to do this:

  1. You could query a database which is set up to have a column like currentViewPath and a column like backViewPath, and then when the button is pressed query for the backViewPath based on your current View’s path and navigate to the result.
# If you don't have a default database for the project, you'll need to include an argument for that
# This also assumes a table named "ViewNavigationLinking"
viewPath = system.db.runQuery("select backViewPath from ViewNavigationLinking where currentViewPath={0}".format(self.page.props.primaryView))
system.perspective.navigate(view=viewPath)
  1. You could have a tag which operates the same way.
viewPath = system.tag.readBlocking([self.page.props.primaryView])[0]
system.perspective.navigate(view=viewPath)
  1. You could have a custom property on EVERY View which declares the path of the View to go back to from this View. This would then also require a configured message listener on the View root listening at the Page or Session scope as well as a broadcast from the button on that same scope.

Button script:

system.perspective.sendMessage('VIEWGOBACK', scope='page')

Configure a Message Handler on the root of every View with the handler name of “VIEWGOBACK” and the following script:

system.perspective.navigate(view=self.custom.backViewPath)
2 Likes

Hi cmallonee,

I am sorry for the late reaction.
I am planning to add a parameter on every view, so i know when it is open.
I want to make labels visible in the dockview in certain views, i want to use this parameter also for the navigation, but i cant figure out how to make a parameter true when a view is open.

I hope you can help me.

Thank you in advance.

With kind regards,

Ronnie Rijkers

  1. Create the custom property with the desired key (custom.myKey).
  2. Set the value to false.
  3. Create a View onStartup Event, and associate a Script Action to the Event.
  4. Supply the following code for the script: self.custom.myKey = True (note the case difference in "true").

BUT... This is not going to do what you want, because you have no way to refer to this property from outside the View. You could move the relevant value to a param, but you still have no way to know WHICH View you're looking at.

cmallonee,

I am going to make tags in the tagbrowser by each view.
This way i know which view is open. I tried by making the myKey true on view startup and false on view shutdown. But this dont seem to work. This way i thought to make the right tag high, but it seems like the shutdown script dont run when i leave the view, is this possible?

Other question, what is the different between the True and “true” in the script.

Thankyou

I just verified that it should be working, but there are some idiosyncrasies when it comes to View onShutdown Events:

  1. You may not use system.perspective calls within a View onShutdown Event, because the reference system.perspective calls require to a perspective resource is no longer valid (the View no longer exists, so we have no way to refer to it). So if your onShutdown Event contains any usage of system.perspective, you need to remove it.
  2. Other system calls should work just fine. I just tried system.tag.writeBlocking() as part of a View onShutdown Event and had no issue.

View properties are stored in a .json file, and JSON uses Java variables. Java represents binary truth values with true and false.

Scripting is done in Jython, which happens to use Python's representation of binary truth values (so True and False). If you supply a value of true or false in a script, it will fail to execute at runtime (I believe it throws a NameError). Likewise, if you supply True or False to the Property Editor, it will interpret that value as a String.

I have done it in a different way, i made a session custom parameter OpenView where i write in the onStartup view the next code:
self.session.custom.View = "5.2 Cell02_Zone02" For example.

Now it refresh the parameter each time i open a new view with the name of the view. I have made a binding to a memory tag set to string that holds the name of the view that is currently open.

Now i am searching for a way to fill my memory tag called PreviousView that must have 1 delay in changing from views so that i can use this tag to link to my dynamic back button.

Thanks for the help, and i will let you know if i am stuck with the PreviousView tag!

The problem with this method is that you will only be able to go back one View. If a user keeps clicking the button, you’ll go back-and-forth between two Views.

That hasn’t come to my mind, you are right.
Then i should have a greater memory of the previous views.
I have also a navigation where all the screens are visible so there can be navigated in the entire application, the screens don’t have to direct linked so this is going to be a tough one.

The application has a standard layering, so i can make the choice to write a script that goes one layer up the ladder by pressing the button. It works, but ain’t pretty.
I am going to think about this, and try some of your suggestions.

Thankyou!

This View will wreak absolute havoc with your method as each View will write itself as being open in your property/tag setup. This is why View navigation is a bad idea to try to manage. As part of the View onStartup, you could make a check against the Active Page to see if it's the page you want to apply this logic on:

if page.props.path = '/some/page/path:
    # write the viewPath of the current View to props/tag

but this requires a hard-coded path.