From 4992eb6bb9a110636cdc147fba7e2208f1e7cb9d Mon Sep 17 00:00:00 2001 From: atharvavyas139 Date: Thu, 23 Feb 2017 23:23:16 +0530 Subject: [PATCH] raw typeracer --- TypeRacer/test.txt | 1 + TypeRacer/typeracer.py | 73 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 TypeRacer/test.txt create mode 100644 TypeRacer/typeracer.py diff --git a/TypeRacer/test.txt b/TypeRacer/test.txt new file mode 100644 index 0000000..1650efd --- /dev/null +++ b/TypeRacer/test.txt @@ -0,0 +1 @@ +"you get plant leaves, wrap them in paper, light it on fire and suck on it" which is normally a sentence-but not today because I'm setting out on the quest for a long sentence-that I'm typing up which reminds me of a story my grandpa told me about himself when he was "your age"-about how they covered the letters of the type writers and they had to type so-that they could memorize where the letters are on a type writer and my-grandpa says-he will never regret taking that class because it helped him out a lot when-it came to typing and now a days he is not bad a typing at all because He is almost-as fast as me because I am a pretty fast typer and writing this article isn't-taking very long and expect being pretty far pretty soon at-the pace I'm going right now so there are going to-be some serious records getting busted when I'm finally finished writing this article on-this dumb website which will probably end up huffing this article even though-it is fun-packed and joyful and keeps the reader reading when they use that excuse-mom saying "just one more sentence" but that sentence is 10,000 words long and still continuing to go at a reasonable pace \ No newline at end of file diff --git a/TypeRacer/typeracer.py b/TypeRacer/typeracer.py new file mode 100644 index 0000000..94e63a8 --- /dev/null +++ b/TypeRacer/typeracer.py @@ -0,0 +1,73 @@ +import sys +from PyQt4.QtGui import * +from PyQt4.QtCore import * +from random import randint +import time +from io import * +def required_string(): + f=open("test.txt","r+") + s=f.read() + l=[] + l=s.split("-") + x=randint(0,len(l)-1) + return l[x] +class Window(QWidget): + def __init__(self,parent=None): + QWidget.__init__(self,parent) + self.lt=QGridLayout() + self.l1=QLabel("") + self.pallet=QPalette() + self.s=required_string() + self.l1list=[] + self.l1list=self.s.split() + self.l1.setText(self.s) + self.inp=QLineEdit("") + self.countw=0 + self.countcw=0 + self.start=time.time() + self.pallet.setColor(QPalette.Foreground,Qt.green) + self.l1.setPalette(self.pallet) + self.inp.textChanged.connect(self.textchanged) + self.b1=QPushButton("Change paragraph") + self.b1.clicked.connect(self.pressed) + self.l2=QLabel("WPM:") + self.op=QLineEdit("") + self.lt.addWidget(self.l1,1,1,4,4) + self.lt.addWidget(self.inp,5,1,4,4) + self.lt.addWidget(self.l2,9,1,1,1) + self.lt.addWidget(self.op,9,2,1,1) + self.lt.addWidget(self.b1,9,4,1,1) + self.setLayout(self.lt) + def textchanged(self): + self.t=self.inp.text() + self.diff=(time.time()-self.start) + print(self.l1list[self.countw]) + print(self.t) + if(self.t==self.l1list[self.countw]): + self.optextchange(1) + elif len(self.t)>1: + self.a=len(self.t) + if self.t[len(self.t)-1]=='\n' or self.t[len(self.t)-1]==' ': + self.countw=self.countw+1 + self.inp.setText("") + self.optextchange(0) + def optextchange(self,a): + if a==1: + self.countcw=self.countcw+1 + self.op.setText(str(self.countcw*60/self.diff)) + def pressed(self): + self.s=required_string() + self.l1list=[] + self.l1list=self.s.split() + self.l1.setText(self.s) + self.start=time.time() + self.countcw=0 + self.countw=0 +def perform(): + app=QApplication(sys.argv) + window=Window() + window.show() + sys.exit(app.exec()) +if __name__=="__main__": + perform() + \ No newline at end of file