2018-02-15 18:28:01 +01:00
|
|
|
"""BMStatusBar class definition"""
|
2020-06-09 12:49:54 +02:00
|
|
|
|
2016-12-15 16:11:29 +01:00
|
|
|
from time import time
|
2020-06-09 12:49:54 +02:00
|
|
|
|
2018-02-15 18:28:01 +01:00
|
|
|
from qtpy import QtWidgets
|
2016-12-15 16:11:29 +01:00
|
|
|
|
2018-02-15 18:28:01 +01:00
|
|
|
|
|
|
|
class BMStatusBar(QtWidgets.QStatusBar):
|
2020-06-09 12:49:54 +02:00
|
|
|
"""Status bar with queue and priorities"""
|
2016-12-15 16:11:29 +01:00
|
|
|
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
|
|
|
|
|
2018-02-15 18:28:01 +01:00
|
|
|
def timerEvent(self, event): # pylint: disable=unused-argument
|
2020-06-09 12:49:54 +02:00
|
|
|
"""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"""
|
2016-12-15 16:11:29 +01:00
|
|
|
while len(self.important) > 0:
|
|
|
|
self.iterator += 1
|
|
|
|
try:
|
2018-02-15 18:28:01 +01:00
|
|
|
if (
|
|
|
|
self.important[self.iterator][1]
|
|
|
|
+ BMStatusBar.deleteAfter < time()
|
|
|
|
):
|
2016-12-15 16:11:29 +01:00
|
|
|
del self.important[self.iterator]
|
|
|
|
self.iterator -= 1
|
|
|
|
continue
|
|
|
|
except IndexError:
|
|
|
|
self.iterator = -1
|
|
|
|
continue
|
2018-02-15 18:28:01 +01:00
|
|
|
self.showMessage(self.important[self.iterator][0], 0)
|
2016-12-15 16:11:29 +01:00
|
|
|
break
|
|
|
|
|
|
|
|
def addImportant(self, message):
|
|
|
|
self.important.append([message, time()])
|
|
|
|
self.iterator = len(self.important) - 2
|
|
|
|
self.timerEvent(None)
|