Skip to content

Commit 8d319a4

Browse files
authored
Merge b78dc61 into 9823556
2 parents 9823556 + b78dc61 commit 8d319a4

13 files changed

Lines changed: 363 additions & 296 deletions

File tree

source/NVDAObjects/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
TreeInterceptor,
3131
)
3232
import braille
33+
from utils.security import _isObjectAboveLockScreen
3334
import vision
3435
import globalPluginHandler
3536
import brailleInput
@@ -1433,3 +1434,11 @@ def getSelectedItemsCount(self,maxCount=2):
14331434
For performance, this method will only count up to the given maxCount number, and if there is one more above that, then sys.maxint is returned stating that many items are selected.
14341435
"""
14351436
return 0
1437+
1438+
#: Type definition for auto prop '_get_isAboveLockScreen'
1439+
isAboveLockScreen: bool
1440+
1441+
def _get_isAboveLockScreen(self) -> bool:
1442+
if not isWindowsLocked():
1443+
return True
1444+
return _isObjectAboveLockScreen(self)

source/api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ def setReviewPosition(
237237
@param isCaret: Whether the review position is changed due to caret following.
238238
@param isMouse: Whether the review position is changed due to mouse following.
239239
"""
240-
if _isSecureObjectWhileLockScreenActivated(reviewPosition.obj):
240+
reviewObj = reviewPosition.obj
241+
if isinstance(reviewObj, treeInterceptorHandler.TreeInterceptor):
242+
reviewObj = reviewObj.rootNVDAObject
243+
if _isSecureObjectWhileLockScreenActivated(reviewObj):
241244
return False
242245
globalVars.reviewPosition=reviewPosition.copy()
243246
globalVars.reviewPositionObj=reviewPosition.obj

source/baseObject.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
11
# A part of NonVisual Desktop Access (NVDA)
2-
# Copyright (C) 2007-2020 NV Access Limited, Christopher Toth, Babbage B.V., Julien Cochuyt
2+
# Copyright (C) 2007-2022 NV Access Limited, Christopher Toth, Babbage B.V., Julien Cochuyt
33
# This file is covered by the GNU General Public License.
44
# See the file COPYING for more details.
55

66
"""Contains the base classes that many of NVDA's classes such as NVDAObjects, virtualBuffers, appModules, synthDrivers inherit from. These base classes provide such things as auto properties, and methods and properties for scripting and key binding.
77
"""
88

9+
from typing import (
10+
Any,
11+
Callable,
12+
Optional,
13+
Set,
14+
Union,
15+
)
916
import weakref
1017
import garbageHandler
1118
from logHandler import log
1219
from abc import ABCMeta, abstractproperty
1320

21+
GetterReturnT = Any
22+
GetterMethodT = Callable[["AutoPropertyObject"], GetterReturnT]
23+
24+
1425
class Getter(object):
1526

1627
def __init__(self,fget, abstract=False):
1728
self.fget=fget
1829
if abstract:
1930
self._abstract = self.__isabstractmethod__ = abstract
2031

21-
def __get__(self,instance,owner):
32+
def __get__(
33+
self,
34+
instance: Union[Any, None, "AutoPropertyObject"],
35+
owner,
36+
) -> Union[GetterReturnT, "Getter"]:
2237
if isinstance(self.fget, classmethod):
2338
return self.fget.__get__(instance, owner)()
2439
elif instance is None:
@@ -31,16 +46,22 @@ def setter(self,func):
3146
def deleter(self,func):
3247
return (abstractproperty if self._abstract else property)(fget=self.fget,fdel=func)
3348

49+
3450
class CachingGetter(Getter):
3551

36-
def __get__(self, instance, owner):
52+
def __get__(
53+
self,
54+
instance: Union[Any, None, "AutoPropertyObject"],
55+
owner,
56+
) -> Union[GetterReturnT, "CachingGetter"]:
3757
if isinstance(self.fget, classmethod):
3858
log.warning("Class properties do not support caching")
3959
return self.fget.__get__(instance, owner)()
4060
elif instance is None:
4161
return self
4262
return instance._getPropertyViaCache(self.fget)
4363

64+
4465
class AutoPropertyType(ABCMeta):
4566

