Skip to content

Commit

Permalink
Merge 1da2d23 into 66bcf8e
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelDCurran authored Sep 22, 2020
2 parents 66bcf8e + 1da2d23 commit 42151e4
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 47 deletions.
3 changes: 2 additions & 1 deletion source/COMRegistrationFixes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import subprocess
import winVersion
import globalVars
from logHandler import log

# Particular 64 bit / 32 bit system paths
Expand Down Expand Up @@ -53,7 +54,7 @@ def applyRegistryPatch(fileName,wow64=False):
log.debug("Applied registry patch: %s with %s"%(fileName,regedit))


OLEACC_REG_FILE_PATH = os.path.abspath(os.path.join("COMRegistrationFixes", "oleaccProxy.reg"))
OLEACC_REG_FILE_PATH = os.path.join(globalVars.appDir, "COMRegistrationFixes", "oleaccProxy.reg")
def fixCOMRegistrations():
"""
Registers most common COM proxies, in case they had accidentally been unregistered or overwritten by 3rd party software installs/uninstalls.
Expand Down
6 changes: 3 additions & 3 deletions source/NVDAHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import time
import globalVars

versionedLibPath='lib'
versionedLibPath = os.path.join(globalVars.appDir, 'lib')
if os.environ.get('PROCESSOR_ARCHITEW6432') == 'ARM64':
versionedLib64Path = 'libArm64'
versionedLib64Path = os.path.join(globalVars.appDir, 'libArm64')
else:
versionedLib64Path = 'lib64'
versionedLib64Path = os.path.join(globalVars.appDir, 'lib64')
if getattr(sys,'frozen',None):
# Not running from source. Libraries are in a version-specific directory
versionedLibPath=os.path.join(versionedLibPath,versionInfo.version)
Expand Down
5 changes: 4 additions & 1 deletion source/NVDAObjects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""Module that contains the base NVDA object type with dynamic class creation support,
as well as the associated TextInfo class."""

import os
import time
import re
import weakref
Expand All @@ -31,6 +32,8 @@
import brailleInput
import locationHelper
import aria
import globalVars


class NVDAObjectTextInfo(textInfos.offsets.OffsetsTextInfo):
"""A default TextInfo which is used to enable text review of information about widgets that don't support text content.
Expand Down Expand Up @@ -1030,7 +1033,7 @@ def _reportErrorInPreviousWord(self):
# No error.
return
import nvwave
nvwave.playWaveFile(r"waves\textError.wav")
nvwave.playWaveFile(os.path.join(globalVars.appDir, "waves", "textError.wav"))

def event_liveRegionChange(self):
"""
Expand Down
6 changes: 4 additions & 2 deletions source/NVDAObjects/behaviors.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import ui
import braille
import nvwave
import globalVars


class ProgressBar(NVDAObject):

Expand Down Expand Up @@ -796,15 +798,15 @@ def event_suggestionsOpened(self):
# Translators: Announced in braille when suggestions appear when search term is entered in various search fields such as Start search box in Windows 10.
braille.handler.message(_("Suggestions"))
if config.conf["presentation"]["reportAutoSuggestionsWithSound"]:
nvwave.playWaveFile(r"waves\suggestionsOpened.wav")
nvwave.playWaveFile(os.path.join(globalVars.appDir, "waves", "suggestionsOpened.wav"))

def event_suggestionsClosed(self):
"""Called when suggestions list or container is closed.
Subclasses should provide custom implementations if possible.
By default NVDA will announce this via speech, braille or via a sound.
"""
if config.conf["presentation"]["reportAutoSuggestionsWithSound"]:
nvwave.playWaveFile(r"waves\suggestionsClosed.wav")
nvwave.playWaveFile(os.path.join(globalVars.appDir, "waves", "suggestionsClosed.wav"))

