Add sound to notifications, and a silence option
Add an optional color icon Compute PFP height from screen height instead of fixing it at 50develop
parent
4560215d7a
commit
a510f5faf3
68
plchat.py
68
plchat.py
|
@ -37,6 +37,8 @@ APPDATA = appdirs.AppDirs('plchat', 'plchat').user_data_dir
|
||||||
THREADS = {}
|
THREADS = {}
|
||||||
STATIC_PREF = ''
|
STATIC_PREF = ''
|
||||||
ICON_PATH = os.path.join(os.path.dirname(__file__), "fedi.svg")
|
ICON_PATH = os.path.join(os.path.dirname(__file__), "fedi.svg")
|
||||||
|
ICON_PATH_COLOR = os.path.join(os.path.dirname(__file__), "fedi_color.svg")
|
||||||
|
NOTIF_SOUND = os.path.join(os.path.dirname(__file__), 'notif.wav')
|
||||||
|
|
||||||
class App(QMainWindow):
|
class App(QMainWindow):
|
||||||
settings = QSettings(APPDATA+"/settings.ini")
|
settings = QSettings(APPDATA+"/settings.ini")
|
||||||
|
@ -51,7 +53,10 @@ class App(QMainWindow):
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
self.setWindowTitle(self.title)
|
self.setWindowTitle(self.title)
|
||||||
self.setWindowIcon(QIcon(QPixmap(ICON_PATH)))
|
if self.settings.value('colorIcon', type=bool):
|
||||||
|
self.setWindowIcon(QIcon(QPixmap(ICON_PATH_COLOR)))
|
||||||
|
else:
|
||||||
|
self.setWindowIcon(QIcon(QPixmap(ICON_PATH)))
|
||||||
self.setGeometry(self.settings.value('left', type=int) or 10, self.settings.value('top', type=int) or 10, self.settings.value('width', type=int) or 640, self.settings.value('height', type=int) or 480)
|
self.setGeometry(self.settings.value('left', type=int) or 10, self.settings.value('top', type=int) or 10, self.settings.value('width', type=int) or 640, self.settings.value('height', type=int) or 480)
|
||||||
|
|
||||||
self._exit = False
|
self._exit = False
|
||||||
|
@ -103,9 +108,15 @@ class App(QMainWindow):
|
||||||
self.darkModeAction.setChecked(self.settings.value('darkMode', type=bool))
|
self.darkModeAction.setChecked(self.settings.value('darkMode', type=bool))
|
||||||
self.darkModeAction.setToolTip("Only affects chat bubbles")
|
self.darkModeAction.setToolTip("Only affects chat bubbles")
|
||||||
|
|
||||||
|
self.colorIconAction = QAction("Use Color Icon", self, checkable=True, triggered=self.useColorIcon)
|
||||||
|
self.colorIconAction.setChecked(self.settings.value('colorIcon', type=bool))
|
||||||
|
|
||||||
self.sendNotificationsAction = QAction("Send Notifications", self, checkable=True)
|
self.sendNotificationsAction = QAction("Send Notifications", self, checkable=True)
|
||||||
self.sendNotificationsAction.setChecked(self.settings.value('sendNotifications', type=bool))
|
self.sendNotificationsAction.setChecked(self.settings.value('sendNotifications', type=bool))
|
||||||
|
|
||||||
|
self.silenceNotifsAction = QAction("Silence Notifications", self, checkable=True, triggered=self.silenceNotifs)
|
||||||
|
self.silenceNotifsAction.setChecked(self.settings.value('silenceNotifications', type=bool))
|
||||||
|
|
||||||
self.fetchHeadersAction = QAction("Fetch Headers", self, checkable=True)
|
self.fetchHeadersAction = QAction("Fetch Headers", self, checkable=True)
|
||||||
self.fetchHeadersAction.setChecked(self.settings.value('fetchHeaders', type=bool))
|
self.fetchHeadersAction.setChecked(self.settings.value('fetchHeaders', type=bool))
|
||||||
|
|
||||||
|
@ -128,10 +139,14 @@ class App(QMainWindow):
|
||||||
|
|
||||||
systraymenu.addAction(showAction)
|
systraymenu.addAction(showAction)
|
||||||
systraymenu.addAction(hideAction)
|
systraymenu.addAction(hideAction)
|
||||||
|
systraymenu.addAction(self.silenceNotifsAction)
|
||||||
systraymenu.addAction(exitAction)
|
systraymenu.addAction(exitAction)
|
||||||
|
|
||||||
self.trayIcon = QSystemTrayIcon()
|
self.trayIcon = QSystemTrayIcon()
|
||||||
self.trayIcon.setIcon(QIcon(ICON_PATH))
|
if self.settings.value('colorIcon', type=bool):
|
||||||
|
self.trayIcon.setIcon(QIcon(ICON_PATH_COLOR))
|
||||||
|
else:
|
||||||
|
self.trayIcon.setIcon(QIcon(ICON_PATH))
|
||||||
self.trayIcon.setVisible(True)
|
self.trayIcon.setVisible(True)
|
||||||
self.trayIcon.setToolTip("PlChat")
|
self.trayIcon.setToolTip("PlChat")
|
||||||
self.trayIcon.setContextMenu(systraymenu)
|
self.trayIcon.setContextMenu(systraymenu)
|
||||||
|
@ -154,7 +169,9 @@ class App(QMainWindow):
|
||||||
prefsmenu.addAction(self.openInTrayAction)
|
prefsmenu.addAction(self.openInTrayAction)
|
||||||
prefsmenu.addAction(self.animatePicturesAction)
|
prefsmenu.addAction(self.animatePicturesAction)
|
||||||
prefsmenu.addAction(self.darkModeAction)
|
prefsmenu.addAction(self.darkModeAction)
|
||||||
|
prefsmenu.addAction(self.colorIconAction)
|
||||||
prefsmenu.addAction(self.sendNotificationsAction)
|
prefsmenu.addAction(self.sendNotificationsAction)
|
||||||
|
prefsmenu.addAction(self.silenceNotifsAction)
|
||||||
prefsmenu.addAction(self.fetchBackgroundsAction)
|
prefsmenu.addAction(self.fetchBackgroundsAction)
|
||||||
prefsmenu.addAction(self.fetchHeadersAction)
|
prefsmenu.addAction(self.fetchHeadersAction)
|
||||||
prefsmenu.addAction(self.twoFourTimeAction)
|
prefsmenu.addAction(self.twoFourTimeAction)
|
||||||
|
@ -217,6 +234,23 @@ class App(QMainWindow):
|
||||||
else:
|
else:
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
|
def silenceNotifs(self, dothing):
|
||||||
|
if dothing:
|
||||||
|
# Definitely not supposed to be poking around in the internals like this lul
|
||||||
|
Notification._notification_audio = None
|
||||||
|
else:
|
||||||
|
Notification.audio = NOTIF_SOUND
|
||||||
|
|
||||||
|
def useColorIcon(self, dothing):
|
||||||
|
if dothing:
|
||||||
|
self.setWindowIcon(QIcon(QPixmap(ICON_PATH_COLOR)))
|
||||||
|
if self.trayIcon:
|
||||||
|
self.trayIcon.setIcon(QIcon(ICON_PATH_COLOR))
|
||||||
|
else:
|
||||||
|
self.setWindowIcon(QIcon(QPixmap(ICON_PATH)))
|
||||||
|
if self.trayIcon:
|
||||||
|
self.trayIcon.setIcon(QIcon(ICON_PATH))
|
||||||
|
|
||||||
def eventLoop(self):
|
def eventLoop(self):
|
||||||
# Custom event loop to process queue events
|
# Custom event loop to process queue events
|
||||||
self.processEvents()
|
self.processEvents()
|
||||||
|
@ -243,6 +277,8 @@ class App(QMainWindow):
|
||||||
self.settings.setValue("sendNotifications", self.sendNotificationsAction.isChecked())
|
self.settings.setValue("sendNotifications", self.sendNotificationsAction.isChecked())
|
||||||
self.settings.setValue("fetchHeaders", self.fetchHeadersAction.isChecked())
|
self.settings.setValue("fetchHeaders", self.fetchHeadersAction.isChecked())
|
||||||
self.settings.setValue("twoFourTime", self.twoFourTimeAction.isChecked())
|
self.settings.setValue("twoFourTime", self.twoFourTimeAction.isChecked())
|
||||||
|
self.settings.setValue('colorIcon', self.colorIconAction.isChecked())
|
||||||
|
self.settings.setValue('silenceNotifications', self.silenceNotifsAction.isChecked())
|
||||||
event.accept()
|
event.accept()
|
||||||
self._eventloop.stop()
|
self._eventloop.stop()
|
||||||
|
|
||||||
|
@ -452,8 +488,14 @@ class App(QMainWindow):
|
||||||
flip = False
|
flip = False
|
||||||
if flip:
|
if flip:
|
||||||
if self.trayIcon:
|
if self.trayIcon:
|
||||||
self.trayIcon.setIcon(QIcon(QPixmap(ICON_PATH)))
|
if self.settings.value('colorIcon', type=bool):
|
||||||
self.setWindowIcon(QIcon(QPixmap(ICON_PATH)))
|
self.trayIcon.setIcon(QIcon(ICON_PATH_COLOR))
|
||||||
|
else:
|
||||||
|
self.trayIcon.setIcon(QIcon(ICON_PATH))
|
||||||
|
if self.settings.value('colorIcon', type=bool):
|
||||||
|
self.setWindowIcon(QIcon(QPixmap(ICON_PATH_COLOR)))
|
||||||
|
else:
|
||||||
|
self.setWindowIcon(QIcon(QPixmap(ICON_PATH)))
|
||||||
self.tabs.widget(ind).markRead()
|
self.tabs.widget(ind).markRead()
|
||||||
self.tabs.widget(ind).setFocus(Qt.NoFocusReason)
|
self.tabs.widget(ind).setFocus(Qt.NoFocusReason)
|
||||||
|
|
||||||
|
@ -476,8 +518,14 @@ class App(QMainWindow):
|
||||||
flip = False
|
flip = False
|
||||||
if flip:
|
if flip:
|
||||||
if self.trayIcon:
|
if self.trayIcon:
|
||||||
self.trayIcon.setIcon(QIcon(QPixmap(ICON_PATH)))
|
if self.settings.value('colorIcon', type=bool):
|
||||||
self.setWindowIcon(QIcon(QPixmap(ICON_PATH)))
|
self.trayIcon.setIcon(QIcon(ICON_PATH_COLOR))
|
||||||
|
else:
|
||||||
|
self.trayIcon.setIcon(QIcon(ICON_PATH))
|
||||||
|
if self.settings.value('colorIcon', type=bool):
|
||||||
|
self.setWindowIcon(QIcon(QPixmap(ICON_PATH_COLOR)))
|
||||||
|
else:
|
||||||
|
self.setWindowIcon(QIcon(QPixmap(ICON_PATH)))
|
||||||
self.tabs.widget(ind).markRead()
|
self.tabs.widget(ind).markRead()
|
||||||
self.tabs.widget(ind).setFocus(Qt.NoFocusReason)
|
self.tabs.widget(ind).setFocus(Qt.NoFocusReason)
|
||||||
|
|
||||||
|
@ -761,13 +809,13 @@ class SingleMessage(QWidget):
|
||||||
p = QPixmap(path)
|
p = QPixmap(path)
|
||||||
if p.isNull():
|
if p.isNull():
|
||||||
p = QPixmap(APPDATA+'/'+ex.getCurrentAcc()[1]+'avi.png')
|
p = QPixmap(APPDATA+'/'+ex.getCurrentAcc()[1]+'avi.png')
|
||||||
p = p.scaledToHeight(50, mode=Qt.SmoothTransformation)
|
p = p.scaledToHeight(round(QDesktopWidget().screenGeometry(-1).height() / 21.6), mode=Qt.SmoothTransformation)
|
||||||
self.userPixmap = p
|
self.userPixmap = p
|
||||||
def setConvoPixmap(self, path):
|
def setConvoPixmap(self, path):
|
||||||
p = QPixmap(path)
|
p = QPixmap(path)
|
||||||
if p.isNull():
|
if p.isNull():
|
||||||
p = QPixmap(APPDATA+'/'+ex.getCurrentAcc()[1]+'avi.png')
|
p = QPixmap(APPDATA+'/'+ex.getCurrentAcc()[1]+'avi.png')
|
||||||
p = p.scaledToHeight(50, mode=Qt.SmoothTransformation)
|
p = p.scaledToHeight(round(QDesktopWidget().screenGeometry(-1).height() / 21.6), mode=Qt.SmoothTransformation)
|
||||||
self.convoPixmap = p
|
self.convoPixmap = p
|
||||||
|
|
||||||
class MessageAvatar(QLabel):
|
class MessageAvatar(QLabel):
|
||||||
|
@ -1392,8 +1440,8 @@ class IconLabel(QLabel):
|
||||||
|
|
||||||
Notification = Notify(
|
Notification = Notify(
|
||||||
default_notification_title="PlChat",
|
default_notification_title="PlChat",
|
||||||
default_notification_icon=ICON_PATH
|
default_notification_icon=ICON_PATH,
|
||||||
#default_notification_audio=NOTIF_SOUND
|
default_notification_audio=NOTIF_SOUND
|
||||||
)
|
)
|
||||||
|
|
||||||
def sendNotification(message, title=None, icon=None):
|
def sendNotification(message, title=None, icon=None):
|
||||||
|
|
Loading…
Reference in New Issue