I was wondering if anyone can break down on what this error means and how I can fix it? I would appreciate any help that may come.
In the script (shown above) it looks like this that Line 39 is referring to. Another thing to know is that this is under the “Action Performed” for a button component.
ORIGINAL CODE:
from java.awt import Font
from com.inductiveautomation.factorypmi.application import VisionDesktop
from com.inductiveautomation.factorypmi.application.components.template import VisionTemplate
desktop_handle = VisionDesktop.CURRENT_DESKTOP.get()
system.gui.openDesktop(windows = ['Popups/MultitrendWindow'], title = "Multi Trend", handle = "Multi Trend", width = 830, height = 705, x = 350, y = 100)
window = system.gui.desktop("Multi Trend").getWindow('Popups/MultitrendWindow')
windows = system.gui.desktop(desktop_handle).getOpenedWindowNames()
found = False
try:
system.gui.openDesktop(windows = ['Popups/MultitrendWindow'], title = "Multi Trend", handle = "Multi Trend", width = 830, height = 705, x = 350, y = 100)
except:
pass
for path in windows:
if 'Popups/MultitrendWindow' in path:
found = True
break
if not found :
system.nav.desktop("Multi Trend").swapTo('Popups/MultitrendWindow', {'new_tags':system.dataset.toDataSet(['tag'], [[event.source.parent.tagPath]]), 'trend_tags':
system.dataset.toDataSet([], [[]])})
window2 = system.gui.desktop("Multi Trend").getWindow('Popups/MultitrendWindow'
if not found:
parent = event.parent #original: self.parent
while type(parent.parent) != VisionTemplate:
parent = parent.parent #Original: parent.parent
new_x = parent.getX() + 100
try:
# system.nav.getCurrentWindow() will throw an exception when called in the Designer
root = system.gui.getWindow(system.nav.getCurrentWindow()).getRootContainer()
if parent.getX() > round(root.getWidth()/2):
new_x = parent.getX() - 100 - window.getWidth()
except:
pass
new_y = parent.getY()
try:
# system.nav.getCurrentWindow() will throw an exception when called in the Designer
if new_y + window.getHeight() > root.getHeight():
new_y = root.getHeight() - window.getHeight()
except:
pass
window2.getRootContainer().new_tags = system.dataset.toDataSet(['tag'],
[[event.source.parent.tagPath]])
window2.getRootContainer().configChart()
Currently, the view I am trying to edit is being edited by someone else, so I can not test it out at the moment. I will get to as soon as I can access it and provide some feedback. Thank you so much!
If the error persists, is it possible if I can bypass it?
It seems the overall function that I want it to do works, but this error is something I do not want to appear during one of my client’s use.
Opening a popup window within a new desktop window to allow the user to drag the popup onto another desktop screen and perform its usual functions within that popup window. This is what I have been working on and this function works fine, it is just that the error that I mention shows whenever I the action is performed for the button component.
I don’t know vision at all, but here’s the most obvious reason that I can think of for your script to fail:
The comparison type(parent.parent) != VisionTemplate is never true, and thus it ends up reaching the top level, gets None as its parent, then fails.
Make sure VisionTemplate is the proper thing to check for. Also, you could try with isinstance(parent.parent, VisionTemplate) instead of type().
If you’re trying to reach the top-most level as I think you are, and there’s no built-in function or method to get it, maybe you could start from root, as it seems you’re already using functions to get it. I expect root.parent will be the top-most thing in the hierarchy.
I just wanted to give an update and I implemented your suggestions from yesterday but still no luck. I will continue to go in that same route and see if I can find something else. I do want to thank you for all the help, I greatly appreciate for pushing me in the right direction!
Just to give some key points. I have a second desktop view that I use for a popup to appear on it. The reason being is that my client wanted that popup to be able to drag across monitors. It still functions as it should, its just that I am unsure how to overcome this error.
Yes sorry, I was referring to the Output Console. And my script looks like how it shown in the original post. Was there something I did incorrect on the previous reply to Jordan? I can try again
from java.awt import Font
from com.inductiveautomation.factorypmi.application import VisionDesktop
from com.inductiveautomation.factorypmi.application.components.template import VisionTemplate
desktop_handle = VisionDesktop.CURRENT_DESKTOP.get()
system.gui.openDesktop(windows = ['Popups/MultitrendWindow'], title = "Multi Trend", handle = "Multi Trend", width = 830, height = 705, x = 350, y = 100)
window = system.gui.desktop("Multi Trend").getWindow('Popups/MultitrendWindow')
windows = system.gui.desktop(desktop_handle).getOpenedWindowNames()
found = False
try:
system.gui.openDesktop(windows = ['Popups/MultitrendWindow'], title = "Multi Trend", handle = "Multi Trend", width = 830, height = 705, x = 350, y = 100)
except:
pass
for path in windows:
if 'Popups/MultitrendWindow' in path:
found = True
break
if not found :
system.nav.desktop("Multi Trend").swapTo('Popups/MultitrendWindow', {'new_tags':system.dataset.toDataSet(['tag'], [[event.source.parent.tagPath]]), 'trend_tags':
system.dataset.toDataSet([], [[]])})
window2 = system.gui.desktop("Multi Trend").getWindow('Popups/MultitrendWindow')
if not found:
parent = event.source
while parent is not None:
win = parent
print type(win)
parent = win.getParent()
new_x = parent.getX() + 100
try:
# system.nav.getCurrentWindow() will throw an exception when called in the Designer
root = system.gui.getWindow(system.nav.getCurrentWindow()).getRootContainer()
if parent.getX() > round(root.getWidth()/2):
new_x = parent.getX() - 100 - window.getWidth()
except:
pass
new_y = parent.getY()
try:
# system.nav.getCurrentWindow() will throw an exception when called in the Designer
if new_y + window.getHeight() > root.getHeight():
new_y = root.getHeight() - window.getHeight()
except:
pass
window2.getRootContainer().new_tags = system.dataset.toDataSet(['tag'],
[[event.source.parent.tagPath]])
window2.getRootContainer().configChart()