Skip to content

Commit c197318

Browse files
authored
Merge 87ffa66 into 6fdabfe
2 parents 6fdabfe + 87ffa66 commit c197318

15 files changed

Lines changed: 148 additions & 87 deletions

source/NVDAHelper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import api
2828
import globalVars
2929
from logHandler import log
30+
import NVDAState
31+
3032

3133
versionedLibPath = os.path.join(globalVars.appDir, 'lib')
3234
if os.environ.get('PROCESSOR_ARCHITEW6432') == 'ARM64':
@@ -35,7 +37,7 @@
3537
versionedLib64Path = os.path.join(globalVars.appDir, 'lib64')
3638

3739

38-
if not globalVars.runningAsSource:
40+
if not NVDAState.isRunningAsSource():
3941
# When running as a py2exe build, libraries are in a version-specific directory
4042
versionedLibPath=os.path.join(versionedLibPath,versionInfo.version)
4143
versionedLib64Path=os.path.join(versionedLib64Path,versionInfo.version)

source/appModuleHandler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import baseObject
3434
from logHandler import log
3535
import NVDAHelper
36+
import NVDAState
3637
import winKernel
3738
import config
3839
import NVDAObjects #Catches errors before loading default appModule
@@ -86,7 +87,7 @@ def __getattr__(attrName: str) -> Any:
8687
since add-ons are initialized before `appModuleHandler`
8788
and when `appModuleHandler` was not yet initialized the variable was set to `None`.
8889
"""
89-
if attrName == "NVDAProcessID" and globalVars._allowDeprecatedAPI:
90+
if attrName == "NVDAProcessID" and NVDAState._allowDeprecatedAPI():
9091
log.warning("appModuleHandler.NVDAProcessID is deprecated, use globalVars.appPid instead.")
9192
if initialize._alreadyInitialized:
9293
return globalVars.appPid
@@ -114,7 +115,7 @@ def _warnDeprecatedAliasAppModule() -> None:
114115
f" instead import appModules.{replacementModName}."
115116
)
116117
log.warning(deprecatedImportWarning)
117-
if not globalVars._allowDeprecatedAPI:
118+
if not NVDAState._allowDeprecatedAPI():
118119
raise ModuleNotFoundError(deprecatedImportWarning)
119120

120121

source/appModules/lockapp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
import config
1515
import controlTypes
1616
import eventHandler
17-
import globalVars
1817
import inputCore
1918
from logHandler import log
2019
from NVDAObjects import NVDAObject
2120
from NVDAObjects.lockscreen import LockScreenObject
2221
from NVDAObjects.UIA import UIA
22+
import NVDAState
2323
from utils.security import getSafeScripts
2424
from winAPI.sessionTracking import isWindowsLocked
2525

@@ -34,7 +34,7 @@
3434
def __getattr__(attrName: str) -> Any:
3535
"""Module level `__getattr__` used to preserve backward compatibility.
3636
"""
37-
if attrName == "LockAppObject" and globalVars._allowDeprecatedAPI:
37+
if attrName == "LockAppObject" and NVDAState._allowDeprecatedAPI():
3838
log.warning("lockapp.LockAppObject is deprecated, use NVDAObjects.lockscreen.LockScreenObject instead.")
3939
return LockScreenObject
4040
raise AttributeError(f"module {repr(__name__)} has no attribute {repr(attrName)}")

source/config/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
_validateConfig_featureFlag,
4040
)
4141
from typing import Any, Dict, List, Optional, Set
42+
import NVDAState
43+
4244

4345
#: True if NVDA is running as a Windows Store Desktop Bridge application
4446
isAppX=False
@@ -66,10 +68,10 @@
6668

6769
def __getattr__(attrName: str) -> Any:
6870
"""Module level `__getattr__` used to preserve backward compatibility."""
69-
if attrName == "NVDA_REGKEY" and globalVars._allowDeprecatedAPI:
71+
if attrName == "NVDA_REGKEY" and NVDAState._allowDeprecatedAPI():
7072
log.warning("NVDA_REGKEY is deprecated, use RegistryKey.NVDA instead.")
7173
return RegistryKey.NVDA.value
72-
if attrName == "RUN_REGKEY" and globalVars._allowDeprecatedAPI:
74+
if attrName == "RUN_REGKEY" and NVDAState._allowDeprecatedAPI():
7375
log.warning("RUN_REGKEY is deprecated, use RegistryKey.RUN instead.")
7476
return RegistryKey.RUN.value
7577
raise AttributeError(f"module {repr(__name__)} has no attribute {repr(attrName)}")

source/core.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import addonHandler
2828
import extensionPoints
2929
import garbageHandler
30+
import NVDAState
3031

3132

3233
# inform those who want to know that NVDA has finished starting up.
@@ -160,7 +161,7 @@ def restartUnsafely():
160161
except ValueError:
161162
pass
162163
options = []
163-
if globalVars.runningAsSource:
164+
if NVDAState.isRunningAsSource():
164165
options.append(os.path.basename(sys.argv[0]))
165166
_startNewInstance(NewNVDAInstance(
166167
sys.executable,
@@ -172,7 +173,7 @@ def restartUnsafely():
172173
def restart(disableAddons=False, debugLogging=False):
173174
"""Restarts NVDA by starting a new copy."""
174175
if globalVars.appArgs.launcher:
175-
globalVars.exitCode=3
176+
NVDAState._setExitCode(3)
176177
if not triggerNVDAExit():
177178
log.error("NVDA already in process of exiting, this indicates a logic error.")
178179
return
@@ -185,7 +186,7 @@ def restart(disableAddons=False, debugLogging=False):
185186
except ValueError:
186187
pass
187188
options = []
188-
if globalVars.runningAsSource:
189+
if NVDAState.isRunningAsSource():
189190
options.append(os.path.basename(sys.argv[0]))
190191
if disableAddons:
191192
options.append('--disable-addons')
@@ -483,8 +484,9 @@ def main():
483484
import mathPres
484485
log.debug("Initializing MathPlayer")
485486
mathPres.initialize()
486-
if not globalVars.appArgs.minimal and (time.time()-globalVars.startTime)>5:
487-
log.debugWarning("Slow starting core (%.2f sec)" % (time.time()-globalVars.startTime))
487+
timeSinceStart = time.time() - NVDAState.getStartTime()
488+
if not globalVars.appArgs.minimal and timeSinceStart > 5:
489+
log.debugWarning("Slow starting core (%.2f sec)" % timeSinceStart)
488490
# Translators: This is spoken when NVDA is starting.
489491
speech.speakMessage(_("Loading NVDA. Please wait..."))
490492
import wx
@@ -673,7 +675,7 @@ def handlePowerStatusChange(self):
673675
# initialize wxpython localization support
674676
wxLocaleObj = wx.Locale()
675677
wxLang = getWxLangOrNone()
676-
if not globalVars.runningAsSource:
678+
if not NVDAState.isRunningAsSource():
677679
wxLocaleObj.AddCatalogLookupPathPrefix(os.path.join(globalVars.appDir, "locale"))
678680
if wxLang:
679681
try:
@@ -835,9 +837,10 @@ def _doPostNvdaStartupAction():
835837
config.saveOnExit()
836838

837839
try:
838-
if globalVars.focusObject and hasattr(globalVars.focusObject,"event_loseFocus"):
840+
focusObject = api.getFocusObject()
841+
if focusObject and hasattr(focusObject, "event_loseFocus"):
839842
log.debug("calling lose focus on object with focus")
840-
globalVars.focusObject.event_loseFocus()
843+
focusObject.event_loseFocus()
841844
except:
842845
log.exception("Lose focus error")
843846
try:

source/diffHandler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from textInfos import TextInfo, UNIT_LINE
1717
from threading import Lock
1818
from typing import List
19+
import NVDAState
1920

2021

2122
class DiffAlgo(AutoPropertyObject):
@@ -44,7 +45,7 @@ def _initialize(self):
4445
@note: This should be run from within the context of an acquired lock."""
4546
if not DiffMatchPatch._proc:
4647
log.debug("Starting diff-match-patch proxy")
47-
if globalVars.runningAsSource:
48+
if NVDAState.isRunningAsSource():
4849
dmp_path = (sys.executable, os.path.join(
4950
globalVars.appDir, "..", "include", "nvda_dmp", "nvda_dmp.py"
5051
))

