代码拉取完成,页面将自动刷新
# -*- coding:utf8 -*-
from os import path, makedirs
from time import strftime, localtime
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication,QSystemTrayIcon,QMenu,QAction
import sys, os
import win32api
def log(msg, type = "info"):
"""
Write information to log file.
type: info, warn, error
"""
log_dir = "./log"
log_file = log_dir + "/clock.log"
if not path.exists(log_dir):
makedirs(log_dir)
curr_time = "[ " + strftime("%Y-%m-%d %H:%M:%S", localtime()) + " " + " ]"
if type == "info":
content = curr_time + " <INFO> " + msg + "\n"
elif type == "warn":
content = curr_time + " <WARNING> " + msg + "\n"
elif type == "error":
content = curr_time + " <ERROR> " + msg + "\n"
else:
content = curr_time + u"没有定义的日志类型!\n"
fp = open(log_file, "a")
fp.write(content)
fp.close()
class SysTray(QSystemTrayIcon):
def __init__(self, parent=None):
super(SysTray, self).__init__(parent)
self.initMenu()
self.setMenu()
self.activated.connect(self.iconClicked)
def initMenu(self):
self.menu = QMenu()
self.setAction = QAction(u"设置", self, triggered = self.showMainDlg)
self.helpAction = QAction(u"帮助", self, triggered=self.showHelp)
self.quitAction = QAction(u"退出", self, triggered=self.exitApp)
self.icon = QIcon('./icon/alarm.png')
def setMenu(self):
self.menu.addAction(self.setAction)
self.menu.addAction(self.helpAction)
self.menu.addAction(self.quitAction)
self.setIcon(self.icon)
self.setContextMenu(self.menu)
def iconClicked(self, reason):
if reason==2 or reason==3:
pw = self.parent()
if pw==None:
return
if pw.isVisible():
pw.hide()
else:
pw.show()
def showMainDlg(self):
pw = self.parent()
if pw==None:
return
if not pw.isVisible():
pw.show()
def exitApp(self):
self.setVisible(False)
sys.exit()
def showHelp(self):
try:
win32api.ShellExecute(0, 'open',
os.getcwd() + '/doc/readme.htm',
'', '', 1)
except:
log(u"找不到文件 " + os.getcwd() + '\\doc\\readme.htm', "error")
if __name__ == "__main__":
app = QApplication(sys.argv)
ti = SysTray()
ti.show()
ti.showMessage(u"提示", u"程序启动", 2)
sys.exit(app.exec_())
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。