Nit: all
accepts a generator. Wrapping the argument in square brackets means you're passing in an eagerly evaluated list, avoiding the (presumably intended) optimization of not reading the separate tag if either of the first two conditions fail.
At the risk of showing my ignorance, how do you write it as a generator?
I'm not sure you can with three literals like that.. I'll invite someone to correct me.
Seems to work:
from com.inductiveautomation.ignition.common.model.values import BasicQualifiedValue
def myGenerator():
yield currentValue
yield currentValue.value == 'AP'
yield system.tag.readBlocking('[default]Test Popup')[0].value
currentValue = BasicQualifiedValue('AP')
gen = myGenerator()
print all(gen)
Just use "and
" at this point !
if currentValue and currentValue.value and system.tag.readBlocking()
Personally, I used all, because I prefer the way it reads, not really looking for the performance pickup in this particular instance.
So I tried several things.
I tried on another project where I'm sure I'm the only one that has it opened.
I tried this code first:
logger = system.util.getLogger("myLogger")
logger.info("test")
if currentValue and currentValue.value == "AP" and not system.tag.readBlocking(["[default]Test Popup"])[0].value:
logger.info("1")
for index, sessions in enumerate(system.perspective.getSessionInfo(usernameFilter = "AP", projectFilter="Swecos_PCP")):
logger.info("2")
if sessions[index].id != self.props.id:
continue
logger.info("3")
for pID in sessions[index].pageIds:
logger.info("4")
system.perspective.openPopup("Test_Popup","Popup/testPopup", modal=True, sessionId=self.props.id, pageId=pID)
For this code I have this problem:
Then, as I think there is only one session (mine), I tried this:
logger = system.util.getLogger("myLogger")
logger.info("test")
if currentValue and currentValue.value == "AP" and not system.tag.readBlocking(["[default]Test Popup"])[0].value:
logger.info("1")
for index, sessions in enumerate(system.perspective.getSessionInfo(usernameFilter = "AP", projectFilter="Swecos_PCP")):
logger.info("2")
#if sessions[index].id != self.props.id:
#continue
#logger.info("3")
for pID in sessions[index].pageIds:
logger.info("4")
system.perspective.openPopup("Test_Popup","Popup/testPopup", modal=True, sessionId=self.props.id, pageId=pID)
And I got almost the same error (just 2 lines change):
Just if you want to know, the lines are (first error ---- second error):
-
at org.python.pycode._pyx9350465.valueChanged$1(:6) ---- at org.python.pycode._pyx9350655.valueChanged$1(:6)
-
at org.python.pycode._pyx9350465.call_function() ---- at org.python.pycode._pyx9350655.call_function()
And finally I tried without the for loop and I'm back with my big error of the beginning
In your code sessions is a dictionary, not a list, so it should be sessions.id
instead of session[index].id
, same for sessions.pageIds
You are right thanks!
I am a bit confused because the documentation would say otherwise:
It says nothing about returning a dictionary , so based on the documentation of the function, an index should be needed.
Turns out, it does exactly what the documentation says.
But Alexandre is enumerating into index, sessions
, so sessions
is already an element of the returned list. Which makes it a misleading variable name.
Yeah, I just saw that. Good Ol' ID10T error as they copied my code.
Ugghhh.
Okay, corrected code:
if all([currentValue,currentValue.value == "AP",system.tag.readBlocking(["[default]Test Popup"])[0].value]):
for session in system.perspective.getSessionInfo():
if sessions.id != self.props.id:
continue
for pID in sessions.pageIds:
system.perspective.openPopup("Test_Popup","Popup/testPopup",modal=True,sessionId=self.props.id,pageId=pID)