Skip to content

Instantly share code, notes, and snippets.

@secretsquirrel
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save secretsquirrel/9221125 to your computer and use it in GitHub Desktop.
Save secretsquirrel/9221125 to your computer and use it in GitHub Desktop.
Injecty | Speed Reading
import random
import time
import wx
import sys
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
if len(sys.argv) < 3:
print "Usage:", sys.argv[0], "textFile", "WPM", "StartingPoint"
sys.exit()
if len(sys.argv) < 4:
startingPoint = 0
else:
startingPoint = int(sys.argv[3])
with open(sys.argv[1]) as f:
self.words = [word for line in f for word in line.split()]
self.myLog = open("log."+sys.argv[1], 'a+')
self.myLog.write("Opening Log\n")
self.font = wx.Font(16, wx.DEFAULT, wx.NORMAL, wx.NORMAL )
#
self.count = startingPoint
#self.timer.Start(1000/(int(sys.argv[2])/60))
self.toggleBtn = wx.Button(self, label="Start", size=(50,50))
self.toggleBtn.SetFont(wx.Font(6, wx.DEFAULT, wx.NORMAL, wx.NORMAL ))
self.toggleBtn.Bind(wx.EVT_BUTTON, self.onToggle)
self.injectyText = wx.StaticText(self, -1, "", (120, 10))
self.injectyText.SetFont(self.font)
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.update, self.timer)
#----------------------------------------------------------------------
def update(self, event):
""""""
self.timer.Stop()
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.update, self.timer)
self.timer.Start(1000/(int(sys.argv[2])/60))
pause = wx.Timer(self)
self.injectyText.SetLabel(" ")
word = self.words[self.count]
self.injectyText = wx.StaticText(self, -1, word, (120-len(word)*2, 10))
self.injectyText.SetFont(self.font)
if any(punct in word for punct in '\",.!?;:-'):
self.timer.Stop()
self.timer = wx.Timer(self)
self.Bind(wx.EVT_TIMER, self.update, self.timer)
self.timer.Start(1000/(int(sys.argv[2])/60)*1.6)
self.count += 1
if self.count % 250 == 0:
msg = "You are " + str(self.count) + " words into " + sys.argv[1] + "\n"
print msg
self.myLog.write(msg)
def onToggle(self, event):
btnLabel = self.toggleBtn.GetLabel()
if btnLabel == "Start":
#print "starting timer..."
self.timer.Start(1000/(int(sys.argv[2])/60))
self.toggleBtn.SetLabel("Stop")
else:
self.timer.Stop()
self.toggleBtn.SetLabel("Start")
msg = "You are " + str(self.count) + " words into " + sys.argv[1] + "\n"
print msg
self.myLog.write(msg)
def pause(self):
pass
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, -1, "injecty", size=(300, 50))
panel = MyPanel(self)
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment