I’m using a Momentary button for Logging In. The controlValue is derived from a tag from the PLC which is a Pushbutton.
I want it to navigate to another window after it is pressed and after it checks the value of another property (which is a tag). I wrote a script in actionperformed but it doesn’t work (It logs in but doesn’t navigate)
if event.source.controlValue==1:
if event.source.currentUserLevel>0:
system.nav.swapTo("Window")
else:
system.gui.warningBox("Login Failed")
No, I do not.
There are no permissions currently in any of those windows! The warning box pops up even if the conditions in the if statement are satisfied. I'm guessing its a timing issue and its reading the values from the PLC even before the PLC is able to edit them.
I made it to work by binding the tag values to the Root Container and made a script in propertyChange of the Root Container. So, whenever any property of the Root Container changes, it automatically navigates to the "Window" screen.
It worked alright but my boss needs a simpler solution so that he can get a better understanding of how it works!
This probably means that whatever you are using to populate the currentUserLevel is not working. You should post the code for the binding or whatever scripting you are trying to use to populate that value.
The CurrentUserLevel automatically gets changed by the PLC once the Login Pushbutton is pressed(once the controlValue becomes 1). The problem, however, is that the script is running before the CurrentUserLevel is edited by the PLC, thus the error! I tried using the time.sleep function but to no avail.
Is there a way where we can let the button perform its action (set controlValue to 1) first and then wait a couple of seconds and then check the if statement?
That looks good, Nick. That code would go in the propertyChange event of the Root Container (for oxanemi’s info). There would be no code in the momentary button and when the PLC code finally changed the custom property, then this code would go be affected. Very good.
if event.propertyName == "currentUserLevel":
if event.newValue > 0:
system.nav.swapTo("Window")
else:
system.gui.warningBox("Login Failed")
[/quote]
It worked for the navigation part well! But when the login fails, it doesnt show up the warning box!
The initial value of currentUserLevel is 0 and it stays the same when a login fails. I tried using this code but to no avail.
if controlValue==1:
if event.propertyName == "currentUserLevel":
if event.newValue > 0:
system.nav.swapTo("Window")
elif event.newValue==event.oldValue:
system.gui.warningBox("Login Failed")
I tried using it without the first if statement and it still did not return a warning!
You could try setting the currentUserLevel to negative one (-1) when a login fails and then set it back to zero (0) after the system message pops up. Of course, you’ll have to update your code to look for -1.
You would change it in the PLC. There are an infinite number of ways of solving this. Look into trying to use client tags to figure out if the button was pressed.
When a login fails does the PLC set event.source.currentUserLevel to 0?
If so then you can use the script below. Put it on the propertyChange event on the button.
This script does not require changing the PLC.
if event.propertyName == "controlValue":
if event.newValue == 1:
event.source.currentUserLevel = -1
if event.propertyName == "currentUserLevel":
if event.newValue > 0:
system.nav.swapTo("Window")
elif event.newValue == 0:
system.gui.warningBox("Login Failed")
[quote=“nmudge”]When a login fails does the PLC set event.source.currentUserLevel to 0?
If so then you can use the script below. Put it on the propertyChange event on the button.
This script does not require changing the PLC.
if event.propertyName == "controlValue":
if event.newValue == 1:
event.source.currentUserLevel = -1
if event.propertyName == "currentUserLevel":
if event.newValue > 0:
system.nav.swapTo("Window")
elif event.newValue == 0:
system.gui.warningBox("Login Failed")