I don’t find any ways to show the windows path or name in runtime:
what I “want” is show the windows path in a little label
Does someone have advice?
I don’t find any ways to show the windows path or name in runtime:
what I “want” is show the windows path in a little label
Does someone have advice?
You can use a tag binding. This line works as an expression too.
{[System]Client/User/CurrentWindow}
Note that this only works when you switch main windows. I think if you open a popup window, it will still show the main window’s name and not the popup name. You might can get creative if the system tag doesn’t work by using
system.gui.getOpenedWindowNames()
What you say is very clear… but is not what I looking for…
I can’t believe that no exist a way to know the path of a window.
Can you give an example of your window path, and what you expect to see displayed in the label?
something like that:
If you have a direct reference to the window you can use path.
w = system.gui.getWindow("Old windows/Pop_ItemEntry")
print w.path
prints “Old windows/Pop_ItemEntry” for me. So you probably want to do this on a window startup script.
It seems to me in visionWindowOpened, you could do the following
windowPath = event.source.path
myComponent.text = windowPath
That seems to be a work around, but you would have to add this script to every single popup window. It would be a lot nicer if the window had a path property by default.
I would set the popup Title property to your path
system.gui.getParentWindow(event).getComponentForPath('_parent').title = event.source.path
mmm … like you say sure work but for do that i need to:
already know the path
make same script code.
suppose that: you want create a simple label to show the path (like in my pic) and copy that in all your windows how to do? no ways?
this will do it. Just paste this code in a label’s propertyChange event script
if event.propertyName == 'componentRunning':
event.source.text = system.gui.getParentWindow(event).getComponentForPath('_parent').path
Work fine thanks
errata corride:
work almost fine … but when the you close the windows generate the alarm …
It is probably trying to fire when you close the window as well as when it is opened. It cannot get the window path if the window is already closed, so wrap this up in a try except block.
if event.propertyName == 'componentRunning':
try:
event.source.text = system.gui.getParentWindow(event).getComponentForPath('_parent').path
except:
pass
I modify your idea like that … same advice?
if event.propertyName == 'componentRunning' and event.newValue == 1:
try:
event.source.text = system.gui.getParentWindow(event).getComponentForPath('_parent').path
except:
pass
You shouldn’t need the event.newValue
part unless it is part of other functionality you want. The try except will handle the error message by itself
You should also consider putting this into a template. Then if you decide you want to change the font, border, background, etc, you only have to change it once for the project(s).
After the discussion i make a simple template
hope can help
If it’s a Java error you have to except
the Java error too. Try:
import java
if event.propertyName == 'componentRunning' and event.newValue == 1:
try:
event.source.text = system.gui.getParentWindow(event).getComponentForPath('_parent').path
except:
pass
except java.lang.Exception:
pass
I'm no very expert in python but the sense of put one more control in the "try" is not clear:
"except:" is the default answer to the issue; if we put one more same the default what change?
Can you explain to me the advantage?
The default except
will not capture Java errors and if any Java errors occur, you’ll still get an exception without the additional except
statement
This is a quirk of Jython
But… did this change in 8? I was typing up an example and noticed except: pass
catches both Python and Java errors
However, except Exception, e
only catches Python errors in which case you have to add the extra except block for Java errors
It’s entirely possible I never realized this because I seldom handle exceptions without doing something with the error message