Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dictation-toolbox/natlink
Browse files Browse the repository at this point in the history
…into python-3.11
  • Loading branch information
LexiconCode committed Nov 7, 2022
2 parents 73251dd + aaca609 commit 9b012c9
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions pythonsrc/src/natlink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

# make import natlink possible, getting all the _natlink_corexx.pyd functions...
#we have to know which pyd is registered by the installer.

#pylint:disable=W0702
import importlib
import importlib.machinery
import importlib.util
import traceback

import winreg
import ctypes
W32OutputDebugString = ctypes.windll.kernel32.OutputDebugStringW

Expand All @@ -25,20 +25,20 @@ def outputDebugString(to_show):
clsid="{dd990001-bb89-11d2-b031-0060088dc929}" #natlinks well known clsid

#these keys hold the pyd name for natlink, set up through the installer run regsvr32
subkey1=f"WOW6432Node\CLSID\{clsid}\InprocServer32"
subkey2=f"CLSID\{clsid}\InprocServer32" #only likely if not 64 bit windows
subkey1=fr"WOW6432Node\CLSID\{clsid}\InprocServer32"
subkey2=fr"CLSID\{clsid}\InprocServer32" #only likely if not 64 bit windows
subkeys=[subkey1,subkey2]
default_pyd="_natlink_core15.pyd" #just a sensible default if one isn't registered.
import winreg as wr

path_to_pyd=""
#find the PYD actually registered, and load that one.
found_registered_pyd=False
for subkey in subkeys:
try:
reg=wr.ConnectRegistry(None,wr.HKEY_CLASSES_ROOT)
sk=wr.OpenKey(reg,subkey)
path_to_pyd=wr.QueryValue(sk,None)
found_registered_pyd=True
reg = winreg.ConnectRegistry(None,winreg.HKEY_CLASSES_ROOT)
sk = winreg.OpenKey(reg,subkey)
path_to_pyd = winreg.QueryValue(sk,None)
found_registered_pyd = True
break
except:
pass
Expand All @@ -59,13 +59,13 @@ def outputDebugString(to_show):
from _natlink_core import execScript as _execScript
from _natlink_core import playString as _playString
from _natlink_core import recognitionMimic as _recognitionMimic
except Exception:
tb_lines=''.join(traceback.format_except())
except Exception as exc:
tb_lines=''.join(traceback.format_exception(exc))

outputDebugString(f"Python traceback \n{tb_lines}\n in {__file__}")

def lmap(fn,iter):
return list(map(fn,iter))
def lmap(fn,Iter):
return list(map(fn, Iter))

def playString(a, hook=0):
return _playString(toWindowsEncoding(a), hook)
Expand All @@ -74,6 +74,9 @@ def execScript(script,args=None):
#only encode the script. can't find a single case of anyone using the args
if args is None:
args = []
else:
## added QH:
print(f'execScript, args found: {args}!!!!')
script_w=toWindowsEncoding(script)
return _execScript(script_w,args)

Expand Down

0 comments on commit 9b012c9

Please sign in to comment.