class WebDialog(NVDAObject):
"""
Expand Down
5 changes: 4 additions & 1 deletion source/brailleTables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
"""Manages information about available braille translation tables.
"""

import os
import collections
from locale import strxfrm
import globalVars


#: The directory in which liblouis braille tables are located.
TABLES_DIR = r"louis\tables"
TABLES_DIR = os.path.join(globalVars.appDir, "louis", "tables")

#: Information about a braille table.
#: This has the following attributes:
Expand Down
10 changes: 6 additions & 4 deletions source/characterProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self,locale):
@type locale: string
"""
self._entries = {}
fileName=os.path.join('locale',locale,'characterDescriptions.dic')
fileName = os.path.join(globalVars.appDir, 'locale', locale, 'characterDescriptions.dic')
if not os.path.isfile(fileName):
raise LookupError(fileName)
f = codecs.open(fileName,"r","utf_8_sig",errors="replace")
Expand Down Expand Up @@ -367,12 +367,14 @@ def _getSpeechSymbolsForLocale(locale):
# Load the data before loading other symbols,
# in order to allow translators to override them.
try:
builtin.load(os.path.join("locale", locale, "cldr.dic"),
allowComplexSymbols=False)
builtin.load(
os.path.join(globalVars.appDir, "locale", locale, "cldr.dic"),
allowComplexSymbols=False
)
except IOError:
log.debugWarning("No CLDR data for locale %s" % locale)
try:
builtin.load(os.path.join("locale", locale, "symbols.dic"))
builtin.load(os.path.join(globalVars.appDir, "locale", locale, "symbols.dic"))
except IOError:
_noSymbolLocalesCache.add(locale)
raise LookupError("No symbol information for locale %s" % locale)
Expand Down
4 changes: 2 additions & 2 deletions source/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def isInstalledCopy():
return False
winreg.CloseKey(k)
try:
return os.stat(instDir)==os.stat(os.getcwd())
return os.stat(instDir) == os.stat(globalVars.appDir)
except WindowsError:
return False

Expand Down Expand Up @@ -125,7 +125,7 @@ def getUserDefaultConfigPath(useInstalledPathIfExists=False):
# Therefore add a suffix to the directory to make it specific to Windows Store application versions.
installedUserConfigPath+='_appx'
return installedUserConfigPath
return u'.\\userConfig\\'
return os.path.join(globalVars.appDir, 'userConfig')

def getSystemConfigPath():
if isInstalledCopy():
Expand Down
14 changes: 10 additions & 4 deletions source/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def main():
log.info("Developer Scratchpad mode enabled")
if not globalVars.appArgs.minimal and config.conf["general"]["playStartAndExitSounds"]:
try:
nvwave.playWaveFile("waves\\start.wav")
nvwave.playWaveFile(os.path.join(globalVars.appDir, "waves", "start.wav"))
except:
pass
logHandler.setLogLevelFromConfig()
Expand Down Expand Up @@ -298,7 +298,10 @@ def onEndSession(evt):
speech.cancelSpeech()
if not globalVars.appArgs.minimal and config.conf["general"]["playStartAndExitSounds"]:
try:
nvwave.playWaveFile("waves\\exit.wav",asynchronous=False)
nvwave.playWaveFile(
os.path.join(globalVars.appDir, "waves", "exit.wav"),
asynchronous=False
)
except:
pass
log.info("Windows session ending")
Expand Down Expand Up @@ -410,7 +413,7 @@ def handlePowerStatusChange(self):
if not wxLang and '_' in lang:
wxLang=locale.FindLanguageInfo(lang.split('_')[0])
if hasattr(sys,'frozen'):
locale.AddCatalogLookupPathPrefix(os.path.join(os.getcwd(),"locale"))
locale.AddCatalogLookupPathPrefix(os.path.join(globalVars.appDir, "locale"))
# #8064: Wx might know the language, but may not actually contain a translation database for that language.
# If we try to initialize this language, wx will show a warning dialog.
# #9089: some languages (such as Aragonese) do not have language info, causing language getter to fail.
Expand Down Expand Up @@ -591,7 +594,10 @@ def run(self):

