MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / calcTrayIcon

Method calcTrayIcon

src/bitmessageqt/__init__.py:1657–1686  ·  view source on GitHub ↗
(self, iconFileName, inboxUnreadCount)

Source from the content-addressed store, hash-verified

1655 self.drawTrayIcon(iconFileName, self.findInboxUnreadCount())
1656
1657 def calcTrayIcon(self, iconFileName, inboxUnreadCount):
1658 pixmap = QtGui.QPixmap(":/newPrefix/images/"+iconFileName)
1659 if inboxUnreadCount > 0:
1660 # choose font and calculate font parameters
1661 fontName = "Lucida"
1662 fontSize = 10
1663 font = QtGui.QFont(fontName, fontSize, QtGui.QFont.Bold)
1664 fontMetrics = QtGui.QFontMetrics(font)
1665 # text
1666 txt = str(inboxUnreadCount)
1667 rect = fontMetrics.boundingRect(txt)
1668 # margins that we add in the top-right corner
1669 marginX = 2
1670 marginY = 0 # it looks like -2 is also ok due to the error of metric
1671 # if it renders too wide we need to change it to a plus symbol
1672 if rect.width() > 20:
1673 txt = "+"
1674 fontSize = 15
1675 font = QtGui.QFont(fontName, fontSize, QtGui.QFont.Bold)
1676 fontMetrics = QtGui.QFontMetrics(font)
1677 rect = fontMetrics.boundingRect(txt)
1678 # draw text
1679 painter = QtGui.QPainter()
1680 painter.begin(pixmap)
1681 painter.setPen(
1682 QtGui.QPen(QtGui.QColor(255, 0, 0), QtCore.Qt.SolidPattern))
1683 painter.setFont(font)
1684 painter.drawText(24-rect.right()-marginX, -rect.top()+marginY, txt)
1685 painter.end()
1686 return QtGui.QIcon(pixmap)
1687
1688 def drawTrayIcon(self, iconFileName, inboxUnreadCount):
1689 self.tray.setIcon(self.calcTrayIcon(iconFileName, inboxUnreadCount))

Callers 2

initTrayIconMethod · 0.95
drawTrayIconMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected