98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
import ctypes
|
|
import logging
|
|
from ctypes import wintypes
|
|
|
|
# Set up logging
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def get_resource_path(relative_path):
|
|
import os
|
|
import sys
|
|
try:
|
|
base_path = sys._MEIPASS
|
|
except Exception:
|
|
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__)))
|
|
base_path = project_root
|
|
full_path = os.path.normpath(os.path.join(base_path, relative_path))
|
|
return full_path
|
|
|
|
class Win32SoundHandler:
|
|
def __init__(self, hwnd):
|
|
self.hwnd = hwnd
|
|
self.SND_ALIAS = 0x00010000
|
|
self.SND_FILENAME = 0x00020000
|
|
self.SND_ASYNC = 0x00000001
|
|
self._setup_playsoundapi()
|
|
|
|
def _setup_playsoundapi(self):
|
|
winmm = ctypes.windll.winmm
|
|
self.PlaySoundW = winmm.PlaySoundW
|
|
self.PlaySoundW.argtypes = (
|
|
wintypes.LPCWSTR,
|
|
wintypes.HMODULE,
|
|
wintypes.DWORD
|
|
)
|
|
self.PlaySoundW.restype = wintypes.BOOL
|
|
|
|
def play_info_sound(self):
|
|
self.PlaySoundW("SystemAsterisk", None, self.SND_ALIAS | self.SND_ASYNC)
|
|
|
|
def play_error_sound(self):
|
|
self.PlaySoundW("SystemHand", None, self.SND_ALIAS | self.SND_ASYNC)
|
|
|
|
def play_warn_sound(self):
|
|
self.PlaySoundW("SystemExclamation", None, self.SND_ALIAS | self.SND_ASYNC)
|
|
|
|
def play_question_sound(self):
|
|
self.PlaySoundW("SystemQuestion", None, self.SND_ALIAS | self.SND_ASYNC)
|
|
|
|
def play_default_sound(self):
|
|
self.PlaySoundW("SystemDefault", None, self.SND_ALIAS | self.SND_ASYNC)
|
|
|
|
def play_notification_sound(self):
|
|
self.PlaySoundW("SystemNotification", None, self.SND_ALIAS | self.SND_ASYNC)
|
|
|
|
def play_mail_sound(self):
|
|
self.PlaySoundW("MailBeep", None, self.SND_ALIAS | self.SND_ASYNC)
|
|
|
|
def play_exit_sound(self):
|
|
self.PlaySoundW("SystemExit", None, self.SND_ALIAS | self.SND_ASYNC)
|
|
|
|
def play_connect_server_or_channel(self):
|
|
try:
|
|
sound_path = get_resource_path("sounds/space-pdj.wav")
|
|
import os
|
|
if os.path.exists(sound_path):
|
|
self.PlaySoundW(sound_path, None, self.SND_FILENAME | self.SND_ASYNC)
|
|
else:
|
|
logger.warning(f"Sound file not found: {sound_path}")
|
|
except Exception as e:
|
|
logger.error(f"Error playing popout click sound: {e}")
|
|
|
|
|
|
def play_popout_click(self):
|
|
try:
|
|
sound_path = get_resource_path("sounds/startup.wav")
|
|
import os
|
|
if os.path.exists(sound_path):
|
|
self.PlaySoundW(sound_path, None, self.SND_FILENAME | self.SND_ASYNC)
|
|
else:
|
|
logger.warning(f"Sound file not found: {sound_path}")
|
|
except Exception as e:
|
|
logger.error(f"Error playing popout click sound: {e}")
|
|
|
|
def play_msg_recv(self):
|
|
try:
|
|
sound_path = get_resource_path("sounds/balloon.wav")
|
|
import os
|
|
if os.path.exists(sound_path):
|
|
self.PlaySoundW(sound_path, None, self.SND_FILENAME | self.SND_ASYNC)
|
|
else:
|
|
logger.warning(f"Sound file not found: {sound_path}")
|
|
except Exception as e:
|
|
logger.error(f"Error playing message received sound: {e}")
|
|
|
|
|
|
|