Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sconstruct
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def recursiveCopy(env,targetDir,sourceDir):
import gettext
gettext.install("nvda")
sys.path.append("source")
import comtypesMonkeyPatches
import versionInfo
del sys.path[-1]

Expand Down
4 changes: 1 addition & 3 deletions source/comInterfaces_sconscript
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ interfaceBuilder=env.Builder(
)
env['BUILDERS']['comtypesInterface']=interfaceBuilder

#Bit of a dance to force comtypes generated interfaces in to our directory
# Force comtypes generated interfaces in to our directory
import comtypes.client
comtypes.client.gen_dir=Dir('comInterfaces').abspath
import sys
sys.modules['comtypes.gen']=comtypes.gen=__import__("comInterfaces",globals(),locals(),[])

COM_INTERFACES = {
"IAccessible2Lib.py": "typelibs/ia2.tlb",
Expand Down
22 changes: 18 additions & 4 deletions source/comtypesMonkeyPatches.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2009-2016 NV Access Limited
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2009-2019 NV Access Limited, Babbage B.V.
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

import ctypes
import _ctypes
import importlib
import comtypes.client._generate

# A version of ctypes.WINFUNCTYPE
# that produces a WinFunctionType class whose instance will convert COMError into a CallCancelled exception when called as a function.
Expand Down Expand Up @@ -125,3 +127,15 @@ def _check_version(actual):
if actual != required:
raise ImportError("Wrong version")
comtypes._check_version = _check_version


# Monkeypatch comtypes to clear the importlib cache when importing a new module
old_my_import = comtypes.client._generate._my_import


def new_my_import(fullname):
importlib.invalidate_caches()
return old_my_import(fullname)


comtypes.client._generate._my_import = new_my_import