merge in next_gen branch

This commit is contained in:
emdee 2022-09-27 12:38:39 +00:00
parent fda07698db
commit b51ec9bd71
99 changed files with 14895 additions and 32 deletions

View file

View file

@ -0,0 +1,54 @@
import utils.util
import wave
import pyaudio
import os.path
SOUND_NOTIFICATION = {
'MESSAGE': 0,
'FRIEND_CONNECTION_STATUS': 1,
'FILE_TRANSFER': 2
}
class AudioFile:
chunk = 1024
def __init__(self, fl):
self.wf = wave.open(fl, 'rb')
self.p = pyaudio.PyAudio()
self.stream = self.p.open(
format=self.p.get_format_from_width(self.wf.getsampwidth()),
channels=self.wf.getnchannels(),
rate=self.wf.getframerate(),
output=True)
def play(self):
data = self.wf.readframes(self.chunk)
while data:
self.stream.write(data)
data = self.wf.readframes(self.chunk)
def close(self):
self.stream.close()
self.p.terminate()
def sound_notification(t):
"""
Plays sound notification
:param t: type of notification
"""
if t == SOUND_NOTIFICATION['MESSAGE']:
f = get_file_path('message.wav')
elif t == SOUND_NOTIFICATION['FILE_TRANSFER']:
f = get_file_path('file.wav')
else:
f = get_file_path('contact.wav')
a = AudioFile(f)
a.play()
a.close()
def get_file_path(file_name):
return os.path.join(utils.util.get_sounds_directory(), file_name)

View file

@ -0,0 +1,22 @@
from PyQt5 import QtCore, QtWidgets
def tray_notification(title, text, tray, window):
"""
Show tray notification and activate window icon
NOTE: different behaviour on different OS
:param title: Name of user who sent message or file
:param text: text of message or file info
:param tray: ref to tray icon
:param window: main window
"""
if QtWidgets.QSystemTrayIcon.isSystemTrayAvailable():
if len(text) > 30:
text = text[:27] + '...'
tray.showMessage(title, text, QtWidgets.QSystemTrayIcon.NoIcon, 3000)
QtWidgets.QApplication.alert(window, 0)
def message_clicked():
window.setWindowState(window.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)
window.activateWindow()
tray.messageClicked.connect(message_clicked)