-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWPM.py
127 lines (108 loc) · 3.51 KB
/
WPM.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
117
118
119
120
121
122
123
124
125
126
127
"""Words per minute.
This program lets you display a paragraph, word by word; in full screen!
Version - 1.0.1
"""
import tkinter as tk
from sys import exit
class configuration:
def __init__(self):
self.FontSize = 0
self.WPS = 0
print("Words Per Minute! v1.0.1\n")
print(
"\nUse <Escape>, <F11> or <F1> to manipulate the window's fullscreen properties!\n\n"
)
self.FontSize, self.WPS = self.UserConfiguration()
try:
para = open("para.txt", "r")
if not para:
para.close()
raise FileNotFoundError
else:
choice = 0
choice = int(
input(
"\n0. Use existing para?\n1. Make new para? \nEnter choice (0 Default): "
))
if choice:
raise FileNotFoundError
else:
para.close()
except FileNotFoundError:
para = open("para.txt", "w")
print(
"Enter/Paste your content. To save it - <Ctrl + D + Enter> or <Ctrl + Z + Enter> ( Windows )."
)
while True:
try:
line = input()
except EOFError:
break
para.write(line)
para.close()
except ValueError:
para.close()
def UserConfiguration(self):
print("Configuration Menu:\n\n")
try:
self.FontSize = int(input("Enter Font size (100 default): "))
except ValueError:
self.FontSize = 100
try:
print(
"\nYou might be Familier with Words per minute.\nThis program internally uses Words per Second convention.\nPlease Divide WPM by 60 and enter the value here.\nDefault Value is 2 WPS, i.e. 120 WPM.\n"
)
self.WPS = float(
input(
"Enter Words per Second (Higher the number, faster the words display): "
))
except ValueError:
self.WPS = 2
return (self.FontSize, self.WPS)
def GetFontSize(self):
return int(self.FontSize)
def getWPS(self):
return float(self.WPS)
# This code snippet now flashes the words per minute.
cofg = configuration()
input(
"\n\nBefore proceeding, remember:\n - <Escape> will close the program\n - <F1> will force fully exit fullscreen\n - <F11> will toggle between fullscreen & windowed mode.\n\n**Keys will work after mouse click**\n\n\nPress enter to continue!"
)
para = open("para.txt", "r")
words = [str(x) for x in para.read().split()]
def Miliseconds_per_word():
return 1000 / cofg.getWPS()
MPW = Miliseconds_per_word()
root = tk.Tk()
root.attributes("-fullscreen", True)
root.bind(
"<F11>",
lambda event: root.attributes("-fullscreen", not root.attributes(
"-fullscreen")),
)
root.bind("<F1>", lambda event: root.attributes("-fullscreen", False))
root.bind("<Escape>", lambda event: exit())
w = tk.StringVar()
labelFlash = tk.Label(
root,
bg="Black",
width=root.winfo_screenwidth(),
height=root.winfo_screenheight(),
anchor="center",
text="Sample",
fg="White",
font="Times " + str(cofg.GetFontSize()),
textvariable=w,
)
labelFlash.pack()
indx = 0
def update():
global indx
if indx >= len(words):
indx = 0
w.set(words[indx])
labelFlash.config(text=words[indx])
indx += 1
root.after(int(MPW), update)
update()
root.mainloop()