From 3c10dbac3c0fb8091933ddca28d3dfd5c5e2873c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Golonka?= Date: Tue, 29 Dec 2020 23:53:36 +0100 Subject: [PATCH 1/6] Script decorator: Allow to set `allowInSleepMode` for a decorated script. * Also take this oportunity to use type hints for script decorator parameters --- source/scriptHandler.py | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/source/scriptHandler.py b/source/scriptHandler.py index 6c3422f6fe1..3b699d7bf47 100644 --- a/source/scriptHandler.py +++ b/source/scriptHandler.py @@ -1,9 +1,9 @@ -# scriptHandler.py # A part of NonVisual Desktop Access (NVDA) # Copyright (C) 2007-2020 NV Access Limited, Babbage B.V., Julien Cochuyt # This file is covered by the GNU General Public License. # See the file COPYING for more details. +from typing import List, Optional import time import weakref import inspect @@ -241,32 +241,26 @@ def isScriptWaiting(): return bool(_numScriptsQueued) def script( - description="", - category=None, - gesture=None, - gestures=None, - canPropagate=False, - bypassInputHelp=False, - resumeSayAllMode=None + description: str = "", + category: Optional[str] = None, + gesture: Optional[str] = None, + gestures: Optional[List[str]] = None, + canPropagate: bool = False, + bypassInputHelp: bool = False, + allowInSleepMode: bool = False, + resumeSayAllMode: Optional[int] = None ): """Define metadata for a script. This function is to be used as a decorator to set metadata used by the scripting system and gesture editor. It can only decorate methods which name start swith "script_" @param description: A short translatable description of the script to be used in the gesture editor, etc. - @type description: string @param category: The category of the script displayed in the gesture editor. - @type category: string @param gesture: A gesture associated with this script. - @type gesture: string @param gestures: A list of gestures associated with this script - @type gestures: list(string) @param canPropagate: Whether this script should also apply when it belongs to a focus ancestor object. - @type canPropagate: bool @param bypassInputHelp: Whether this script should run when input help is active. - @type bypassInputHelp: bool @param resumeSayAllMode: The say all mode that should be resumed when active before executing this script. - One of the C{sayAllHandler.CURSOR_*} constants. - @type resumeSayAllMode: int + One of the C{sayAllHandler.CURSOR_*} constants. """ if gestures is None: gestures = [] @@ -295,5 +289,6 @@ def script_decorator(decoratedScript): decoratedScript.bypassInputHelp = bypassInputHelp if resumeSayAllMode is not None: decoratedScript.resumeSayAllMode = resumeSayAllMode + decoratedScript.allowInSleepMode = allowInSleepMode return decoratedScript return script_decorator From 574d816908f6df713e238e6f2eef2f13c78b5772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Golonka?= Date: Wed, 30 Dec 2020 00:02:28 +0100 Subject: [PATCH 2/6] Unit test for allowInSleepMode --- tests/unit/test_scriptHandler.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_scriptHandler.py b/tests/unit/test_scriptHandler.py index 35ffa861823..70127da27a0 100644 --- a/tests/unit/test_scriptHandler.py +++ b/tests/unit/test_scriptHandler.py @@ -1,13 +1,12 @@ -#tests/unit/test_scriptHandler.py -#A part of NonVisual Desktop Access (NVDA) -#This file is covered by the GNU General Public License. -#See the file COPYING for more details. -#Copyright (C) 2018-2019 NV Access Limited, Babbage B.V. +# A part of NonVisual Desktop Access (NVDA) +# This file is covered by the GNU General Public License. +# See the file COPYING for more details. +# Copyright (C) 2018-2021 NV Access Limited, Babbage B.V., Ɓukasz Golonka """Unit tests for the scriptHandler module.""" import unittest -from scriptHandler import * +from scriptHandler import script from inputCore import SCRCAT_MISC from sayAllHandler import CURSOR_CARET @@ -22,6 +21,7 @@ def test_scriptdecoration(self): gestures=["kb:b", "kb:c"], canPropagate=True, bypassInputHelp=True, + allowInSleepMode=True, resumeSayAllMode=CURSOR_CARET ) def script_test(self, gesture): @@ -32,4 +32,5 @@ def script_test(self, gesture): self.assertCountEqual(script_test.gestures, ["kb:a", "kb:b", "kb:c"]) self.assertTrue(script_test.canPropagate) self.assertTrue(script_test.bypassInputHelp) + self.assertTrue(script_test.allowInSleepMode) self.assertEqual(script_test.resumeSayAllMode, CURSOR_CARET) From 738b6207dc4a4f3627175aa02b6aaa16552429b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Golonka?= Date: Wed, 30 Dec 2020 00:03:55 +0100 Subject: [PATCH 3/6] Mention `allowInSleepMode` in script decorator's docstring --- source/scriptHandler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/source/scriptHandler.py b/source/scriptHandler.py index 3b699d7bf47..25075ac2ab6 100644 --- a/source/scriptHandler.py +++ b/source/scriptHandler.py @@ -259,6 +259,7 @@ def script( @param gestures: A list of gestures associated with this script @param canPropagate: Whether this script should also apply when it belongs to a focus ancestor object. @param bypassInputHelp: Whether this script should run when input help is active. + @param allowInSleepMode: Whether this script should run when NVDA is in sleep mode. @param resumeSayAllMode: The say all mode that should be resumed when active before executing this script. One of the C{sayAllHandler.CURSOR_*} constants. """ From 9fc945f546d7a9d3f2945d3052e4bdef50bb46ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Golonka?= Date: Wed, 30 Dec 2020 00:10:43 +0100 Subject: [PATCH 4/6] Lint fixes --- source/scriptHandler.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/scriptHandler.py b/source/scriptHandler.py index 25075ac2ab6..cebbf17464b 100644 --- a/source/scriptHandler.py +++ b/source/scriptHandler.py @@ -241,14 +241,14 @@ def isScriptWaiting(): return bool(_numScriptsQueued) def script( - description: str = "", - category: Optional[str] = None, - gesture: Optional[str] = None, - gestures: Optional[List[str]] = None, - canPropagate: bool = False, - bypassInputHelp: bool = False, - allowInSleepMode: bool = False, - resumeSayAllMode: Optional[int] = None + description: str = "", + category: Optional[str] = None, + gesture: Optional[str] = None, + gestures: Optional[List[str]] = None, + canPropagate: bool = False, + bypassInputHelp: bool = False, + allowInSleepMode: bool = False, + resumeSayAllMode: Optional[int] = None ): """Define metadata for a script. This function is to be used as a decorator to set metadata used by the scripting system and gesture editor. From 5b3b2edde35bbc1c815638d1740d6eb31533c973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Golonka?= Date: Wed, 30 Dec 2020 00:31:01 +0100 Subject: [PATCH 5/6] Update developer guide --- devDocs/developerGuide.t2t | 2 ++ 1 file changed, 2 insertions(+) diff --git a/devDocs/developerGuide.t2t b/devDocs/developerGuide.t2t index ff7d37a112d..31b87a2bddb 100644 --- a/devDocs/developerGuide.t2t +++ b/devDocs/developerGuide.t2t @@ -478,6 +478,8 @@ The following keyword arguments can be used when applying the script decorator: This option defaults to False. - bypassInputHelp: A boolean indicating whether this script should run when input help is active. This option defaults to False. +- allowInSleepMode: A boolean indicating whether this script should run when sleep mode is active. + This option defaults to False. - resumeSayAllMode: The say all mode that should be resumed when active before executing this script. The constants for say all mode are prefixed with CURSOR_ and specified in the sayAllHandler modules. If resumeSayAllMode is not specified, say all does not resume after this script. From ca87cc0daa81875723925cd2188462f037f70013 Mon Sep 17 00:00:00 2001 From: Michael Curran Date: Mon, 11 Jan 2021 16:05:26 +1000 Subject: [PATCH 6/6] Update what's new --- user_docs/en/changes.t2t | 1 + 1 file changed, 1 insertion(+) diff --git a/user_docs/en/changes.t2t b/user_docs/en/changes.t2t index 1ce7ab07062..9a5124af8e6 100644 --- a/user_docs/en/changes.t2t +++ b/user_docs/en/changes.t2t @@ -22,6 +22,7 @@ What's New in NVDA - Instead, override `_getText` which returns a string of all text in the object. - `LiveText` objects can now calculate diffs by character. (#11639) - To alter the diff behaviour for some object, override the `diffAlgo` property (see the docstring for details). +- When defining a script with the script decorator, the 'allowInSleepMode' boolean argument can be specified to control if a script is available in sleep mode or not. (#11979) = 2020.4 =