Re: Best way to disable an add-on on secure screen


Lukasz Golonka
 

Thanks for the pretty interesting discussion.
I personally tent to agree with Tyler that the responsibility of
deciding if the given add-on should be used in secure screens should be
on the user, but that is not always possible / practical.
While both the pattern #2 and #3 proposed by Cyrille are valid the
following changes makes them nicer IMO.
For pattern #2 you can easily avoid unnecessary indentation by keeping
the main class of your plugin in a separate file. To use my winWizard
add-on as an example the __init__.py may look like this:
### Start of example 2 modified:
import globalVars
import globalPluginHandler


if globalVars.appArgs.secure:
GlobalPlugin = globalPluginHandler.GlobalPlugin
else:
from . import winWizard
GlobalPlugin = winWizard.GlobalPlugin


## End of example 2 modified.


For example #3 which is pretty nice as long as your imports don't have
side effects you can easily use class decorator to make this more
Pythonic:

## Start of example 3 modified:
def disableInSecureMode(decoratedCls):
if globalVars.appArgs.secure:
return globalPluginHandler.GlobalPlugin
return decoratedCls

# and then before definition of your plugin class:
@disableInSecureMode

## end of example 3 modified.

--
Regards
Lukasz

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