PyBitmessage-2021-04-27/src/bitmessageqt/statusbar.py
Dmitri Bogomolov 51b5e64f34
Initial support for PyQt5 (main window shown) using QtPy package.
QtPy is a compatibility layer which allows to use the code written for
PyQt5 with any python Qt binding: PyQt4, PyQt5, pyside or pyside2.

Main differences in PyQt5:

  - all widget classes are now in QtWidgets package, not QtGui;
  - QString obsoleted by unicode (sip API 2);
  - changed the way of signals connection.

Closes: #1191
2021-03-03 18:28:47 +02:00

43 lines
1.4 KiB
Python

"""BMStatusBar class definition"""
from time import time
from qtpy import QtWidgets
class BMStatusBar(QtWidgets.QStatusBar):
"""Status bar with queue and priorities"""
duration = 10000
deleteAfter = 60
def __init__(self, parent=None):
super(BMStatusBar, self).__init__(parent)
self.important = []
self.timer = self.startTimer(BMStatusBar.duration)
self.iterator = 0
def timerEvent(self, event): # pylint: disable=unused-argument
"""an event handler which allows to queue and prioritise messages to
show in the status bar, for example if many messages come very quickly
after one another, it adds delays and so on"""
while len(self.important) > 0:
self.iterator += 1
try:
if (
self.important[self.iterator][1]
+ BMStatusBar.deleteAfter < time()
):
del self.important[self.iterator]
self.iterator -= 1
continue
except IndexError:
self.iterator = -1
continue
self.showMessage(self.important[self.iterator][0], 0)
break
def addImportant(self, message):
self.important.append([message, time()])
self.iterator = len(self.important) - 2
self.timerEvent(None)