if not globalVars.appArgs.minimal and config.conf["general"]["playStartAndExitSounds"]:
try:
nvwave.playWaveFile("waves\\exit.wav",asynchronous=False)
nvwave.playWaveFile(
os.path.join(globalVars.appDir, "waves", "exit.wav"),
asynchronous=False
)
except:
pass
# #5189: Destroy the message window as late as possible
Expand Down
4 changes: 2 additions & 2 deletions source/fonts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# brailleViewer.py
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2019 NV Access Limited
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
from typing import List

import globalVars
from logHandler import log
import os
from ctypes import WinDLL
Expand All @@ -13,7 +13,7 @@
Loads custom fonts for use in NVDA.
"""

fontsDir = os.path.abspath("fonts")
fontsDir = os.path.join(globalVars.appDir, "fonts")


def _isSupportedFontPath(f: str) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions source/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
updateCheck = None

### Constants
NVDA_PATH = os.getcwd()
NVDA_PATH = globalVars.appDir
ICON_PATH=os.path.join(NVDA_PATH, "images", "nvda.ico")
DONATE_URL = "http://www.nvaccess.org/donate/"

Expand All @@ -57,7 +57,7 @@ def getDocFilePath(fileName, localized=True):
if hasattr(sys, "frozen"):
getDocFilePath.rootPath = os.path.join(NVDA_PATH, "documentation")
else:
getDocFilePath.rootPath = os.path.abspath(os.path.join("..", "user_docs"))
getDocFilePath.rootPath = os.path.join(NVDA_PATH, "..", "user_docs")

if localized:
lang = languageHandler.getLanguage()
Expand Down
4 changes: 2 additions & 2 deletions source/inputCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,10 @@ def loadLocaleGestureMap(self):
self.localeGestureMap.clear()
lang = languageHandler.getLanguage()
try:
self.localeGestureMap.load(os.path.join("locale", lang, "gestures.ini"))
self.localeGestureMap.load(os.path.join(globalVars.appDir, "locale", lang, "gestures.ini"))
except IOError:
try:
self.localeGestureMap.load(os.path.join("locale", lang.split('_')[0], "gestures.ini"))
self.localeGestureMap.load(os.path.join(globalVars.appDir, "locale", lang.split('_')[0], "gestures.ini"))
except IOError:
log.debugWarning("No locale gesture map for language %s" % lang)

Expand Down
2 changes: 1 addition & 1 deletion source/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def getDocFilePath(fileName,installDir):
return tryPath

def copyProgramFiles(destPath):
sourcePath=os.getcwd()
sourcePath = globalVars.appDir
detectUserConfig=True
detectNVDAExe=True
for curSourceDir,subDirs,files in os.walk(sourcePath):
Expand Down
6 changes: 3 additions & 3 deletions source/logHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class RemoteHandler(logging.Handler):

def __init__(self):
#Load nvdaHelperRemote.dll but with an altered search path so it can pick up other dlls in lib
path=os.path.abspath(os.path.join(u"lib",buildVersion.version,u"nvdaHelperRemote.dll"))
path = os.path.join(globalVars.appDir, "lib", buildVersion.version, "nvdaHelperRemote.dll")
h=ctypes.windll.kernel32.LoadLibraryExW(path,0,LOAD_WITH_ALTERED_SEARCH_PATH)
if not h:
raise OSError("Could not load %s"%path)
Expand All @@ -276,7 +276,7 @@ def handle(self,record):
elif record.levelno>=logging.ERROR and shouldPlayErrorSound:
import nvwave
try:
nvwave.playWaveFile("waves\\error.wav")
nvwave.playWaveFile(os.path.join(globalVars.appDir, "waves", "error.wav"))
except:
pass
return super().handle(record)
Expand Down Expand Up @@ -333,7 +333,7 @@ def _getDefaultLogFilePath():
import tempfile
return os.path.join(tempfile.gettempdir(), "nvda.log")
else:
return ".\\nvda.log"
return os.path.join(globalVars.appDir, "nvda.log")

def _excepthook(*exc_info):
log.exception(exc_info=exc_info, codepath="unhandled exception")
Expand Down
27 changes: 24 additions & 3 deletions source/nvda.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,32 @@

import sys
import os
import globalVars


if getattr(sys, "frozen", None):
# We are running as an executable.
# Append the path of the executable to sys so we can import modules from the dist dir.
sys.path.append(sys.prefix)
os.chdir(sys.prefix)
appDir = sys.prefix
else:
import sourceEnv
#We should always change directory to the location of this module (nvda.pyw), don't rely on sys.path[0]
os.chdir(os.path.normpath(os.path.dirname(__file__)))
appDir = os.path.normpath(os.path.dirname(__file__))
appDir = os.path.abspath(appDir)
os.chdir(appDir)
globalVars.appDir = appDir

import ctypes
import locale
import gettext

try:
gettext.translation('nvda',localedir='locale',languages=[locale.getdefaultlocale()[0]]).install(True)
gettext.translation(
'nvda',
localedir=os.path.join(globalVars.appDir, 'locale'),
languages=[locale.getdefaultlocale()[0]]
).install(True)
except:
gettext.install('nvda')

Expand Down Expand Up @@ -112,6 +121,18 @@ parser.add_argument('--enable-start-on-logon',metavar="True|False",type=stringTo
# If this option is provided, NVDA will not replace an already running instance (#10179)
parser.add_argument('--ease-of-access',action="store_true",dest='easeOfAccess',default=False,help="Started by Windows Ease of Access")
(globalVars.appArgs,globalVars.appArgsExtra)=parser.parse_known_args()
# Make any app args path values absolute
# So as to not be affected by the current directory changing during process lifetime.
pathAppArgs = [
"configPath",
"logFileName",
"portablePath",
]
for name in pathAppArgs:
origVal = getattr(globalVars.appArgs, name)
if isinstance(origVal, str):
newVal = os.path.abspath(origVal)
setattr(globalVars.appArgs, name, newVal)

def terminateRunningNVDA(window):
processID,threadID=winUser.getWindowThreadProcessID(window)
Expand Down
32 changes: 24 additions & 8 deletions source/nvda_slave.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
Performs miscellaneous tasks which need to be performed in a separate process.
"""

