forked from diegomtzg/MirrorX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeManager.py
86 lines (69 loc) · 2.76 KB
/
timeManager.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import time
import smartMirrorManager
from PyQt5.QtWidgets import QWidget, QLabel, QVBoxLayout
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class DateAndTime(QWidget):
global ticker
def __init__(self):
super(DateAndTime, self).__init__()
self.initUI()
def initUI(self):
font1 = QFont('Helvetica', smartMirrorManager.large_fontsize)
font2 = QFont('Helvetica', 60)
self.vbox = QVBoxLayout()
self.time = ''
self.timeLabel = QLabel()
self.vbox.setAlignment(Qt.AlignRight)
self.timeLabel.setAlignment(Qt.AlignRight)
self.timeLabel.setFont(font2)
self.timeLabel.setText("<font color='white'>temp time</font>")
self.weekday = ''
self.weekdayLabel = QLabel()
self.weekdayLabel.setFont(font1)
self.weekdayLabel.setAlignment(Qt.AlignRight)
self.date = ''
self.dateLabel = QLabel()
self.dateLabel.setAlignment(Qt.AlignRight)
self.dateLabel.setFont(font1)
self.vbox.addWidget(self.timeLabel)
self.vbox.addWidget(self.weekdayLabel)
self.vbox.addWidget(self.dateLabel)
self.vbox.addStretch(2)
self.setContentsMargins(0,0,0,0)
self.setLayout(self.vbox)
self.updateTime()
def updateTime(self):
global ticker
timer = QTimer(self) # Timer class updates things every once in a while
timer.timeout.connect(self.tick) # Connect timer to ticking method
timer.start(1000) # Call every second
ticker = False
def tick(self):
global ticker
# Make ticker flash in clock
if(ticker):
newTime = time.strftime("%I:%M %p") # ex. hour: 2:45 PM
newTime = newTime.lstrip('0') # Remove leading zero from time
ticker = False
else:
newTime = time.strftime("%I %M %p") # ex. hour: 2:45 PM
newTime = newTime.lstrip('0') # Remove leading zero from time
ticker = True
newDayOfWeek = time.strftime("%A")
tempMonth = time.strftime("%b")
tempDate = time.strftime("%d").lstrip('0') # Remove leading zero from date
tempYear = time.strftime("%Y")
newDate = tempMonth + " " + tempDate + ", " + tempYear
if newTime != self.time:
temp = "<font color='white'>" + newTime + "</font>"
self.time = newTime
self.timeLabel.setText(temp)
if newDayOfWeek != self.weekday:
temp = "<font color='white'>" + newDayOfWeek + "</font>"
self.weekday = newDayOfWeek
self.weekdayLabel.setText(temp)
if newDate != self.date:
temp = "<font color='white'>" + newDate + "</font>"
self.date = newDate
self.dateLabel.setText(temp)