param = event.source.parent.MotorID
if event.source.parent.EnablePopups:
system.nav.openWindowInstance('popup', {'MotorID' : param})
system.nav.centerWindow('popup')
to open a popup for some motor information.
I like being able to have many open at a time but would like to restrict 1 per motor. It doesn’t make sense to have 3 popups open for motor X… I’m assuming I need to add something in the event script to do this but I’m not sure how to handle it.
Yes, we don’t care how many times you open the same popup window. Your script needs to check all of the opened windows to see if there is one with the same name and same parameter like this:param = event.source.parent.MotorID
if event.source.parent.EnablePopups:
windows = system.gui.getOpenedWindows()
found = 0
for win in windows:
if win.name == "popup" and win.rootContainer.MotorID == param:
found = 1
break
if not found:
system.nav.openWindowInstance('popup', {'MotorID' : param})
system.nav.centerWindow('popup')
else:
system.gui.messageBox("Motor already opened")
got it, thanks.
How can I center the window I am opening only?
It looks like it just keeps centering the first instance and the other windows open in the top left corner…
It seems a bit counter-intuitive to allow multiple popups but always force them into the middle of the screen where they’ll overlap - usually it’s better to open popups for a specific item next to the item on the screen.
Anyway, the reason you’re having a problem with centring is because system.nav.centerWindow('popup')tries to get a window reference by name and finds the first one that you opened, ignoring the latest one.
To solve this you must use the reference to the window you just opened as follows:param = event.source.parent.MotorID
if event.source.parent.EnablePopups:
windows = system.gui.getOpenedWindows()
found = 0
for win in windows:
if win.name == "popup" and win.rootContainer.MotorID == param:
found = 1
break
if not found:
newPopup = system.nav.openWindowInstance('popup', {'MotorID' : param})
system.nav.centerWindow(newPopup)
else:
system.gui.messageBox("Motor already opened")To make sure the popup window appears in front of the main window, set it’s Layer property to a value greater than the main window’s value.
The problem you still have however is demonstrated as follows: clicking on Motor 1 opens its popup OK; clicking on Motor 2 opens its popup OK; but clicking back on Motor 1 just displays a warning and does not bring its popup back to the top. So far I’ve not managed to find a way to force a window to the top of the z-order. Anyone else have any ideas?
Yes, I did realize that was why it was happening… I just wonder what would be the best way to open multiple popups. I think a random window centering would work well. So every time you order a window, it randomly selects its position…
Thanks Carl. The following code works well:param = event.source.parent.MotorID
if event.source.parent.EnablePopups:
windows = system.gui.getOpenedWindows()
found = 0
for win in windows:
if win.name == "popup" and win.rootContainer.MotorID == param:
found = 1
win.setSelected(1)
break
if not found:
newPopup = system.nav.openWindowInstance('popup', {'MotorID' : param})
system.nav.centerWindow(newPopup)
if event.source.parent.EnablePopups: windows = system.gui.getOpenedWindows()
found = 0
for win in windows:
if win.name == “Popup_SOV” and win.rootContainer.Device == param1: found = 1 win.setSelected(1)
break
if not found: newPopup = system.nav.openWindowInstance(‘Popup_SOV’, {‘Device’ : param1, ‘Auto’ : param2, ‘Close’ : param3, ‘Open’ : param4}) system.nav.centerWindow(newPopup)
"
You have a syntax error because you’ve cut and pasted code that had unicode curly quote marks. (where the error shows question marks). Replace those with proper single or double ASCII quote characters.
(Your initial code posted didn’t use a code formatting block, so the forum software made your quotes “pretty”. Which is why AIO’s attempt to format for you failed.)
param1 = event.source.parent.Device
param2 = event.source.parent.getComponent('Group').Auto
param3 = event.source.parent.getComponent('Group').Close
param4 = event.source.parent.getComponent('Group').Open
if event.source.parent.EnablePopups:
windows = system.gui.getOpenedWindows()
found = 0
for win in windows:
if win.name == "Popup_SOV" and win.rootContainer.Device == param1:
found = 1
win.setSelected(1)
break
if not found:
newPopup = system.nav.openWindowInstance('Popup_SOV',{'Device':param1,'Auto':param2,'Close':param3,'Open':param4})
system.nav.centerWindow(newPopup)
but on the running time
I got new error to run the pop up
Error executing script for event: actionPerformed
on component: Button .
That means that the container your Button resides in has no property named EnablePopups. I don’t know where you copied this script from, nor do I know the structure of the Window it’s being used in, so that’s all I can tell you from the stacktrace. Perhaps that is supposed to be a custom property on the container?
I took it from this post
I had the same problem that the guy that start this post my code was done to open multiple pop ups but the problem was that if you click on the same object 3 times 3 times will bring a pop up no matter if it is already open.
so my original code was this
but then I saw the post and I figure the actual code will work now I don’t know what should be the function of “EnablePopups” I guess it’s the action of trying to open a new pop up
So I replace that for componentEnabled it works kind off one click in the first object bring the pop up
a second click will show the pop up currently open to the front
but if I click on the first object and the the second both pop ups will open
the problem is if I click on the first one again it will open a repeated pop up
It looks like the EnablePopups property is only used in the script to determine if Popups are enabled. To place this property, select the parent container of your Button, then right-click the parent container and select “Custom Properties” under the “Customizers” expandable menu. create a new property named “EnablePopups”, and select a data type of boolean. Apply your changes, and make sure to set the property’s value to be True, otherwise your script will be bypassed.
logger = system.util.getLogger('TROUBLESHOOTING')
if event.source.parent.EnablePopups:
windows = system.gui.getOpenedWindows()
found = 0
for win in windows:
logger.info('Window name: {0}\t| param1: {1}'.format(win.name, param1))
if win.name == "Popup_SOV" and win.rootContainer.Device == param1:
found = 1
win.setSelected(1)
break
if not found:
logger.info('Popup with name \'Popup_SOV\' not found; making a new instance now.')
newPopup = system.nav.openWindowInstance('Popup_SOV',{'Device':param1,'Auto':param2,'Close':param3,'Open':param4})
system.nav.centerWindow(newPopup)