diff options
Diffstat (limited to 'las.py')
-rw-r--r-- | las.py | 258 |
1 files changed, 127 insertions, 131 deletions
@@ -5,159 +5,155 @@ import dbus import random import time import csnd -from dict import dict -from dict import word +from dict import Dict +from dict import Word # My class for key detection class _Getch: - """Gets a single character from standard input. Does not echo to the screen.""" - def __init__(self): - try: - self.impl = _GetchWindows() - except ImportError: - self.impl = _GetchUnix() + """Gets a single character from standard input. Does not echo to the screen.""" + def __init__(self): + try: + self.impl = _GetchWindows() + except ImportError: + self.impl = _GetchUnix() - def __call__(self): return self.impl() + def __call__(self): return self.impl() class _GetchUnix: - def __init__(self): - import tty, sys - - def __call__(self): - import sys, tty, termios - fd = sys.stdin.fileno() - old_settings = termios.tcgetattr(fd) - try: - tty.setraw(sys.stdin.fileno()) - ch = sys.stdin.read(1) - finally: - termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) - return ch + def __init__(self): + import tty, sys + + def __call__(self): + import sys, tty, termios + fd = sys.stdin.fileno() + old_settings = termios.tcgetattr(fd) + try: + tty.setraw(sys.stdin.fileno()) + ch = sys.stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) + return ch class _GetchWindows: - def __init__(self): - import msvcrt + def __init__(self): + import msvcrt - def __call__(self): - import msvcrt - return msvcrt.getch() + def __call__(self): + import msvcrt + return msvcrt.getch() -class listenspell(): +class Listenspell(): - def __init__(self): + def __init__(self): - self.skill_level = 0 - self.level_threshold = 5 - self.points = 0 - self.words_played = 0 - self.words_correct = 0 - self.init = False - from dict import dict - from dict import word - self.dict_obj = dict() - self.word_obj = word() + self.skill_level = 0 + self.level_threshold = 5 + self.points = 0 + self.words_played = 0 + self.words_correct = 0 + self.init = False + self.dict_obj = Dict() + self.word_obj = Word() - def startspeechd(self): # Currently not in use have to manually start sugar-speechd - import os - pid = os.fork() - if pid: - return - else: - # we are the child - os.popen("./sugar-speechd") + def start_speechd(self): # Currently not in use have to manually start sugar-speechd + import os + pid = os.fork() + if pid: + return + else: + # we are the child + os.popen("./sugar-speechd") - def playsound(self,event): - if event == "begin": - os.popen("aplay --quiet begin.wav") - elif event == "correct": - os.popen("aplay --quiet correct.wav") - elif event == "incorrect": - os.popen("aplay --quiet incorrect.wav") + def play_sound(self,event): + if event == "begin": + os.popen("aplay --quiet begin.wav") + elif event == "correct": + os.popen("aplay --quiet correct.wav") + elif event == "incorrect": + os.popen("aplay --quiet incorrect.wav") - def setskill_level(self,level): - self.skill_level = level + def set_skill_level(self,level): + self.skill_level = level - def getskill_level(self): - return self.skill_level + def get_skill_level(self): + return self.skill_level - def getwords_played(self): - return self.words_played + def get_words_played(self): + return self.words_played - def getwords_correct(self): - return self.words_correct + def get_words_correct(self): + return self.words_correct - def getpoints(self): - return self.points + def get_points(self): + return self.points - def ans_correct(self, wordid): - self.playsound("correct") - self.points = self.points + self.skill_level - self.words_correct = self.words_correct + 1 + def ans_correct(self, wordid): + self.play_sound("correct") + self.points = self.points + self.skill_level + self.words_correct = self.words_correct + 1 - def ans_incorrect(self, wordid): - self.playsound("incorrect") - - def clearscreen(self,numlines=100): - """Clear the console. + def ans_incorrect(self, wordid): + self.play_sound("incorrect") + def clear_screen(self,numlines=100): + """Clear the console. numlines is an optional argument used only as a fall-back. """ - import os - if os.name == "posix": - # Unix/Linux/MacOS/BSD/etc - os.system('clear') - elif os.name in ("nt", "dos", "ce"): - # DOS/Windows - os.system('CLS') - else: - # Fallback for other operating systems. - print '\n' * numlines - - def load_wordid(self, num_words): - temp_list = [] - self.wordid_list = [] - temp_list = self.dict_obj.getrandomwordid(length = self.skill_level,numwords = num_words) - for(wordid, ) in temp_list: - self.wordid_list.append(wordid) - return self.wordid_list - - def getwordinfo(self,wordid, attribute): - if self.word_obj.getwordid() != wordid: - self.word_obj.__init__(identifier = "wordid", value= wordid) - print "Hello Again" - self.words_played = self.words_played + 1 - - if attribute == "def": - return self.word_obj.getdef() - elif attribute == "usage": - return self.word_obj.getusage() - elif attribute == "word": - return self.word_obj.getword() - elif attribute == "phnm": - return self.word_obj.getword() # For the time being - - else: return "Invalid attribute" - - - def saytext(self, text): - if self.init == False: - bus = dbus.SessionBus() - self.espeak_object = bus.get_object('org.laptop.Speech','/org/laptop/Speech') - self.init = True - text = str(text) - self.espeak_object.SayText(text) - - def getkey(self): - for longestinput in range(15): - inkey = _Getch() - import sys - for i in xrange(sys.maxint): - k=inkey() - if k<>'':break - elif k == '\r': break - return k - - def exitgame(self): - self.saytext("goodbye") - sys.exit() + import os + if os.name == "posix": + # Unix/Linux/MacOS/BSD/etc + os.system('clear') + elif os.name in ("nt", "dos", "ce"): + # DOS/Windows + os.system('CLS') + else: + # Fallback for other operating systems. + print '\n' * numlines + + def load_wordid(self, num_words): + temp_list = [] + self.wordid_list = [] + temp_list = self.dict_obj.get_random_wordid(length = self.skill_level,numwords = num_words) + for(wordid, ) in temp_list: + self.wordid_list.append(wordid) + return self.wordid_list + + def get_word_info(self,wordid, attribute): + if self.word_obj.get_wordid() != wordid: + self.word_obj.__init__(identifier = "wordid", value= wordid) + print "Hello Again" + self.words_played = self.words_played + 1 + + if attribute == "def": + return self.word_obj.get_def() + elif attribute == "usage": + return self.word_obj.get_usage() + elif attribute == "word": + return self.word_obj.get_word() + elif attribute == "phnm": + return self.word_obj.get_word() # For the time being + + else: return "Invalid attribute" + + def say_text(self, text): + if self.init == False: + bus = dbus.SessionBus() + self.espeak_object = bus.get_object('org.laptop.Speech','/org/laptop/Speech') + self.init = True + text = str(text) + self.espeak_object.SayText(text) + + def get_key(self): + for longestinput in range(15): + inkey = _Getch() + import sys + for i in xrange(sys.maxint): + k=inkey() + if k<>'':break + elif k == '\r': break + return k + + def exit_game(self): + self.say_text("goodbye") + sys.exit()
\ No newline at end of file |