Re: Question about screen curtain, review comments

 

Thanks!


On 7-9-2019 13:14, Noelia Ruiz wrote:
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.

Regards

El 07/09/2019 a las 12:40, Leonard de Ruijter escribió:
Hey Noelia,


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:


def test():
     try:
         return(42)
     finally:
         print("hello!")

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.


Regards,

Leonard


On 7-9-2019 11:17, Noelia Ruiz wrote:
@leonardder and @feerrenrut :

def script_toggleScreenCurtain(self, gesture):
        message = None
        try:
            screenCurtainName = "screenCurtain"
            if not vision.getProviderClass(screenCurtainName).canStart():
                # Translators: Reported when the screen curtain is not available.
                message = _("Screen curtain not available")
                return

If return, I think that the message won't be reported if screen curtain is not available.

Also:

# Translators: Reported when the screen curtain could not be enabled.
                    message = _("Could not enable screen curtain")
                    return

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.
Kind regards








Join nvda-devel@groups.io to automatically receive all group messages.