source/documentationUtils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
import globalVars
1010
import languageHandler
11+
import NVDAState
12+
1113

1214

1315
def getDocFilePath(fileName, localized=True):
1416
if not getDocFilePath.rootPath:
15-
if globalVars.runningAsSource:
17+
if NVDAState.isRunningAsSource():
1618
getDocFilePath.rootPath = os.path.join(globalVars.appDir, "..", "user_docs")
1719
else:
1820
getDocFilePath.rootPath = os.path.join(globalVars.appDir, "documentation")
@@ -41,7 +43,7 @@ def getDocFilePath(fileName, localized=True):
4143
return None
4244
else:
4345
# Not localized.
44-
if globalVars.runningAsSource and fileName in ("copying.txt", "contributors.txt"):
46+
if NVDAState.isRunningAsSource() and fileName in ("copying.txt", "contributors.txt"):
4547
# If running from source, these two files are in the root dir.
4648
return os.path.join(globalVars.appDir, "..", fileName)
4749
else:

source/easeOfAccess.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from enum import Enum, IntEnum
1010
from typing import Any, List
1111

12-
import globalVars
1312
from logHandler import log
13+
import NVDAState
1414
import winreg
1515
import winUser
1616
import winVersion
@@ -23,13 +23,13 @@
2323

2424
def __getattr__(attrName: str) -> Any:
2525
"""Module level `__getattr__` used to preserve backward compatibility."""
26-
if attrName == "ROOT_KEY" and globalVars._allowDeprecatedAPI:
26+
if attrName == "ROOT_KEY" and NVDAState._allowDeprecatedAPI():
2727
log.warning("ROOT_KEY is deprecated, use RegistryKey.ROOT instead.")
2828
return RegistryKey.ROOT.value
29-
if attrName == "APP_KEY_PATH" and globalVars._allowDeprecatedAPI:
29+
if attrName == "APP_KEY_PATH" and NVDAState._allowDeprecatedAPI():
3030
log.warning("APP_KEY_PATH is deprecated, use RegistryKey.APP instead.")
3131
return RegistryKey.APP.value
32-
if attrName == "APP_KEY_NAME" and globalVars._allowDeprecatedAPI:
32+
if attrName == "APP_KEY_NAME" and NVDAState._allowDeprecatedAPI():
3333
log.warning("APP_KEY_NAME is deprecated.")
3434
return _APP_KEY_NAME
3535
raise AttributeError(f"module {repr(__name__)} has no attribute {repr(attrName)}")

