-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimelabel.py
executable file
·53 lines (43 loc) · 1.53 KB
/
timelabel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
import time, datetime, calendar
from PyQt4 import QtCore
#--------------temp measure-----------------------
class TimeThread(QtCore.QThread): # time label
def __init__(self, time_signal, parent=None):
super(TimeThread, self).__init__(parent)
self.time_signal = time_signal
self.isRun=False
def run(self):
while self.isRun:
s=time.localtime()
a = datetime.datetime.now()
if s.tm_min<10:
minutes='0'+str(s.tm_min)
else:
minutes=str(s.tm_min)
if s.tm_hour<10:
hours='0'+str(s.tm_hour)
else:
hours=str(s.tm_hour)
if s.tm_sec<10:
secundes='0'+str(s.tm_sec)
else:
secundes=str(s.tm_sec)
month=_fromUtf8(calendar.month_name[s.tm_mon])
day=str(s.tm_mday)
dayname=_fromUtf8(calendar.day_name[s.tm_wday])
out=['','','']
out[0]=day+', ' + month
out[1]='%s:%s:%s' % (hours,minutes,secundes)
out[2]=dayname
self.time_signal.emit(out)
sleepparam = float(str(datetime.datetime.now()-a)[-6:])/1000000
#print 1 - sleepparam
time.sleep(1 - sleepparam)
def stop(self):
self.isRun=False
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s