Skip to content

Commit 84d96a1

Browse files
committed
programmatically draw number of new screens in tray icon, fix #17
1 parent 6626316 commit 84d96a1

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

app.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def initTrayIcon(self):
7676
self.trayIconLoading = QIcon("resources/img/menu_bar_extras_icon__loading.png")
7777
self.trayIconLoading.addPixmap("resources/img/menu_bar_extras_icon__loading_alt.png", QIcon.Selected)
7878

79-
self.trayIconUnread = QIcon("resources/img/menu_bar_extras_icon__unread.png")
80-
self.trayIconUnread.addPixmap("resources/img/menu_bar_extras_icon__unread_alt.png", QIcon.Selected)
79+
self.trayIconUnreadPixmap = QPixmap("resources/img/menu_bar_extras_icon__unread.png")
80+
self.trayIconUnreadAltPixmap = QPixmap("resources/img/menu_bar_extras_icon__unread_alt.png")
8181

8282
self.actionQuit = QAction(u"Quit", self, triggered=self.quit)
8383
self.actionShowConfigurationDialog = QAction(u"Configuration", self, triggered=self.showConfigurationDialog)
@@ -101,7 +101,28 @@ def trayIconSetIconLoading(self):
101101
self.trayIcon.setIcon(self.trayIconLoading)
102102

103103
def trayIconSetIconUnread(self, count=1):
104-
self.trayIcon.setIcon(self.trayIconUnread)
104+
font = QFont("Tahoma", 8, QFont.Bold)
105+
font.setStyleHint(QFont.SansSerif)
106+
font.setStyleStrategy(QFont.PreferQuality)
107+
108+
new_icon_pixmap = self.trayIconUnreadPixmap.copy()
109+
painter = QPainter(new_icon_pixmap)
110+
painter.setFont(font)
111+
painter.drawText(0, 3, 14, 16, QtCore.Qt.AlignRight, str(count))
112+
painter.end()
113+
114+
new_icon = QIcon(new_icon_pixmap)
115+
116+
new_icon_alt_pixmap = self.trayIconUnreadAltPixmap.copy()
117+
painter = QPainter(new_icon_alt_pixmap)
118+
painter.setFont(font)
119+
painter.setPen(QPen(QColor(255, 255, 255)))
120+
painter.drawText(0, 3, 15, 16, QtCore.Qt.AlignRight, str(count))
121+
painter.end()
122+
123+
new_icon.addPixmap(new_icon_alt_pixmap, QIcon.Selected)
124+
125+
self.trayIcon.setIcon(new_icon)
105126

106127
def updateTrayIconMenu(self):
107128
self.trayIconMenu.clear()
-24 Bytes
Loading
-11 Bytes
Loading

0 commit comments

Comments
 (0)