I'm going blind. I use Python to protect my eyes

Keywords: REST Qt less Pycharm

background

Recently, it's more and more hard to watch the computer at work, and my eyes are more and more uncomfortable. Occasionally, a few tears will come out. At this time, I finally realized that it must be excessive use of eyes. On average, I stare at the screen for no less than eight hours every day, and my eyes don't get proper rest, which will lead to more and more sore eyes. So, I spent half a day, using PyQt5 to do this little eye care assistant from scratch.

major function

1. Force yourself to rest properly and protect your eyes
2. Force yourself to rest properly and protect your eyes
3. Force yourself to rest properly and protect your eyes
Important things are to be repeated for 3 times!!!!!!

Run screenshots

1. Main interface


Main interface.png

2. Interface in operation


Running interface.png

3. Rest time interface (occupy 90% of the screen, as for the top layer, it is mandatory that you can't use the computer, of course, you have to force back to the desktop...)
Rest time interface.png

Code sent (low quality code, do not like light spray 0.0)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
@Time    : 2019/2/28 14:02
@Author  : Negen
@Site    :
@File    : RestAssistantApp.py
@Software: PyCharm
'''
import sys

from PyQt5.QtCore import *
from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication, QLabel, QLineEdit, QMessageBox
from PyQt5 import QtCore
from PyQt5.QtGui import QFont, QColor, QPalette
class MainFrame(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint|QtCore.Qt.WindowMinimizeButtonHint)
        font = QFont()
        font.setPointSize(16)
        self.timeLabel = QLabel(self)
        self.timeLabel.setFont(font)
        self.timeLabel.resize(300, 30)
        timer = QTimer(self)
        timer.timeout.connect(self.showtime)
        timer.start()

        self.label = QLabel("Enter the length of break interval( M)", self)
        self.label.setFont(font)
        self.label.move(50, 50)
        self.label.resize(250, 30)
        self.edit = QLineEdit(self)
        self.edit.setFont(font)
        self.edit.move(125, 95)
        self.edit.resize(50, 30)
        self.btn = QPushButton("confirm", self)
        self.btn.resize(150, 30)
        self.btn.move(75, 150)
        self.resize(300, 200)
        self.setWindowTitle('Eye care assistant')
        self.show()

    """
    //Real time display time
    """
    def showtime(self):
        datetime = QDateTime.currentDateTime()
        timeText = datetime.toString()
        self.timeLabel.setText(" " + timeText)

    def clickHandel(self):
        try:
            minutes = int(self.edit.text())
            self.close()
            self.littleFrame = LittleFrame(minutes)
            self.littleFrame.show()
        except Exception as e:
            QMessageBox.information(self, "Tips", "please enter an integer")


class LittleFrame(QMainWindow):
    def __init__(self,minutes):
        super().__init__()
        self.initUI()
        self.minutes = minutes
        self.second = minutes * 60

    def initUI(self):
        self.desktop = QApplication.desktop()
        # Get display resolution size
        self.screenRect = self.desktop.screenGeometry()
        self.height = self.screenRect.height()
        self.width = self.screenRect.width()
        self.setGeometry(self.width*0.85, self.height*0.8, 250, 80)
        # self.setFixedSize(self.width*0.9, self.height*0.9)
        #Disable maximize button  #Roof placement
        self.setWindowFlags(QtCore.Qt.WindowCloseButtonHint|QtCore.Qt.WindowStaysOnTopHint)
        self.setWindowTitle('Eye protection assistant in operation...')
        font = QFont()
        font.setPointSize(16)
        self.timeLabel = QLabel(self)
        self.timeLabel.setFont(font)
        self.timeLabel.move(40,15)
        self.timeLabel.resize(250,50)
        self.timer = QTimer(self)
        self.timer.setInterval(1000)
        self.timer.timeout.connect(self.showtime)
        self.timer.start()

    """
    //Real time display time
    """
    def showtime(self):
        if self.second == 0:
            self.close()
            self.restFrame = RestFrame()
            self.restFrame.setStyleSheet("#MainWindow{background-color: yellow}")
            self.restFrame.show()

        self.timeLabel.setText(str(self.second).zfill(2) + "Rest in seconds")
        self.second -= 1


class RestFrame(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.desktop = QApplication.desktop()
        # Get display resolution size
        self.screenRect = self.desktop.screenGeometry()
        self.height = self.screenRect.height()
        self.width = self.screenRect.width()
        self.setGeometry(self.width*0.05, self.height*0.05, self.width*0.9, self.height*0.9)
        # self.setFixedSize(self.width*0.9, self.height*0.9)
        #Disable maximize button  #Roof placement
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint|QtCore.Qt.WindowMinimizeButtonHint|QtCore.Qt.WindowStaysOnTopHint)
        self.setStyleSheet("#MainWindow{background-color: yellow}")
        font = QFont()
        font.setPointSize(80)
        self.titleLabel = QLabel(self)
        self.titleLabel.setText("Oh, rest....")
        self.titleLabel.resize(self.width,self.height/2)
        self.titleLabel.move(self.width*0.3, self.height*0.3)
        self.titleLabel.setFont(font)
        self.setWindowTitle('Rest...')


if __name__ == '__main__':
    app = QApplication(sys.argv)
    a = MainFrame()
    a.show()
    a.btn.clicked.connect(a.clickHandel)
    sys.exit(app.exec_())

Concluding remarks

After all, my first contact with pyqt5 (it's not an excuse for me to show), if there are any better ideas and suggestions. Please do not be stingy, generous to put forward (so as to reflect your atmosphere).
thanks!!!!!!

Posted by mckinney3 on Fri, 29 Nov 2019 23:01:47 -0800