-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathagenda-timer.py
116 lines (95 loc) · 4.38 KB
/
agenda-timer.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python
from tkinter import *
from tkinter import ttk
from tkinter import font
import datetime
import json
import os
# ############################################################################
# Configuration Options
timeremaining_warning=240 # When there is only x seconds left change the text to orange to warn the speaker
timeremaining_critical=180 # When there is only x seconds left change the text to red to warn the speaker
fullscreen=False
color_bg="#282c34"
color_mute="#abb2bf"
color_green="#8dc270"
color_highlights="#ffffff"
# You should not need to change anything below
# ############################################################################
def quit(*args):
root.destroy()
def update_agenda():
# Get the time remaining until the event
now = datetime.datetime.now()
realTime.set(now.strftime('%H:%M'))
json_file = open('agenda.json')
json_str = json_file.read()
data = json.loads(json_str)
# Count the number of agenda items in the Json file
numOfSessions=len(data)
# We need to loop through all the sessions and stop at the current session to get the details of that agenda item
for i in range(numOfSessions):
if datetime.datetime.now() < datetime.datetime.strptime(data[i]['endtime'], '%Y%m%d%H%M%S' ):
currSession = i
sessionTitle.set(data[i]['title'])
currentSpeaker.set(data[i]['speaker'])
break
endtime = datetime.datetime.strptime(data[currSession]['endtime'], '%Y%m%d%H%M%S')
remainder = datetime.datetime.strptime(data[currSession]['endtime'], '%Y%m%d%H%M%S') - now
# remove the microseconds part
remainder = remainder - datetime.timedelta(microseconds=remainder.microseconds)
# Set the countdown colour based on the remaining amount of time
if (datetime.datetime.now() > (endtime - datetime.timedelta(seconds=timeremaining_warning) ) ):
lblCountdownTime.configure(foreground='orange')
elif (datetime.datetime.now() > (endtime - datetime.timedelta(seconds=timeremaining_critical) ) ):
lblCountdownTime.configure(foreground='red')
else:
lblCountdownTime.configure(foreground=color_green)
# Set the text on the Tk Label for Countdown
remainingTime.set(str(remainder))
# Trigger the countdown after 1000ms
root.after(1000, update_agenda)
# Use Tkinter to create the app window
root = Tk()
imgicon = PhotoImage(file=os.path.join(os.path.dirname(os.path.realpath(__file__)),'icon.gif'))
root.tk.call('wm', 'iconphoto', root._w, imgicon)
if (fullscreen):
root.attributes("-fullscreen", True)
else:
root.geometry("1024x800")
root.title("Agenda Countdown")
root.configure(background=color_bg)
root.bind("<Escape>", quit)
root.bind("x", quit)
style = ttk.Style()
style.theme_use('classic') # to fix bug on Mac OSX
style.configure("Red.TLabel", fg='red')
# Set the end date and time for the countdown
fntNormal = font.Font(family='Helvetica', size=60, weight='bold')
fntForCountdown = font.Font(family='Helvetica', size=80, weight='bold')
fntForTitle = font.Font(family='Helvetica', size=40, weight='bold')
fntSmall = font.Font(family='Helvetica', size=20, weight='bold')
# Create some Tkinter variables
remainingTime = StringVar()
sessionTitle = StringVar()
realTime = StringVar()
currentSpeaker = StringVar()
numOfSessions = IntVar()
currSession = IntVar()
i = IntVar()
txtTimeRemaining = StringVar()
# Add Tkinter Labels to hold the text elements
lblRealTime = ttk.Label(root, textvariable=realTime, font=fntNormal, foreground=color_mute, background=color_bg)
lblRealTime.place(relx=0.9, rely=0.1, anchor=CENTER)
lblTimeRemaining = ttk.Label(root, textvariable=txtTimeRemaining, font=fntSmall, foreground=color_mute, background=color_bg)
lblTimeRemaining.place(relx=0.5, rely=0.45, anchor=CENTER)
txtTimeRemaining.set('Time Remaining: ')
lblTitle = ttk.Label(root, textvariable=sessionTitle, font=fntForTitle, foreground=color_highlights, background=color_bg)
lblTitle.place(relx=0.5, rely=0.2, anchor=CENTER)
lblSpeaker = ttk.Label(root, textvariable=currentSpeaker, font=fntForTitle, foreground=color_highlights, background=color_bg)
lblSpeaker.place(relx=0.5, rely=0.3, anchor=CENTER)
lblCountdownTime = ttk.Label(root, textvariable=remainingTime, font=fntForCountdown, foreground=color_green, background=color_bg)
lblCountdownTime.place(relx=0.5, rely=0.6, anchor=CENTER)
# Run the update_agenda
root.after(1000, update_agenda)
root.mainloop()