#!/usr/bin/python

# QStopWatch -- a very simple stop watch

# Copyright (C) 2006 Dominic Battre <dominic {at} battre {dot} de>

# Copyright (C) 2013 ActivityWorkshop.net

#

# This program is free software; you can redistribute it and/or

# modify it under the terms of the GNU Library General Public

# License as published by the Free Software Foundation; either

# version 2 of the License, or (at your option) any later version.

#

# This program is distributed in the hope that it will be useful,

# but WITHOUT ANY WARRANTY; without even the implied warranty of

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU

# Library General Public License for more details.

#

# You should have received a copy of the GNU Library General Public

# License along with this program; if not, write to the Free

# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

# Versions:

# 2006-11-18  version 1.0   - simple but fully functional stop watch

# 2006-11-18  version 1.0.1 - fixed problem with QString vs. Python string

# Obtained from http://kde-apps.org/content/show.php/QStopWatch?content=48810

# 2013-06-19  version 1.1   - ported to python 2.7, qt4; used QLCDNumber for time display

import sys

from PyQt4 import QtGui, QtCore

class MainWindow(QtGui.QMainWindow):

DEFAULT_WINDOW_TITLE = "Stopwatch"

def __init__(self, *args):

apply(QtGui.QMainWindow.__init__, (self,) + args)

self.mainWidget = QtGui.QWidget(self);

self.setCentralWidget(self.mainWidget);

self.mainLayout = QtGui.QVBoxLayout(self.mainWidget)

self.buttonsWidget = QtGui.QWidget(self.mainWidget);

self.buttonsLayout = QtGui.QHBoxLayout(self.buttonsWidget)

self.txTime  = QtGui.QLCDNumber(self.mainWidget);

self.txTime.setSegmentStyle(QtGui.QLCDNumber.Flat);

self.bnStart = QtGui.QPushButton("&Start", self.buttonsWidget);

self.bnClear = QtGui.QPushButton("&Clear", self.buttonsWidget);

self.connect(self.bnStart, QtCore.SIGNAL("clicked()"), self.slotBnStartClicked)

self.connect(self.bnClear, QtCore.SIGNAL("clicked()"), self.slotBnClearClicked)

self.buttonsLayout.addWidget(self.bnStart);

self.buttonsLayout.addWidget(self.bnClear);

self.mainLayout.addWidget(self.txTime);

self.mainLayout.addWidget(self.buttonsWidget);

self.counting = False;

self.msInLastLaps = 0;

self.timer = QtCore.QTimer(self);

self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.slotTimerEvent);

self.displayTime(0, False)

self.setWindowTitle(self.DEFAULT_WINDOW_TITLE)

# reduce to minimum size

self.resize(self.minimumSizeHint())

def displayTime(self, msecs, exact):

ms = msecs % 1000

msecs /= 1000

sec = msecs % 60

msecs /= 60

min = msecs % 60

msecs /= 60

hours = msecs

if exact:

timestring = '%02d:%02d:%02d.%03d' % (hours, min, sec, ms)

self.txTime.setNumDigits(12 if hours > 0 else 9)

self.txTime.display(timestring)

self.setWindowTitle(self.DEFAULT_WINDOW_TITLE)

else:

timestring = '%02d:%02d:%02d' % (hours, min, sec)

self.txTime.setNumDigits(8 if hours > 0 else 5)

self.txTime.display(timestring)

self.setWindowTitle(timestring)

def slotBnStartClicked(self):

if ( self.counting ) :

print "stop  ", str(QtCore.QTime.currentTime().toString())

self.timer.stop();

self.msInLastLaps += self.startTime.msecsTo(QtCore.QTime.currentTime());

self.displayTime(self.msInLastLaps, True)

self.bnStart.setText("&Start")

else:

self.startTime = QtCore.QTime.currentTime()

print "start ", str(self.startTime.toString())

self.timer.start(500)

self.bnStart.setText("&Stop")

self.slotTimerEvent()

self.counting = not self.counting

def slotBnClearClicked(self):

print "clear";

self.msInLastLaps = 0;

self.startTime = QtCore.QTime.currentTime()

self.displayTime(0, not self.counting)

def slotTimerEvent(self):

self.displayTime(self.msInLastLaps + self.startTime.msecsTo(QtCore.QTime.currentTime()), False)

# Main method as the program entry point

def main(args):

app = QtGui.QApplication(args)

win = MainWindow()

win.show()

app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))

app.exec_()

if __name__=="__main__":

main(sys.argv)

