黑松山资源网 Design By www.paidiu.com
用Python + PyQT写的一个系统桌面时钟,刚学习Python,写的比较简陋,但是基本的功能还可以。
功能:
①窗体在应用程序最上层,不用但是打开其他应用后看不到时间
②左键双击全屏,可以做小屏保使用,再次双击退出全屏。
③系统托盘图标,主要参考PyQt4源码目录中的PyQt4\examples\desktop\systray下的程序
④鼠标右键,将程序最小化
使用时需要heart.svg放在源代码同级目录下,[文件可在PyQt4示例代码目录下PyQt4\examples\desktop\systray\images找到
运行需要Python2.7 + PyQt4.
__metaclass__ = type #!coding= utf-8 #http://blog.csdn.net/gatieme/article/details/17659259 #gatieme import sys from PyQt4.QtCore import * from PyQt4.QtGui import * #-------------------------------------------------------------------------------- class SystemTrayIcon(QSystemTrayIcon): """ The systemTrayIcon which uesd to connect the clock """ #---------------------------------------------------------------------------- def __init__(self, mainWindow, parent = None): """ mainWindow : the main window that the system tray icon serves to """ super(SystemTrayIcon, self).__init__(parent) self.window = mainWindow self.setIcon(QIcon("heart.svg")) # set the icon of the systemTrayIcon self.createActions( ) self.createTrayMenu( ) self.connect(self, SIGNAL("doubleClicked"), self.window, SLOT("showNormal")) #self.connect(self, SIGNAL("activated( )"), self, SLOT("slot_iconActivated")) def createActions(self): """ create some action to Max Min Normal show the window """ self.minimizeAction = QAction("Mi&nimize", self.window, triggered = self.window.hide) self.maximizeAction = QAction("Ma&ximize", self.window, triggered = self.window.showMaximized) self.restoreAction = QAction("&Restore", self.window, triggered = self.window.showNormal) self.quitAction = QAction("&Quit", self.window, triggered = qApp.quit) def createTrayMenu(self): self.trayIconMenu = QMenu(self.window) self.trayIconMenu.addAction(self.minimizeAction) self.trayIconMenu.addAction(self.maximizeAction) self.trayIconMenu.addAction(self.restoreAction) self.trayIconMenu.addSeparator( ) self.trayIconMenu.addAction(self.quitAction) self.setContextMenu(self.trayIconMenu) def setVisible(self, visible): self.minimizeAction.setEnabled(not visible) self.maximizeAction.setEnabled(not self.window.isMaximized()) self.restoreAction.setEnabled(self.window.isMaximized() or not visible) super(Window, self).setVisible(visible) def closeEvent(self, event): #if event.button( ) == Qt.RightButton: self.showMessage("Message", "The program will keep running in the system tray. To " "terminate the program, choose <b>Quit</b> in the " "context menu of the system tray entry.", QSystemTrayIcon.Information, 5000) self.window.hide( ) event.ignore( ) def slot_iconActivated(self, reason): if reason == QSystemTrayIcon.DoubleClick: self.wiondow.showNormal( ) #-------------------------------------------------------------------------------- class DigitClock(QLCDNumber): """ the DigitClock show a digit clock int the printer """ #---------------------------------------------------------------------------- def __init__(self, parent = None): """ the constructor function of the DigitClock """ super(DigitClock, self).__init__(parent) pale = self.palette( ) pale.setColor(QPalette.Window, QColor(100, 180, 100)) self.setPalette(pale) self.setNumDigits(19) self.systemTrayIcon = SystemTrayIcon(mainWindow = self) self.dragPosition = None; self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Popup | Qt.Tool) self.setWindowOpacity(1) self.showTime( ) # print the time when the clock show self.systemTrayIcon.show( ) # show the SystemTaryIcon when the clock show self.timer = QTimer( ) self.connect(self.timer, SIGNAL("timeout( )"), self.showTime) self.timer.start(1000) self.resize(500, 60) #---------------------------------------------------------------------------- def showTime(self): """ show the current time """ self.date = QDate.currentDate( ) self.time = QTime.currentTime( ) text = self.date.toString("yyyy-MM-dd") + " " + self.time.toString("hh:mm:ss") self.display(text) #---------------------------------------------------------------------------- def mousePressEvent(self, event): """ clicked the left mouse to move the clock clicked the right mouse to hide the clock """ if event.button( ) == Qt.LeftButton: self.dragPosition = event.globalPos( ) - self.frameGeometry( ).topLeft( ) event.accept( ) elif event.button( ) == Qt.RightButton: self.systemTrayIcon.closeEvent(event) #self.systemTrayIcon.hide( ) #self.close( ) def mouseMoveEvent(self, event): """ """ if event.buttons( ) & Qt.LeftButton: self.move(event.globalPos( ) - self.dragPosition) event.accept( ) def keyPressEvent(self, event): """ you can enter "ESC" to normal show the window, when the clock is Maxmize """ if event.key() == Qt.Key_Escape and self.isMaximized( ): self.showNormal( ) def mouseDoubleClickEvent(self, event): """ """ if event.buttons() == Qt.LeftButton: if self.isMaximized( ): self.showNormal( ) else: self.showMaximized( ) if __name__ == "__main__": app = QApplication(sys.argv) digitClock = DigitClock( ) digitClock.show( ) sys.exit(app.exec_( ))
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年10月08日
2024年10月08日
- 《丁当 20首重量级歌曲 Fu Good 下一站天后 2CD》[WAV/分轨][650MB]
- 歌莉雅.2012-My.Voice.Story【环星】【FLAC分轨】
- 群星.1993-一曲成名·青春无悔【飞碟】【WAV+CUE】
- 刘德华.2000-爱无知(金装版)【NEWMELODY】【WAV+CUE】
- 许巍《时光漫步》1CD[FLAC/分轨][804.3MB]
- 群星《2024第一季度百度歌曲排行抖音榜top100》1CD[FLAC/分轨][2.3GB]
- 张柏芝《全新经验》[FLAC/分轨][450MB]
- 唐朝.2008-浪漫骑士【音乐家】【WAV+CUE】
- 张芸京.2016-失败的高歌【泡耳音乐】【WAV+CUE】
- 群星.1991-音乐工厂1·皇后大道东【音乐工厂】【WAV+CUE】
- 群星.1992-音乐工厂2·首都【音乐工厂】【WAV+CUE】
- 群星.1994-音乐工厂3·儿童乐园【音乐工厂】【WAV+CUE】
- 胡鸿钧.2021-ex:CHANGE【星梦娱乐】【WAV+CUE】
- 班得瑞原装进口《第一张新世纪专辑:仙境》1CD[APE/CUE分轨][292.3MB]
- 伍佰《摇滚教父 伍佰黄金精选 2CD》[WAV+CUE][990MB]