161 lines
6.9 KiB
Python
161 lines
6.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# Form implementation generated from reading ui file 'sit_reminder.ui'
|
|
#
|
|
# Created by: PyQt5 UI code generator 5.15.6
|
|
#
|
|
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
|
|
# run again. Do not edit this file unless you know what you are doing.
|
|
|
|
|
|
import notify2
|
|
import schedule
|
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow
|
|
from PyQt5.QtGui import QIntValidator, QIcon
|
|
from PyQt5.QtCore import QThread, pyqtSignal
|
|
|
|
|
|
class Ui_MainWindow(object):
|
|
def setupUi(self, MainWindow):
|
|
MainWindow.setObjectName("MainWindow")
|
|
MainWindow.resize(344, 400)
|
|
MainWindow.setMinimumSize(QtCore.QSize(344, 400))
|
|
MainWindow.setMaximumSize(QtCore.QSize(344, 400))
|
|
# icon = QtGui.QIcon()
|
|
# icon.addPixmap(QtGui.QPixmap(":/icon/images/stand.svg"), QtGui.QIcon.Normal, QtGui.QIcon.On)
|
|
# MainWindow.setWindowIcon(icon)
|
|
MainWindow.setIconSize(QtCore.QSize(64, 64))
|
|
self.centralwidget = QtWidgets.QWidget(MainWindow)
|
|
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
|
|
sizePolicy.setHorizontalStretch(0)
|
|
sizePolicy.setVerticalStretch(0)
|
|
sizePolicy.setHeightForWidth(self.centralwidget.sizePolicy().hasHeightForWidth())
|
|
self.centralwidget.setSizePolicy(sizePolicy)
|
|
self.centralwidget.setMaximumSize(QtCore.QSize(600, 400))
|
|
self.centralwidget.setAutoFillBackground(False)
|
|
self.centralwidget.setObjectName("centralwidget")
|
|
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
|
|
self.gridLayout.setObjectName("gridLayout")
|
|
self.start = QtWidgets.QPushButton(self.centralwidget)
|
|
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
|
|
sizePolicy.setHorizontalStretch(0)
|
|
sizePolicy.setVerticalStretch(0)
|
|
sizePolicy.setHeightForWidth(self.start.sizePolicy().hasHeightForWidth())
|
|
self.start.setSizePolicy(sizePolicy)
|
|
# self.start.setStyleSheet("border-image: url(:/image/images/play.svg);\n"
|
|
# "border-image: url(:/image/images/pause.svg);")
|
|
self.start.setIconSize(QtCore.QSize(32, 32))
|
|
self.start.setAutoExclusive(False)
|
|
self.start.setObjectName("start")
|
|
self.gridLayout.addWidget(self.start, 10, 2, 1, 1)
|
|
self.thirty = QtWidgets.QPushButton(self.centralwidget)
|
|
self.thirty.setObjectName("thirty")
|
|
self.gridLayout.addWidget(self.thirty, 5, 0, 1, 1)
|
|
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
|
self.gridLayout.addItem(spacerItem, 11, 2, 1, 1)
|
|
self.sixty = QtWidgets.QPushButton(self.centralwidget)
|
|
self.sixty.setObjectName("sixty")
|
|
self.gridLayout.addWidget(self.sixty, 5, 4, 1, 1)
|
|
spacerItem1 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
|
self.gridLayout.addItem(spacerItem1, 4, 2, 1, 1)
|
|
spacerItem2 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
|
self.gridLayout.addItem(spacerItem2, 2, 2, 1, 1)
|
|
spacerItem3 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
|
self.gridLayout.addItem(spacerItem3, 6, 2, 1, 1)
|
|
self.time = QtWidgets.QLineEdit(self.centralwidget)
|
|
self.time.setAlignment(QtCore.Qt.AlignCenter)
|
|
self.time.setObjectName("time")
|
|
self.gridLayout.addWidget(self.time, 7, 2, 1, 1)
|
|
spacerItem4 = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
|
|
self.gridLayout.addItem(spacerItem4, 0, 2, 1, 1)
|
|
spacerItem5 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
|
|
self.gridLayout.addItem(spacerItem5, 1, 0, 1, 1)
|
|
self.selectTime = QtWidgets.QLabel(self.centralwidget)
|
|
font = QtGui.QFont()
|
|
font.setPointSize(25)
|
|
self.selectTime.setFont(font)
|
|
self.selectTime.setAlignment(QtCore.Qt.AlignCenter)
|
|
self.selectTime.setObjectName("selectTime")
|
|
self.gridLayout.addWidget(self.selectTime, 1, 1, 1, 3)
|
|
spacerItem6 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
|
|
self.gridLayout.addItem(spacerItem6, 1, 4, 1, 1)
|
|
self.ten = QtWidgets.QPushButton(self.centralwidget)
|
|
self.ten.setObjectName("ten")
|
|
self.gridLayout.addWidget(self.ten, 3, 4, 1, 1)
|
|
self.one = QtWidgets.QPushButton(self.centralwidget)
|
|
self.one.setObjectName("one")
|
|
self.gridLayout.addWidget(self.one, 3, 0, 1, 1)
|
|
MainWindow.setCentralWidget(self.centralwidget)
|
|
|
|
self.one.clicked.connect(lambda: self.setTime('1'))
|
|
self.ten.clicked.connect(lambda: self.setTime('10'))
|
|
self.thirty.clicked.connect(lambda: self.setTime('30'))
|
|
self.sixty.clicked.connect(lambda: self.setTime('60'))
|
|
|
|
# 限制输入范围为 1,240
|
|
self.time.setPlaceholderText('请输入整数')
|
|
val = QIntValidator()
|
|
val.setRange(1, 240)
|
|
self.time.setValidator(val)
|
|
|
|
self.start.clicked.connect(self.startBtn)
|
|
|
|
self.retranslateUi(MainWindow)
|
|
QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
|
|
|
def retranslateUi(self, MainWindow):
|
|
_translate = QtCore.QCoreApplication.translate
|
|
MainWindow.setWindowTitle(_translate("MainWindow", "提醒小助手"))
|
|
self.start.setText(_translate("MainWindow", "开始"))
|
|
self.thirty.setText(_translate("MainWindow", "30分"))
|
|
self.sixty.setText(_translate("MainWindow", "60分"))
|
|
self.selectTime.setText(_translate("MainWindow", "选择时长"))
|
|
self.ten.setText(_translate("MainWindow", "10分"))
|
|
self.one.setText(_translate("MainWindow", "1分"))
|
|
|
|
def setTime(self, text):
|
|
self.time.setText(text)
|
|
|
|
def startBtn(self):
|
|
self.thread = Work()
|
|
self.thread.setTime(self.time.text())
|
|
self.thread.start()
|
|
|
|
# import apprcc_rc
|
|
|
|
|
|
class Work(QThread):
|
|
signal = pyqtSignal()
|
|
|
|
def __init__(self):
|
|
super(Work, self).__init__()
|
|
|
|
def setTime(self, timeset):
|
|
self.timeset = timeset
|
|
|
|
def job(self):
|
|
title = '休息助手 '
|
|
message = '该起来动一下了!'
|
|
# subprocess.Popen(['notify-send', title+message])
|
|
notify2.init(title)
|
|
n = notify2.Notification(title, message)
|
|
n.show()
|
|
|
|
def run(self):
|
|
self.timeset = int(self.timeset)
|
|
schedule.every(self.timeset).minutes.do(self.job)
|
|
while True:
|
|
schedule.run_pending()
|
|
QThread.sleep(1)
|
|
|
|
import sys
|
|
|
|
if __name__ == '__main__':
|
|
app = QApplication(sys.argv)
|
|
app.setWindowIcon(QIcon('./images/stand.svg'))
|
|
main = QMainWindow()
|
|
ui = Ui_MainWindow()
|
|
ui.setupUi(main)
|
|
main.show()
|
|
sys.exit(app.exec_())
|