import sys
import os
import globalVars


# Initialise comtypes.client.gen_dir and the comtypes.gen search path
# and Append our comInterfaces directory to the comtypes.gen search path.
import comtypes
Expand All @@ -16,23 +21,34 @@ import comtypes.gen
import comInterfaces
comtypes.gen.__path__.append(comInterfaces.__path__[0])


if hasattr(sys, "frozen"):
# Error messages (which are only for debugging) should not cause the py2exe log message box to appear.
sys.stderr = sys.stdout
globalVars.appDir = sys.prefix
else:
globalVars.appDir = os.path.abspath(os.path.dirname(__file__))

# #2391: some functions may still require the current directory to be set to NVDA's app dir
os.chdir(globalVars.appDir)


import gettext
import locale
#Localization settings
try:
gettext.translation('nvda',localedir='locale',languages=[locale.getdefaultlocale()[0]]).install()
gettext.translation(
'nvda',
localedir=os.path.join(globalVars.appDir, 'locale'),
languages=[locale.getdefaultlocale()[0]]
).install()
except:
gettext.install('nvda')

import sys
import os

import versionInfo
import logHandler
if hasattr(sys, "frozen"):
# Error messages (which are only for debugging) should not cause the py2exe log message box to appear.
sys.stderr = sys.stdout
#Many functions expect the current directory to be where slave is located (#2391)
os.chdir(sys.prefix)


def main():
import installer
Expand Down
Loading

0 comments on commit 42151e4

Please sign in to comment.