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?
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:
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.