4667
def __init__(self,name,bases,dict):
@@ -125,6 +146,7 @@ class AutoPropertyObject(garbageHandler.TrackedObject, metaclass=AutoPropertyTyp
125146
#: @type: bool
126147
cachePropertiesByDefault = False
127148

149+
_propertyCache: Set[GetterMethodT]
128150

129151
def __new__(cls, *args, **kwargs):
130152
self = super(AutoPropertyObject, cls).__new__(cls)
@@ -134,7 +156,7 @@ def __new__(cls, *args, **kwargs):
134156
self.__instances[self]=None
135157
return self
136158

137-
def _getPropertyViaCache(self,getterMethod=None):
159+
def _getPropertyViaCache(self, getterMethod: Optional[GetterMethodT] = None) -> GetterReturnT:
138160
if not getterMethod:
139161
raise ValueError("getterMethod is None")
140162
missing=False

source/core.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ def onEndSession(evt):
601601
wx.CallAfter(audioDucking.initialize)
602602

603603
from winAPI.messageWindow import WindowMessage
604-
from winAPI import sessionTracking
605604
import winUser
606605
# #3763: In wxPython 3, the class name of frame windows changed from wxWindowClassNR to wxWindowNR.
607606
# NVDA uses the main frame to check for and quit another instance of NVDA.
@@ -630,27 +629,12 @@ def __init__(self, windowName=None):
630629
self.orientationCoordsCache = (0,0)
631630
self.handlePowerStatusChange()
632631

633-
# Call must be paired with a call to sessionTracking.unregister
634-
if not sessionTracking.register(self.handle):
635-
import utils.security
636-
wx.CallAfter(utils.security.warnSessionLockStateUnknown)
637-
638-
def destroy(self):
639-
"""
640-
NVDA must unregister session tracking before destroying the message window.
641-
"""
642-
# Requires an active message window and a handle to unregister.
643-
sessionTracking.unregister(self.handle)
644-
super().destroy()
645-
646632
def windowProc(self, hwnd, msg, wParam, lParam):
647633
post_windowMessageReceipt.notify(msg=msg, wParam=wParam, lParam=lParam)
648634
if msg == WindowMessage.POWER_BROADCAST and wParam == self.PBT_APMPOWERSTATUSCHANGE:
649635
self.handlePowerStatusChange()
650636
elif msg == winUser.WM_DISPLAYCHANGE:
651637
self.handleScreenOrientationChange(lParam)
652-
elif msg == WindowMessage.WTS_SESSION_CHANGE:
653-
sessionTracking.handleSessionChange(sessionTracking.WindowsTrackedSession(wParam), lParam)
654638

655639
def handleScreenOrientationChange(self, lParam):
656640
# TODO: move to winAPI
@@ -809,7 +793,8 @@ def run(self):
809793
mouseHandler.pumpAll()
810794
braille.pumpAll()
811795
vision.pumpAll()
812-
except:
796+
sessionTracking.pumpAll()
797+
except Exception:
813798
log.exception("errors in this core pump cycle")
814799
baseObject.AutoPropertyObject.invalidateCaches()
815800
watchdog.asleep()
@@ -832,6 +817,9 @@ def run(self):
832817
log.debug("initializing updateCheck")
833818
updateCheck.initialize()
834819

820+
from winAPI import sessionTracking
821+
sessionTracking.initialize()
822+
835823
_TrackNVDAInitialization.markInitializationComplete()
836824

837825
log.info("NVDA initialized")

source/globalVars.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
if typing.TYPE_CHECKING:
2323
import NVDAObjects # noqa: F401 used for type checking only
24+
import textInfos # noqa: F401 used for type checking only
2425

2526

2627
class DefaultAppArgs(argparse.Namespace):
@@ -70,7 +71,7 @@ class DefaultAppArgs(argparse.Namespace):
7071
mouseOldY=None
7172
navigatorObject: typing.Optional['NVDAObjects.NVDAObject'] = None
7273
reviewPosition=None
73-
reviewPositionObj=None
74+
reviewPositionObj: typing.Optional["textInfos.TextInfoObjT"] = None
7475
lastProgressValue=0
7576
appArgs = DefaultAppArgs()
7677
unknownAppArgs: typing.List[str] = []

source/nvda.pyw

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,19 @@ if mutex is None:
350350
sys.exit(1)
351351

352352

353-
if _isSecureDesktop():
353+
def _serviceDebugEnabled() -> bool:
354354
import winreg
355355
try:
356356
k = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\NVDA")
357-
if not winreg.QueryValueEx(k, u"serviceDebug")[0]:
358-
globalVars.appArgs.secure = True
357+
if winreg.QueryValueEx(k, "serviceDebug")[0]:
358+
return True
359359
except WindowsError:
360+
pass
361+
return False
362+
363+
364+
if _isSecureDesktop():
365+
if not _serviceDebugEnabled():
360366
globalVars.appArgs.secure = True
361367
globalVars.appArgs.changeScreenReaderFlag = False
362368
globalVars.appArgs.minimal = True

source/textInfos/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# A part of NonVisual Desktop Access (NVDA)
22
# This file is covered by the GNU General Public License.
33
# See the file COPYING for more details.
4-
# Copyright (C) 2006-2021 NV Access Limited, Babbage B.V., Accessolutions, Julien Cochuyt
4+
# Copyright (C) 2006-2022 NV Access Limited, Babbage B.V., Accessolutions, Julien Cochuyt
55

66
"""Framework for accessing text content in widgets.
77
The core component of this framework is the L{TextInfo} class.
@@ -32,6 +32,7 @@
3232

3333
if typing.TYPE_CHECKING:
3434
import NVDAObjects
35+
import treeInterceptorHandler # noqa: F401 used for type checking only
3536

3637
SpeechSequence = List[Union[Any, str]]
3738

@@ -287,6 +288,9 @@ def _logBadSequenceTypes(sequence: SpeechSequence, shouldRaise: bool = True):
287288
return speech.types.logBadSequenceTypes(sequence, raiseExceptionOnError=shouldRaise)
288289

289290

291+
TextInfoObjT = Union["NVDAObjects.NVDAObject", "treeInterceptorHandler.TreeInterceptor"]
292+
293+
290294
class TextInfo(baseObject.AutoPropertyObject):
291295
"""Provides information about a range of text in an object and facilitates access to all text in the widget.
292296
A TextInfo represents a specific range of text, providing access to the text itself, as well as information about the text such as its formatting and any associated controls.
@@ -307,7 +311,11 @@ class TextInfo(baseObject.AutoPropertyObject):
307311
@type bookmark: L{Bookmark}
308312
"""
309313

310-
def __init__(self,obj,position):
314+
def __init__(
315+
self,
316+
obj: TextInfoObjT,
317+
position
318+
):
311319
"""Constructor.
312320
Subclasses must extend this, calling the superclass method first.
313321
@param position: The initial position of this range; one of the POSITION_* constants or a position object supported by the implementation.
@@ -338,9 +346,9 @@ def _set_end(self, otherEndpoint: "TextInfoEndpoint"):
338346
self.end.moveTo(otherEndpoint)
339347

340348
#: Typing information for auto-property: _get_obj
341-
obj: "NVDAObjects.NVDAObject"
349+
obj: TextInfoObjT
342350

343-
def _get_obj(self) -> "NVDAObjects.NVDAObject":
351+
def _get_obj(self) -> TextInfoObjT:
344352
"""The object containing the range of text being represented."""
345353
return self._obj()
346354

source/treeInterceptorHandler.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
# treeInterceptorHandler.py
21
# A part of NonVisual Desktop Access (NVDA)
3-
# Copyright (C) 2006-2020 NV Access Limited, Davy Kager, Accessolutions, Julien Cochuyt
2+
# Copyright (C) 2006-2022 NV Access Limited, Davy Kager, Accessolutions, Julien Cochuyt
43
# This file is covered by the GNU General Public License.
54
# See the file COPYING for more details.
65

7-
from typing import Optional, Dict
6+
from typing import (
7+
TYPE_CHECKING,
8+
Dict,
9+
Optional,
10+
)
811

912
from logHandler import log
1013
import baseObject
@@ -18,6 +21,10 @@
1821
from speech.types import SpeechSequence
1922
from controlTypes import OutputReason
2023

24+
if TYPE_CHECKING:
25+
import NVDAObjects
26+
27+
2128
runningTable=set()
2229

2330
def getTreeInterceptor(obj):
@@ -84,12 +91,11 @@ class TreeInterceptor(baseObject.ScriptableObject):
8491

8592
shouldTrapNonCommandGestures=False #: If true then gestures that do not have a script and are not a command gesture should be trapped from going through to Windows.
8693

87-
def __init__(self, rootNVDAObject):
94+
def __init__(self, rootNVDAObject: "NVDAObjects.NVDAObject"):
8895
super(TreeInterceptor, self).__init__()
8996
self._passThrough = False
9097
#: The root object of the tree wherein events and scripts are intercepted.
91-
#: @type: L{NVDAObjects.NVDAObject}
92-
self.rootNVDAObject = rootNVDAObject
98+
self.rootNVDAObject: "NVDAObjects.NVDAObject" = rootNVDAObject
9399

94100
def terminate(self):
95101
"""Terminate this interceptor.

0 commit comments

Comments
 (0)