diff --git a/main/__init__.py b/main/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main/main.py similarity index 78% rename from main.py rename to main/main.py index 996eaa7..166f544 100644 --- a/main.py +++ b/main/main.py @@ -6,15 +6,35 @@ # # 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 os 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 +from PyQt5.QtWidgets import QApplication, QMainWindow, QSystemTrayIcon, QWidget, QMenu +from PyQt5.QtGui import QIntValidator, QIcon, QPixmap +from PyQt5.QtCore import QThread, pyqtSignal, Qt +from tool import QSSLoader +class SystemTrayIcon(QSystemTrayIcon): + + def __init__(self, icon, parent=None): + QSystemTrayIcon.__init__(self, icon, parent) + menu = QMenu(parent) + showAction = menu.addAction("显示") + exitAction = menu.addAction("退出") + self.setContextMenu(menu) + exitAction.triggered.connect( self.exit) + showAction.triggered.connect(self.showApp) + + def showApp(self): + main = QMainWindow() + style_sheet = QSSLoader.QSSLoader.read_qss_file(os.getcwd() + '/resource/current.qss') + main.setStyleSheet(style_sheet) + main.show() + + def exit(self): + QtCore.QCoreApplication.exit() class Ui_MainWindow(object): def setupUi(self, MainWindow): @@ -22,9 +42,6 @@ class Ui_MainWindow(object): 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) @@ -43,12 +60,10 @@ class Ui_MainWindow(object): 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.gridLayout.addWidget(self.start, 10, 2, Qt.AlignCenter) self.thirty = QtWidgets.QPushButton(self.centralwidget) self.thirty.setObjectName("thirty") self.gridLayout.addWidget(self.thirty, 5, 0, 1, 1) @@ -118,9 +133,14 @@ class Ui_MainWindow(object): self.time.setText(text) def startBtn(self): - self.thread = Work() - self.thread.setTime(self.time.text()) - self.thread.start() + try: + if self.time.text() and int(self.time.text()) > 0: + self.thread = Work() + self.thread.setTime(self.time.text()) + self.thread.start() + except Exception as e: + print(e) + # import apprcc_rc @@ -132,6 +152,9 @@ class Work(QThread): super(Work, self).__init__() def setTime(self, timeset): + print(True if timeset else False) + # print(timeset) + # print(type(timeset)) self.timeset = timeset def job(self): @@ -139,7 +162,7 @@ class Work(QThread): message = '该起来动一下了!' # subprocess.Popen(['notify-send', title+message]) notify2.init(title) - n = notify2.Notification(title, message) + n = notify2.Notification(title, message, os.getcwd() + '/images/stand.svg') n.show() def run(self): @@ -149,13 +172,19 @@ class Work(QThread): schedule.run_pending() QThread.sleep(1) + import sys if __name__ == '__main__': app = QApplication(sys.argv) - app.setWindowIcon(QIcon('./images/stand.svg')) + app.setWindowIcon(QIcon(os.getcwd() + '/images/stand.svg')) main = QMainWindow() ui = Ui_MainWindow() + w = QWidget() + trayIcon = SystemTrayIcon(QtGui.QIcon(os.getcwd() + '/images/stand.svg'), w) + trayIcon.show() ui.setupUi(main) + style_sheet = QSSLoader.QSSLoader.read_qss_file(os.getcwd() + '/resource/current.qss') + main.setStyleSheet(style_sheet) main.show() sys.exit(app.exec_()) diff --git a/resource/current.qss b/resource/current.qss new file mode 100644 index 0000000..39a3614 --- /dev/null +++ b/resource/current.qss @@ -0,0 +1,64 @@ +/*去掉item虚线边框*/ +QListWidget, QListView, QTreeWidget, QTreeView { + outline: 0px; +} +/*设置左侧选项的最小最大宽度,文字颜色和背景颜色*/ +QListWidget { + min-width: 120px; + max-width: 120px; + color: white; + background: black; + +} + +QPushButton { + max-width: 120px; + color: white; + border-top-left-radius:10px; + border-top-right-radius:10px; + border-bottom-left-radius:10px; + border-bottom-right-radius:10px; + background: blue; +} +QPushButton:pressed, +QPushButton:pressed:focus { + /* 改变背景色 */ + background-color: #f50057; + /* 改变边框风格 */ + border-style:inset; + /* 改变边框风格 */ + border-style:inset; +} + +QPushButton#upload_btn { + padding: 3px 20px; + text-align:center; +} + + +/*被选中时的背景颜色和左边框颜色*/ +QListWidget::item:selected { + background: rgb(52, 52, 52); + border-right: 4px solid rgb(9, 187, 7); +} +/*鼠标悬停颜色*/ +HistoryPanel::item:hover { + background: rgb(52, 52, 52); +} + +/*右侧的层叠窗口的背景颜色*/ +QStackedWidget { + background: rgb(30, 30, 30); +} +/*模拟的页面*/ +QLabel { + color: black; +} +QLineEdit { + border: 2px solid rgb(52,52,52); + border-top-left-radius:10px; + border-top-right-radius:10px; + border-bottom-left-radius:10px; + border-bottom-right-radius:10px; + +} \ No newline at end of file diff --git a/tool/QSSLoader.py b/tool/QSSLoader.py new file mode 100644 index 0000000..6faa814 --- /dev/null +++ b/tool/QSSLoader.py @@ -0,0 +1,9 @@ +class QSSLoader: + def __init__(self): + pass + + @staticmethod + def read_qss_file(qss_file_name): + # print(qss_file_name) + with open(qss_file_name, 'r', encoding='UTF-8') as file: + return file.read() diff --git a/tool/__init__.py b/tool/__init__.py new file mode 100644 index 0000000..e69de29