Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init(self):
GetModule("shdocvw.dll")
SHDocVw = comtypes.gen.SHDocVw
self.shellWindows = CreateObject(SHDocVw.ShellWindows)
self.__listOpenExplorerDirectories()
exit(1)
if save_as.exists():
print('Error: Path {0} already exists. Not overwriting'.format(save_as), file=sys.stderr)
exit(1)
with Timer(factor=1000) as t:
parsed = parse(text, stylesheets=css)
print('Parsed in {0:f} ms'.format(t.elapsed))
with Timer(factor=1000) as t:
try:
word = CreateObject("Word.Application")
except AttributeError as e:
gen_dir = inspect.getsourcefile(gen)
print('****** There was an error opening word ******')
print('This is a transient error that sometimes happens.')
print('Remove all files (except __init__.py) from here:')
print(os.path.dirname(gen_dir))
print('Then retry the program')
print('*********************************************')
raise e
doc = word.Documents.Add()
print('Opened word in {0:f} ms'.format(t.elapsed))
word.Visible = not arguments['--hidden']
from comtypes.gen import Word as constants
try:
comtypes_path = os.path.abspath(os.path.join(comtypes.__path__[0], "gen"))
if not os.path.isdir(comtypes_path):
os.mkdir(comtypes_path)
logger.info("Created comtypes.gen directory: '%s'", comtypes_path)
comtypes_init = os.path.join(comtypes_path, "__init__.py")
if not os.path.exists(comtypes_init):
logger.info("Writing __init__.py file: '%s'", comtypes_init)
ofi = open(comtypes_init, "w")
ofi.write("# comtypes.gen package, directory for generated files.\n")
ofi.close()
except (OSError, IOError), details:
logger.info("Creating comtypes.gen package failed: %s", details)
module = sys.modules["comtypes.gen"] = types.ModuleType("comtypes.gen")
comtypes.gen = module
comtypes.gen.__path__ = []
logger.info("Created a memory-only package.")
def get_object_by_coordinates(self, x, y):
obj_point = ctypes.wintypes.POINT()
obj_point.x = x
obj_point.y = y
i_accessible = ctypes.POINTER(comtypes.gen.Accessibility.IAccessible)()
obj_child_id = comtypes.automation.VARIANT()
ctypes.oledll.oleacc.AccessibleObjectFromPoint(
obj_point,
ctypes.byref(i_accessible),
ctypes.byref(obj_child_id))
return WinElement(i_accessible, obj_child_id.value or 0)
class CallCancelled(Exception):
"""Raised when a call is cancelled.
"""
# Apply several monkey patches to comtypes
# noinspection PyUnresolvedReferences
import comtypesMonkeyPatches
# Initialise comtypes.client.gen_dir and the comtypes.gen search path
# and Append our comInterfaces directory to the comtypes.gen search path.
import comtypes
import comtypes.client
import comtypes.gen
import comInterfaces
comtypes.gen.__path__.append(comInterfaces.__path__[0])
import sys
import winVersion
import threading
import nvwave
import os
import time
import ctypes
import logHandler
import globalVars
from logHandler import log
import addonHandler
import extensionPoints
# inform those who want to know that NVDA has finished starting up.
postNvdaStartup = extensionPoints.Action()
def __init__(self, obj_handle, i_object_id):
"""
Constructor.
:param obj_handle: instance of i_accessible or window handle.
:param int i_object_id: object id.
"""
if isinstance(obj_handle, comtypes.gen.Accessibility.IAccessible):
i_accessible = obj_handle
else:
i_accessible = ctypes.POINTER(
comtypes.gen.Accessibility.IAccessible)()
ctypes.oledll.oleacc.AccessibleObjectFromWindow(
obj_handle,
0,
ctypes.byref(comtypes.gen.Accessibility.IAccessible._iid_),
ctypes.byref(i_accessible))
self._i_accessible = i_accessible
self._i_object_id = i_object_id
self._cached_children = set()
def _create_comtypes_gen_package():
"""Import (creating it if needed) the comtypes.gen package."""
try:
import comtypes.gen
logger.info("Imported existing %s", comtypes.gen)
except ImportError:
import comtypes
logger.info("Could not import comtypes.gen, trying to create it.")
try:
comtypes_path = os.path.abspath(os.path.join(comtypes.__path__[0], "gen"))
if not os.path.isdir(comtypes_path):
os.mkdir(comtypes_path)
logger.info("Created comtypes.gen directory: '%s'", comtypes_path)
comtypes_init = os.path.join(comtypes_path, "__init__.py")
if not os.path.exists(comtypes_init):
logger.info("Writing __init__.py file: '%s'", comtypes_init)
ofi = open(comtypes_init, "w")
ofi.write("# comtypes.gen package, directory for generated files.\n")
ofi.close()
except (OSError, IOError), details:
logger.info("Creating comtypes.gen package failed: %s", details)
def setAsComtypesGenModule():
import sys
import comtypes
import comtypes_gen
sys.modules['comtypes.gen']=comtypes.gen=comtypes_gen
def _create_comtypes_gen_package():
"""Import (creating it if needed) the comtypes.gen package."""
try:
import comtypes.gen
logger.info("Imported existing %s", comtypes.gen)
except ImportError:
import comtypes
logger.info("Could not import comtypes.gen, trying to create it.")
module = sys.modules["comtypes.gen"] = types.ModuleType("comtypes.gen")
comtypes.gen = module
comtypes.gen.__path__ = []
logger.info("Created a memory-only package.")
def _create_comtypes_gen_package():
"""Import (creating it if needed) the comtypes.gen package."""
try:
import comtypes.gen
logger.info("Imported existing %s", comtypes.gen)
except ImportError:
import comtypes
logger.info("Could not import comtypes.gen, trying to create it.")
module = sys.modules["comtypes.gen"] = types.ModuleType("comtypes.gen")
comtypes.gen = module
comtypes.gen.__path__ = []
logger.info("Created a memory-only package.")