Last active
November 10, 2016 14:17
-
-
Save ompugao/755acc6163d0c3822e0a2832d3edbe52 to your computer and use it in GitHub Desktop.
a script to protect your eyes from dry-eye.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
__author__ = "ompugao" | |
import sys | |
from PyQt4 import QtGui, QtCore | |
class BlinkYourEyesWidget(QtGui.QWidget): | |
def __init__(self, parent = None, widget = None): | |
super(BlinkYourEyesWidget, self).__init__() | |
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint|QtCore.Qt.FramelessWindowHint) | |
#self.setAttribute(Qt.Qt.WA_NoSystemBackground) | |
#self.setAttribute(QtCore.Qt.WA_TranslucentBackground) | |
self.setWindowOpacity(0.6) | |
#self.setStyleSheet("background-color:transparent;") | |
self.background_color = QtCore.Qt.black | |
self.timer_count = 0 | |
self.timer = QtCore.QTimer() | |
self.timer.setInterval(100) #[milliseconds] | |
self.timer.timeout.connect(self.timer_callback) | |
self.initUI() | |
self.timer.start() | |
def initUI(self): | |
screenrect = QtGui.QDesktopWidget().screenGeometry().getRect() | |
width = screenrect[2] / 10 #170 | |
height = screenrect[3] / 10 #80 | |
self.setGeometry(screenrect[2] - width, 0, width, height) #screenrect[3] - height | |
self.setWindowTitle('Blink Your Eyes') | |
self.show() | |
def timer_callback(self, ): | |
self.timer_count = (self.timer_count + 1)%25 #3 seconds | |
if self.timer_count == 0: | |
self.background_color = QtCore.Qt.white | |
self.repaint() | |
elif self.timer_count == 3: | |
self.background_color = QtCore.Qt.black | |
self.repaint() | |
def paintEvent(self, e): | |
self.drawBackground() | |
def drawBackground(self,): | |
p = self.palette() | |
p.setColor(self.backgroundRole(), self.background_color) | |
self.setPalette(p) | |
def keyPressEvent(self, event): | |
if event.key() == QtCore.Qt.Key_Escape: | |
self.close() | |
def main(): | |
app = QtGui.QApplication(sys.argv) | |
ex = BlinkYourEyesWidget() | |
sys.exit(app.exec_()) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment