getCursorHidden() behaviour

Hi!,

I am trying the following Python code hooked to a key to hide or display the mouse cursor.

def toggleMouseCursor(self):
    """shows or hides mouse cursor"""
    props = WindowProperties()
    hidden = props.getCursorHidden()
    print hidden
    props.setCursorHidden(not hidden)
    base.win.requestProperties(props)

It does not work, it hides the mouse cursor the first time (because it was visible by configuration), and
then the cursor never shows up again.
The print statement ALWAYS prints “False”
Although the following code works without a problem:

    def toggleMouseCursor(self):
        """shows or hides mouse cursor"""
        self.cursorHidden = not self.cursorHidden #keep track of this by hand
        props = WindowProperties()
        props.setCursorHidden(self.cursorHidden)
        base.win.requestProperties(props)

Is there something wrong with the first snippet for what I want to achieve?

Thanks!
francholi

Have you tried calling “base.win.getProperties()” to get the current window properties?

[edit]
By which I mean something like the following:

props = base.win.getProperties()
hidden = props.getCursorHidden()
# etc...

Thaumaturge is correct, but just to clarify on why your code doesn’t work:

This code creates a new, empty WindowProperties object. Calling getAnything on a WindowProperties object that does not specify any particular properties will either error or simply return some default settings. As Thaumaturge pointed out, you are interested in acquiring a WindowProperties object that specifies the current properties of the window, using base.win.getProperties().

Then, you want to tell the window to update the setCursorHidden property, so your code would look somewhat like this:

def toggleMouseCursor(self):
    """shows or hides mouse cursor"""
    oldProps = base.win.getProperties()
    hidden = oldProps.getCursorHidden()
    newProps = WindowProperties()
    newProps.setCursorHidden(not hidden)
    base.win.requestProperties(newProps)

Keep in mind that the WindowProperties object passed to requestProperties should be considered a ‘delta’ object; ie., it only specifies the properties that you want to change, instead of respecifying every single property.