toxygen/toxygen/notifications/tray.py

24 lines
939 B
Python
Raw Permalink Normal View History

2024-02-13 21:00:45 +00:00
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
2022-09-27 12:38:39 +00:00
2024-02-13 21:00:45 +00:00
from qtpy import QtCore, QtWidgets
2022-09-27 12:38:39 +00:00
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
"""
2022-10-08 17:59:45 +00:00
if tray and QtWidgets.QSystemTrayIcon.isSystemTrayAvailable():
2022-09-27 12:38:39 +00:00
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)