Handle missing winsound module not in startup

This commit is contained in:
Philipp Hörist 2017-01-01 23:08:30 +01:00
parent 33041619ee
commit 32604e99bf
2 changed files with 11 additions and 12 deletions

View File

@ -165,15 +165,6 @@ class GajimApplication(Gtk.Application):
from common import check_paths
if os.name == 'nt':
try:
import winsound # windows-only built-in module for playing wav
except Exception:
pritext = _('Gajim needs pywin32 to run')
sectext = _('Please make sure that Pywin32 is installed on your '
'system. You can get it at %s') % \
'http://sourceforge.net/project/showfiles.php?group_id=78018'
if pritext:
dlg = Gtk.MessageDialog(None,
Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL,

View File

@ -52,8 +52,16 @@ from string import Template
from common.i18n import Q_
from common.i18n import ngettext
if os.name == 'nt':
try:
HAS_WINSOUND = True
import winsound # windows-only built-in module for playing wav
except ImportError:
HAS_WINSOUND = False
print('Gajim is not able to playback sound because'
'pywin32 is missing', file=sys.stderr)
try:
import winsound # windows-only built-in module for playing wav
import wave # posix-only fallback wav playback
import ossaudiodev as oss
except Exception:
@ -739,12 +747,12 @@ def play_sound_file(path_to_soundfile):
path_to_soundfile = check_soundfile_path(path_to_soundfile)
if path_to_soundfile is None:
return
elif os.name == 'nt':
elif os.name == 'nt' and HAS_WINSOUND:
try:
winsound.PlaySound(path_to_soundfile,
winsound.SND_FILENAME|winsound.SND_ASYNC)
except Exception:
pass
log.exception('Sound Playback Error')
elif os.name == 'posix':
if gajim.config.get('soundplayer') == '':
def _oss_play():