source/eventHandler.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import speech
1515
from speech.commands import _CancellableSpeechCommand
1616
import treeInterceptorHandler
17-
import globalVars
1817
import controlTypes
1918
from logHandler import log
2019
import globalPluginHandler
@@ -182,7 +181,7 @@ def __init__(self, obj, reportDevInfo: bool):
182181

183182
# Assumption: we only process one focus event at a time, so even if several focus events are queued,
184183
# all focused objects will still gain this tracking attribute. Otherwise, this may need to be set via
185-
# api.setFocusObject when globalVars.focusObject is set.
184+
# api.setFocusObject when api.getFocusObject is set.
186185
setattr(obj, WAS_GAIN_FOCUS_OBJ_ATTR_NAME, True)
187186
elif not hasattr(obj, WAS_GAIN_FOCUS_OBJ_ATTR_NAME):
188187
setattr(obj, WAS_GAIN_FOCUS_OBJ_ATTR_NAME, False)
@@ -327,7 +326,7 @@ def doPreGainFocus(obj: "NVDAObjects.NVDAObject", sleepMode: bool = False) -> bo
327326
# - api.getFocusAncestors() via api.setFocusObject() called in doPreGainFocus
328327
speech._manager.removeCancelledSpeechCommands()
329328

330-
if globalVars.focusDifferenceLevel<=1:
329+
if api.getFocusDifferenceLevel() <= 1:
331330
newForeground=api.getDesktopObject().objectInForeground()
332331
if not newForeground:
333332
log.debugWarning("Can not get real foreground, resorting to focus ancestors")
@@ -341,7 +340,7 @@ def doPreGainFocus(obj: "NVDAObjects.NVDAObject", sleepMode: bool = False) -> bo
341340
executeEvent('foreground', newForeground)
342341
if sleepMode: return True
343342
#Fire focus entered events for all new ancestors of the focus if this is a gainFocus event
344-
for parent in globalVars.focusAncestors[globalVars.focusDifferenceLevel:]:
343+
for parent in api.getFocusAncestors()[api.getFocusDifferenceLevel()]:
345344
executeEvent("focusEntered",parent)
346345
if obj.treeInterceptor is not oldTreeInterceptor:
347346
if hasattr(oldTreeInterceptor,"event_treeInterceptor_loseFocus"):

0 commit comments

Comments
 (0)