Obviously, the function works well in the console too. It was my mistake since I didn't use a function to encapsulate code.
toggle quoted messageShow quoted text
El 07/09/2019 a las 13:14, Noelia Ruiz via Groups.Io escribió:
Great work and excellent explanation!
Previously, I tried to test something similar in the Python console and for any reason this failed, but it works perfectly in a global plugin using ui.message().
In the console I got this: SyntaxError: 'return' outside function
But this works and expected. Thanks for all your work and my best wishes.
El 07/09/2019 a las 12:40, Leonard de Ruijter escribió:
Thanks for pointing this out. It actually works as expected, but I will explain why.
The script uses a try/finally block. I think the following code is pretty explanatory when executed:
You will notice that when executing test(), both 42 and Hello are printed. In short, return brings you straight to the finally block, and I think the function will first execute the finally block and then returns.
On 7-9-2019 11:17, Noelia Ruiz wrote:
@leonardder and @feerrenrut :
def script_toggleScreenCurtain(self, gesture):
message = None
screenCurtainName = "screenCurtain"
if not vision.getProviderClass(screenCurtainName).canStart():
# Translators: Reported when the screen curtain is not available.
message = _("Screen curtain not available")
If return, I think that the message won't be reported if screen curtain is not available.
# Translators: Reported when the screen curtain could not be enabled.
message = _("Could not enable screen curtain")
Sorry if I'm missing something.
My tests are successful toggling screen curtain, so I can't check what happens when this can't be done.