From 87283408d5f579ff68e50003ce40ef2c06570409 Mon Sep 17 00:00:00 2001 From: ngld Date: Mon, 16 Apr 2018 02:51:01 +0200 Subject: [PATCH] Finally fix the COM problems by not importing comtypes early. --- knossos/clibs.py | 19 ++++++++++++++----- knossos/windows.py | 2 ++ releng/windows/Knossos.spec | 2 +- releng/windows/fix-comtypes-rthook.py | 6 ------ setup.py | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 releng/windows/fix-comtypes-rthook.py diff --git a/knossos/clibs.py b/knossos/clibs.py index 57c1b874..077a7213 100644 --- a/knossos/clibs.py +++ b/knossos/clibs.py @@ -25,8 +25,6 @@ from . import center if sys.platform == 'win32': - from comtypes import client as cc - ENCODING = 'latin1' else: ENCODING = 'utf8' @@ -417,7 +415,8 @@ def list_voices(): return [] try: - voice = cc.CreateObject('SAPI.SpVoice') + import win32com.client as cc + voice = cc.Dispatch('SAPI.SpVoice') return [v.GetDescription() for v in voice.GetVoices()] except Exception: logging.exception('Failed to retrieve voices!') @@ -429,8 +428,18 @@ def speak(voice, volume, text): return False try: - hdl = cc.CreateObject('SAPI.SpVoice') - hdl.Voice = hdl.GetVoices()[voice] + import win32com.client as cc + + hdl = cc.Dispatch('SAPI.SpVoice') + + # We always seem to receive an AttributeError when we try to access + # SetVoice the first time. It works the second time for whatever reason... >_> + try: + hdl.SetVoice + except AttributeError: + pass + + hdl.SetVoice(hdl.GetVoices()[voice]) hdl.Volume = volume hdl.Speak(text, 19) hdl.WaitUntilDone(10000) diff --git a/knossos/windows.py b/knossos/windows.py index b8255ed6..a1be8642 100644 --- a/knossos/windows.py +++ b/knossos/windows.py @@ -520,6 +520,8 @@ def _check_editable(self): except Exception: logging.exception('Failed to retrieve editable status for %s!' % mid) res[mid] = False + else: + res[mid] = False if not self.closed: self.updateEditable.emit(res) diff --git a/releng/windows/Knossos.spec b/releng/windows/Knossos.spec index ae9ae6b5..a9cabe5a 100644 --- a/releng/windows/Knossos.spec +++ b/releng/windows/Knossos.spec @@ -23,7 +23,7 @@ onefile = False him = ['knossos.parsetab'] debug = os.environ.get('KN_BUILD_DEBUG') == 'yes' is_x64 = platform.architecture()[0] == '64bit' -rthooks = ['fix-comtypes-rthook.py', 'version-rthook.py'] +rthooks = ['version-rthook.py'] if debug: rthooks.append('../../tools/common/debug-rthook.py') diff --git a/releng/windows/fix-comtypes-rthook.py b/releng/windows/fix-comtypes-rthook.py deleted file mode 100644 index fdf8213b..00000000 --- a/releng/windows/fix-comtypes-rthook.py +++ /dev/null @@ -1,6 +0,0 @@ -import os.path -import comtypes.client as cc - -cc.gen_dir = os.path.expandvars(r'$APPDATA\knossos\comtypes') -if not os.path.isdir(cc.gen_dir): - os.makedirs(cc.gen_dir) diff --git a/setup.py b/setup.py index 324d5db4..c76533cc 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ data = stream.read() commit = data[:7] if commit == '0000000': - commit = data.split(' ')[1][:7] + commit = data.splitlines()[-1].split(' ')[1][:7] version += '+' + commit elif len(ref[0]) == 40: