diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/Snapshot/SnapshotTimer.py --- a/src/eric7/Snapshot/SnapshotTimer.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Snapshot/SnapshotTimer.py Wed Jul 13 14:55:47 2022 +0200 @@ -15,55 +15,57 @@ class SnapshotTimer(QWidget): """ Class implementing the snapshot timer widget. - + @signal timeout() emitted after the timer timed out """ + timeout = pyqtSignal() - + def __init__(self): """ Constructor """ super().__init__(None) - + self.setWindowFlags( - Qt.WindowType.WindowStaysOnTopHint | - Qt.WindowType.FramelessWindowHint | - Qt.WindowType.X11BypassWindowManagerHint + Qt.WindowType.WindowStaysOnTopHint + | Qt.WindowType.FramelessWindowHint + | Qt.WindowType.X11BypassWindowManagerHint ) - + self.__timer = QTimer() self.__textRect = QRect() self.__time = 0 self.__length = 0 self.__toggle = True - + # text is taken from paintEvent with maximum number plus some margin try: - fmWidth = self.fontMetrics().horizontalAdvance(self.tr( - "Snapshot will be taken in %n seconds", "", 99)) + fmWidth = self.fontMetrics().horizontalAdvance( + self.tr("Snapshot will be taken in %n seconds", "", 99) + ) except AttributeError: - fmWidth = self.fontMetrics().width(self.tr( - "Snapshot will be taken in %n seconds", "", 99)) + fmWidth = self.fontMetrics().width( + self.tr("Snapshot will be taken in %n seconds", "", 99) + ) self.resize(fmWidth + 6, self.fontMetrics().height() + 4) - + self.__timer.timeout.connect(self.__bell) - + def start(self, seconds): """ Public method to start the timer. - + @param seconds timeout value (integer) """ screenGeom = QApplication.screens()[0].geometry() - self.move(screenGeom.width() // 2 - self.size().width() // 2, - screenGeom.top()) + self.move(screenGeom.width() // 2 - self.size().width() // 2, screenGeom.top()) self.__toggle = True self.__time = 0 self.__length = seconds self.__timer.start(1000) self.show() - + def stop(self): """ Public method to stop the timer. @@ -71,7 +73,7 @@ self.setVisible(False) self.hide() self.__timer.stop() - + def __bell(self): """ Private slot handling timer timeouts. @@ -82,53 +84,59 @@ if self.__time == self.__length: self.__timer.stop() self.timeout.emit() - + self.__time += 1 self.__toggle = not self.__toggle self.update() - + def paintEvent(self, evt): """ Protected method handling paint events. - + @param evt paint event (QPaintEvent) """ painter = QPainter(self) - + if self.__time < self.__length: pal = QToolTip.palette() - textBackgroundColor = pal.color(QPalette.ColorGroup.Active, - QPalette.ColorRole.Base) + textBackgroundColor = pal.color( + QPalette.ColorGroup.Active, QPalette.ColorRole.Base + ) if self.__toggle: - textColor = pal.color(QPalette.ColorGroup.Active, - QPalette.ColorRole.Text) + textColor = pal.color( + QPalette.ColorGroup.Active, QPalette.ColorRole.Text + ) else: - textColor = pal.color(QPalette.ColorGroup.Active, - QPalette.ColorRole.Base) + textColor = pal.color( + QPalette.ColorGroup.Active, QPalette.ColorRole.Base + ) painter.setPen(textColor) painter.setBrush(textBackgroundColor) - helpText = self.tr("Snapshot will be taken in %n seconds", "", - self.__length - self.__time) + helpText = self.tr( + "Snapshot will be taken in %n seconds", "", self.__length - self.__time + ) textRect = painter.boundingRect( self.rect().adjusted(2, 2, -2, -2), Qt.AlignmentFlag.AlignHCenter | Qt.TextFlag.TextSingleLine, - helpText) + helpText, + ) painter.drawText( textRect, Qt.AlignmentFlag.AlignHCenter | Qt.TextFlag.TextSingleLine, - helpText) - + helpText, + ) + def enterEvent(self, evt): """ Protected method handling the mouse cursor entering the widget. - + @param evt enter event (QEvent) """ screenGeom = QApplication.screens()[0].geometry() if self.x() == screenGeom.left(): self.move( - screenGeom.x() + - (screenGeom.width() // 2 - self.size().width() // 2), - screenGeom.top()) + screenGeom.x() + (screenGeom.width() // 2 - self.size().width() // 2), + screenGeom.top(), + ) else: self.move(screenGeom.topLeft())