I have set up a container. Within the container I have a slider. When I click on the slider it becomes outlined with a thin border. I am assuming this indicates that object has the focus.

My problem is I can’t get it to unfocus unless I click on another input object.

I am not real familiar with jython but I would guess that I could use the mouse exited event to defocus but I am not sure of the syntax if this is the case.

Actually, I checked on the other input objects I have, and the focus stays on anything that is clicked until something else is clicked.

Yes, thats true, components that can recieve input focus keep the focus until something else takes it or the window is closed. This is the standard behavior of windows programs as far as I know.

There isn’t an “unfocus” method. In order to unfocus one component, you give focus to another component.

Why don’t you describe the problem that you’re encountering by having the slider be focused, and we can go from there.


With the object still focused it can be accidentally changed if someone hits the keyboard. Most of the time this isn’t a problem, but Murphy’s law being what it is…

Ah, I see. Well, although it might not look as flashy, if you’re really worried about it, you could have the user edit the point via a numeric text field and turn the Protected property on. This makes the field require a double click or enter keypress to become editable, and then becomes non-editable after each change (even though the component still has ‘focus’)

Or, put the slider on a popup window, and have the user hit OK (closing the window) when done editing.

Or, don’t bind the slider’s value bidirectionally to the point - only bind it unidirectionally, and then have a “submit” button that takes the slider’s value and uses it to update your value in the database. This has the benefit that the “submit” button will take the focus.

Hope this helps,

Would it be possible to set the focus to another object? The button I use to close the window for instance?

Sure! All components have a function called requestFocusInWindow() which you can call to have that component become focused.

For instance, suppose that on mouseExit of your slider you want to focus the button called CloseButton on the root container of your window, you would put a script like this on the mouseExit event:

window = fpmi.gui.getParentWindow(event) button = window.rootContainer.getComponent("CloseButton") button.requestFocusInWindow()

Hope this helps,

Yes it does.

On a side note, the level of help that everybody I have talked to is willing to give is phenomenal. It is very much appreciated.

Glad to help! Let us know if you have anymore questions.

Would you mind explaining what is going on with that script? It would help me to understand it instead of just using it. Thanks in advance.

Sure, here goes:

First of all, this is an action script, which means that it responds to some event that occurs on a component. In this case, we want to respond to the mouseExited event of your slider component, which will fire, not surprisingly, whenever the mouse exits the vicinity of the slider.

Ok, now line by line:

window = fpmi.gui.getParentWindow(event)

All action scripts start with one variable already defined: event. This object describes the event that occured, including the component that it occured on (event.source). fpmi.gui.getParentWindow is a built in function that takes an event object, and returns to you a reference to the window that the event took place in. (There are lots of built in functions - see the documentation under Technical Reference / Jython / Built-in Modules for more info.) We take that window reference and assign it to a variable called window

button = window.rootContainer.getComponent("CloseButton")

window.rootContainer is a reference to your window’s root container. All containers have a function called getComponent which takes a name of a component. In this case, we are assuming that your close button is called “CloseButton” and is on your root container. If either of those assumtions is wrong, this won’t work. If the assumtions are correct, then we will get a reference to your button component. We assign that reference to a variable called button. Note - we had to put CloseButton in quotes because it is a string - the name of a component. If we didn’t have quotes, the scripting engine would think that we wanted to pass the value of a variable named CloseButton to the getComponent function. Of course, we don’t have a variable named CloseButton, so this would be incorrect.


This simply calls the requestFocusInWindow() function on the button.

Side note:. Lets assume that your slider was on the root container, right next to the CloseButton. Then we could have replaced the first 2 lines with this:

button = event.source.parent.getComponent("CloseButton")

…or this

button = fpmi.gui.getSibling(event, "CloseButton")

If terms like variable and function are foreign to you, then you probably want to go ahead and read an introductory tutorial to Python like:’s_Tutorial_for_Python/Contents or or

Hope this helps!

I have some exposure to “C”, “C++”, Pascal, and a couple other higher level languages. Probably enough to be dangerous. With a little help from you guys answering my questions I can be even more dangerous. :open_mouth:

So no problem with variables and functions and it is a little more clear how to call a function now. I am still a little fuzzy on how the path to the object in question is derived.

To clarify what I am fuzzy about, I tried to get the focus back on a mouseEntered event.

There is no real need to do that except as an exercise to see if I understood how an object is referenced. It was painfully obvious that I don’t get it yet by the big red “I hate you” error message when I rolled the mouse over the object.

The object is several layers down.

the window name is Ammonia Air Unit
the root container is root container
I have another container called Temp Alarm Slide Meter
Within that is the slide meter called Setpoint Slider

what I put in the mouseEntered event was:

Setpoint Slider.requestFocusInWindow()

Thank you for the links. It will take some time but I will go through the tutorials.

Hey, nothing like coming in 11 posts into a thread, but let’s see if I can help you out:

The big problem with your try is that you’re attempting to reference the object directly, by using it’s name. This is understandable, but unfortunately not how things work. In programming terms, the Name of a component is like it’s Type. What you need to do is get the “instance” of the window/component you’re interested in, and you do that through the various functions Carl mentioned.

Here’s what I think could work for you. I’ve done it a bit differently than Carl’s example in hope that’ll be clearer initially:

winInstance = fpmi.gui.getWindow('Ammonia Air Unit')
parentPanelInstance = winInstance.rootContainer.getComponent('Temp Alarm Slide Meter')
sliderInstance = parentPanelInstance.getComponent('Setpoint Slider')

The main difference is that I got the window by name, not through the event object. Then we go down the hierarchy getting each actual object until we get the component we’re interested in. I also used different variable names to show that they can be whatever you want. I think one thing that throws people with a bit of programming experience off when the approach jython is that variable declaration is implicit. Just assign something to a name, and now that variable exists. I think that sometime when we use examples with variable names like “window” and “button”, people might get a bit confused and think they’re some sort of keyword… but they’re not.

Anyhow, hope that clears things up a bit. Just to complicate things a tad more, the following line of code would have done the exact same thing:


The reason is because you’re putting it in the event handler on the slider, so the source property of the event object will actually be the instance of that slider, the same as got assigned to “sliderInstance” above.

OK, hope that helps, or at least gives you some more to think about! :slight_smile:


Yes, it does help.

It is apparent I need to go through the tutorials, though.