python lcd 时间显示的更多相关文章

  1. python中时间格式

    问题:通过MySQLdb查询datetime字段,然后通过浏览器显示出来,得到的格式是:         'Thu, 19 Feb 2009 16:00:07 GMT'   (http呈现出来的格式) ...

  2. python datetime 时间日期处理小结

    python datetime 时间日期处理小结 转载请注明出处:http://hi.baidu.com/leejun_2005/blog/item/47f340f1a85b5cb3a50f5232. ...

  3. python 的时间与日期

    显示当前日期: import time print time.strftime('%Y-%m-%d %A %X %Z',time.localtime(time.time())) 或者 你也可以用: p ...

  4. python(时间模块,序列化模块等)

    一.time模块 表示时间的三种方式: 时间戳:数字(计算机能认识的) 时间字符串:t='2012-12-12' 结构化时间:time.struct_time(tm_year=2017, tm_mon ...

  5. Python之时间表示

    Python的time模块中提供了丰富的关于时间操作方法,可以利用这些方法来完成这个需求. time.time() :获取当前时间戳 time.ctime(): 当前时间的字符串形式 time.loc ...

  6. 1、Python 日期时间格式化输出

    今天帮朋友写自动化脚本,又需要用格式化日期,又忘记怎么写了,还是写到自己博客里面,方便日后需要的时候看一眼吧.So,临时加一篇 Python 的文章. 1.Python的time模块 import t ...

  7. 【STM32H7教程】第51章 STM32H7的LTDC应用之LCD汉字显示和2D图形显示

    完整教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=86980 第51章       STM32H7的LTDC应用之LCD汉字 ...

  8. 痞子衡嵌入式:记录i.MXRT1060驱动LCD屏显示横向渐变色有亮点问题解决全过程(提问篇)

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家分享的是i.MXRT1060上LCD横向渐变色显示出亮点问题的分析解决经验. 痞子衡前段时间在支持一个i.MXRT1060客户项目时遇到了LCD ...

  9. js获取当前时间显示在页面上

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

随机推荐

  1. 【iOS基础】iOS 网络请求

    一.一个HTTP请求的基本要素1.请求URL:客户端通过哪个路径找到服务器 2.请求参数:客户端发送给服务器的数据* 比如登录时需要发送的用户名和密码 3.返回结果:服务器返回给客户端的数据* 一般是 ...

  2. Using HttpClient properly to avoid CLOSE_WAIT TCP connections

    Apache的HttpComponent组件,用的人不在少数.但是能用好的人,却微乎其微,为什么?很简单,TCP里面的细节实现不是每个人都能捕获到的(细节是魔鬼),像并发请求控制&资源释放,N ...

  3. java总结文章

    java总结文章 原创地址: http://www.cnblogs.com/Alandre/ (泥沙砖瓦浆木匠),须要转载的,保留下! Thanks Talk is cheap. Show me th ...

  4. LOADRUNNER8.1卸载

    卸载LOADRUNNER8.1后,不能正常又一次安装的问题. Loadrunner 8.1 安装1.下载Loadrunner8.1 (官方英文版) 2.安装Loadrunner8.1 3.破解:htt ...

  5. Verilog之i2c合约

    说明:i2c乔布斯.有这么多的事情在网上参考. 时刻:2014年5一个月6周二星期 1.问题叙述性说明: 正如图.已知的时钟clk为100k,rst为复位信号.上升沿有效,基于Verilog HDL或 ...

  6. jQuery mouseover,mouseout事件多次执行的问题处理

    控制鼠标移上移下事件,在使用Jquery 的mouseover,mouseout事件时,元素内部含有其它元素,会造成该事件多次的触发的情况. 问题解析 在用到mouseover和mouseout事件来 ...

  7. NumberSpinner( 数字微调) 组件

    本节课重点了解 EasyUI 中 Spinner(微调)组件的使用方法,这个组件依赖于Numberbox(数值输入框)和 Spinner(微调)组件. 一. 加载方式//class 加载方式<i ...

  8. 使用VS Code调试TypeScript游戏程序JsTankGame成功!!!

    TypeScript游戏程序JsTankGame不是本人写的,是从CSDN下载的. JsTankGame是用Visual Studio开发的,因此在Visual Studio下调试非常顺畅.本人尝试用 ...

  9. Xcode简易基础篇,以新手角度去操作

    声明:此Newlife XCode非Mac的XCode,避免误会. 日常用的Newlife X组件的相关资源,不限于XCode,只是以XCode组件为主: 1.QQ群:1600800 2.博客 : h ...

  10. ICP编程软件配置(烧写KEIL编译后的bin文件)

    1. 安装NuMicro_ICP_Programming_Tool_1.29.6425软件 2. 打开软件后选择目标芯片后点击“连接”按钮 3. 添加程序 4. 点击设定按钮进行设定 5. 点击开始 ...