码迷,mamicode.com
首页 > 编程语言 > 详细

python之qt动态时间显示

时间:2014-12-10 22:42:01      阅读:439      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   color   os   sp   for   on   

# -*- coding: cp936 -*-

from PyQt4 import QtGui

from PyQt4 import QtCore

import sys,time,random,os,re

from PyQt4.QtGui import *

from PyQt4.QtCore import *

def Class_Import_Image(path):

        i=0#为什么函数名称是这样,因为Image它是一个类的对象,因为要导入所以写成这样

        #while 1:

        try:

             ls=os.listdir(path)

        #except:

             #print(‘access deny‘)

        except Exception, e:

                print(‘access deny‘)

                print e,ur‘文件路径不正确‘,ur‘您的文件路径呢?对不起找错地方了吧‘,ur‘这个地方都能被您找到,真。。。。。‘

        else:

            for l in ls:

                print‘第‘,i+1,‘次‘

                time.sleep(1)

                temp=os.path.join(path,l)

                print ur‘创建文件时间:‘,time.ctime((os.path.getatime(temp))),

                print ur‘创建文件夹时间为:‘, time.ctime(os.path.getctime(os.path.dirname(temp))),

                print len(temp),ur‘数量‘,sum(os.path.getsize(os.path.join(path,l)) for name in temp),ur‘字节数‘,

                if(os.path.isdir(temp)):

                        print(temp)

                        Class_Import_Image(temp)

                else:

                        print(temp)

                i+=1

                if i>4 :

                        #退出

                        sys.exit(0)

def a(path):

    while True:

        image=re.compile(‘(.jpg$|.gif$)‘)

        p=image.findall(path)

        if p:

            print p,‘您的图片格式找到了,它是以.jpg或.gif的扩展名‘

        else:

            print‘图片格式错误‘,‘你说的是什么格式呀?‘

            raise AttributeError

        if sys.argv>=0:

            sys.exit(0)

        else:

            continue

#退出的时间也需要知道下

def Path_time2():

    _time2=time.strftime(‘%Y年-%m月-%d日 %H:%M:%S‘,time.localtime(time.time()))

    print ‘本次退出时间为‘,_time2

#进入观看图片的时间和退出观看图片的时间

    

class DigiClock(QLCDNumber):

        def __init__(self,parent=None): 

                super(DigiClock,self).__init__(parent)

            

                p=self.palette() 

                p.setColor(QPalette.Window,Qt.red) 

                self.setPalette(p)

 

                #QtGui.QWidget.__init__(self, parent)

                self.setGeometry(600, 300, 500, 150)

                self.setWindowTitle(‘Python Pil‘)

                self.setToolTip(time.strftime(‘%Y-%m-%d %H:%M:%S‘,time.localtime(time.time())))

                time.sleep(1)

                #self.setToolTip(time.ctime(os.path.getctime(os.path.dirname(‘e:\\image\\‘))))

                self.setWindowIcon(QtGui.QIcon(‘e:\\image\\abc.jpg‘))

                QtGui.QToolTip.setFont(QtGui.QFont(‘OldEnglish‘, 10))

                

                self.setNumDigits(19)

                self.dragPosition=None

            

                self.setWindowFlags(Qt.FramelessWindowHint) 

                self.setWindowOpacity(0.5)

 

                

                timer=QTimer(self) 

                self.connect(timer,SIGNAL("timeout()"),self.showTime) 

                timer.start(1000)

                

                self.showTime()         

                self.resize(400,100)

        def closeEvent(self, event):

                reply = QtGui.QMessageBox.question(self, ‘Message‘,

                "Are you sure to quit?", QtGui.QMessageBox.Yes,

                QtGui.QMessageBox.No)

                if reply == QtGui.QMessageBox.Yes:

                        event.accept()

                else:

                        event.ignore()

 

                

 

                self.setWindowTitle(‘grid layout‘)

                names = [‘Cls‘, ‘Bck‘, ‘‘, ‘Close‘, ‘7‘, ‘8‘, ‘9‘, ‘/‘,

                ‘4‘, ‘5‘, ‘6‘, ‘*‘, ‘1‘, ‘2‘, ‘3‘,

                ‘-‘, ‘0‘, ‘.‘, ‘=‘, ‘+‘]

                18

                grid = QtGui.QGridLayout()

                j = 0

                pos = [(0, 0), (0, 1), (0, 2), (0, 3),

                (1, 0), (1, 1), (1, 2), (1, 3),

                (2, 0), (2, 1), (2, 2), (2, 3),

                (3, 0), (3, 1), (3, 2), (3, 3),

                (4, 0), (4, 1), (4, 2), (4, 3)]

                for i in names:

                        button = QtGui.QPushButton(i)

                if j == 2:

                        grid.addWidget(QtGui.QLabel(‘‘), 0, 2)

                else:

                        grid.addWidget(button, pos[j][0], pos[j][1])

                        j = j + 1

                        self.setLayout(grid)

                self.setWindowTitle(‘signal & slot‘)

                lcd = QtGui.QLCDNumber(self)

                slider = QtGui.QSlider(QtCore.Qt.Horizontal, self)

                vbox = QtGui.QVBoxLayout()

                vbox.addWidget(lcd)

                vbox.addWidget(slider)

                self.setLayout(vbox)

                self.connect(slider, QtCore.SIGNAL(‘valueChanged(int)‘), lcd,

                QtCore.SLOT(‘display(int)‘))

                self.resize(200,10)

 

        def mousePressEvent(self,event): 

                if event.button()==Qt.LeftButton: 

                    self.dragPosition=event.globalPos()-self.frameGeometry().topLeft() 

                    event.accept() 

                if event.button()==Qt.RightButton: 

                    self.close() 

            

        def mouseMoveEvent(self,event): 

                if event.buttons() & Qt.LeftButton: 

                    self.move(event.globalPos()-self.dragPosition) 

                    event.accept() 

            

        def showTime(self): 

                time=QTime.currentTime()

                date=QDate.currentDate()

                text= date.toString("yyyy-MM-dd")+" "+time.toString("hh:mm:ss")     

                self.display(text)

                Class_Import_Image(‘e:\\image\\‘)

      

def Path_time3():

        try:

                Path_time1()

                time.sleep(random.randint(1,2))

        except Exception:

                app = QtGui.QApplication(sys.argv)

                form=DigiClock()

                form.show()

                app.exec_()

                sys.exit(app.exec_())

                if  a(‘e:\\image\\*.jp‘):

                    sys.exit(0)

                Path_time2()

Path_time3()

如图:bubuko.com,布布扣

python之qt动态时间显示

标签:blog   http   io   ar   color   os   sp   for   on   

原文地址:http://www.cnblogs.com/mhxy13867806343/p/4156289.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!