Skip to content

Instantly share code, notes, and snippets.

@dpinney
Created November 16, 2023 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpinney/a3c0b1f333ef89748fa12d057a553193 to your computer and use it in GitHub Desktop.
Save dpinney/a3c0b1f333ef89748fa12d057a553193 to your computer and use it in GitHub Desktop.
Slow Blink LED
#!/usr/local/bin/python
# Inspired by https://news.ycombinator.com/item?id=38274782#38276107
# Blinks a green circle on top of all windows at 60 BPM because it seems to help people focus?
# Requires `pip install pyqt5`
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QPixmap, QPainter, QColor, QBrush
from PyQt5.QtCore import QTimer, Qt
class BlinkingCircleApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Blinking Circle')
self.setGeometry(300, 300, 250, 250)
self.setWindowFlags(Qt.WindowStaysOnTopHint)
self.label = QLabel(self)
self.pixmap = QPixmap(250, 250)
self.pixmap.fill(Qt.white)
self.label.setPixmap(self.pixmap)
self.visible = False
self.timer = QTimer(self)
self.timer.timeout.connect(self.blink_circle)
self.timer.start(500) # 500 ms interval for 60 bpm
self.show()
def blink_circle(self):
painter = QPainter(self.pixmap)
if self.visible:
painter.setBrush(QBrush(Qt.white, Qt.SolidPattern))
painter.drawEllipse(50, 50, 150, 150)
else:
painter.setBrush(QBrush(QColor('green'), Qt.SolidPattern))
painter.drawEllipse(50, 50, 150, 150)
self.label.setPixmap(self.pixmap)
self.visible = not self.visible
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = BlinkingCircleApp()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment