def gamemenu(): # setting directory for stroing highscorelist / logfile #~ means home on linux . as first char will hide gamefolder = os.path.expanduser(os.path.join("~",".screensavertest")) gamefile = os.path.join(gamefolder, "highscorelist.txt") # do not name gamefile "file", that is a reserved word ! createGameDir(gamefolder) createGameFile(gamefile) # gamefile should now exist in gamefolder resolution = [640,480] fullscreen = False watched = 0 title = "please choose wisely:" buttons = ["watch screensaver", "change resolution", "toggle fullscreen", "view highscore","visit homepage", "quit"] #picture = None # gif file or make sure python-imaging-tk is installed correctly picture = "data/tux.gif" # ---- use pygame only to get a list of valid screen resolutions --- reslist = getPygameModes() # --- ask player name ---- playername = easygui.enterbox("What is you name?", "please enter you name and press ENTER or click ok", "Mister dunno") while True: #endless loop if fullscreen: msg2 = "fullscreen mode" else: msg2 = "window mode" msg = "Welcome at screensaver game menu.\nScreensaver will run with %ix%i resolution,\n%s" % (resolution[0], resolution[1], msg2) selection = easygui.buttonbox(msg, title, buttons, picture) if selection == "quit": easygui.msgbox("bye-bye", "such a sad decision...") break # leave loop elif selection == "visit homepage": print("i try to open the webbrowser, please wait a bit...") webbrowser.open_new_tab("http://www.thepythongamebook.com") elif selection == "toggle fullscreen": fullscreen = not fullscreen elif selection == "view highscore": text = readGameFile(gamefile) easygui.textbox("This is the Screensaver logfile", "displaying highscore", text) elif selection == "watch screensaver": watched += 1 # get return value from called pygame program (playtime) playtime = screensaver.screensaver(resolution, fullscreen) easygui.msgbox("You watched the scrensaver %i x using this game menu \nYour screen was saved for %.2f seconds" % (watched, playtime)) # writing highscore-list line = "date: %s player: %s playtime: %.2f seconds resolution: %ix%i fullscreen: %s \n" % (time.asctime(), playername, playtime, resolution[0], resolution[1], fullscreen) writeGameFile(gamefile, line) elif selection == "change resolution": answer = easygui.choicebox("Please select one of those screen resolutions", "x,y", reslist) # answer gives back a string like '(320, 200)' resolution = parse(answer) return
def gamemenu(): gamefolder = os.path.expanduser(os.path.join( "~", ".screensavertest")) # ~ means home on linux . as first char will hide gamefile = os.path.join( gamefolder, "highscorelist.txt" ) # do not call it "file", that is a reserved word ! if os.path.isdir(gamefolder): print "directory already exist" else: print "directory does not exist yet" try: os.mkdir(gamefolder) except: raise UserWarning, "error at creating directory %s" % gamefolder exit() if os.path.isfile(gamefile): print "highscore file aready exist" else: try: f = file(gamefile, "w") # open for writing f.write("--- screensaver logfile ---\n") f.close() except: raise UserWarning, "error while creating file %s" % gamefile exit() # gamefile should now exist in gamefolder resolution = [640, 480] fullscreen = False watched = 0 title = "please choose wisely:" buttons = [ "watch screensaver", "change resolution", "toggle fullscreen", "view highscore", "quit" ] #picture = None # gif file or make sure python-imaging-tk is installed correctly picture = "data/tux.gif" # ---- use pygame only to get a list of valid screen resolutions --- pygame.init() reslist = pygame.display.list_modes() pygame.quit() # ---- end of pygame ---------- # --- ask player name ---- playername = easygui.enterbox( "What is you name?", "please enter you name and press ENTER or click ok", "Mister dunno") while True: #endless loop if fullscreen: msg = "Welcome at screensaver game menu.\nScreensaver will run with %ix%i resolution,\nfullscreen mode" % ( resolution[0], resolution[1]) else: msg = "Welcome at screensaver game menu.\nScreensave will run with %ix%i resolution,\nwindow mode" % ( resolution[0], resolution[1]) selection = easygui.buttonbox(msg, title, buttons, picture) if selection == "quit": easygui.msgbox("bye-bye", "such a sad decision...") break # leave loop elif selection == "toggle fullscreen": fullscreen = not fullscreen elif selection == "view highscore": try: f = file(gamefile, "r") # read text = f.read() f.close() except: raise UserWarning, "Error while reading higscore file %s" % gamefile exit() easygui.textbox("This is the Screensaver logfile", "displaying highscore", text) elif selection == "watch screensaver": watched += 1 playtime = screensaver.screensaver(resolution, fullscreen) easygui.msgbox( "You watched the scrensaver %i x using this game menu \nYour screen was saved for %.2f seconds" % (watched, playtime)) # writing highscore-list try: f = file(gamefile, "a") # append f.write( "date: %s player: %s playtime: %.2f seconds resolution: %ix%i fullscreen: %s \n" % (time.asctime(), playername, playtime, resolution[0], resolution[1], fullscreen)) f.close() except: raise UserWarning, "Error while writing higscore file %s" % gamefile exit() elif selection == "change resolution": answer = easygui.choicebox( "Please select one of those screen resolutions", "x,y", reslist) # answer gives back a string like '(320, 200)' comma = answer.find(",") # position of the comma inside answer x = int(answer[1:comma]) y = int(answer[comma + 1:-1]) resolution = (x, y) return
def please_translate(self,french_word,mode=""): translation_in=easygui.enterbox(msg=french_word,title="Flash Card Recto") if translation_in==None or translation_in=="-q": return None substitution_list=[",","(",")"," ",";","ยจ"] correct_pattern_str=copy.copy(self.__content[french_word]["Definition/Translation/Association"]) for substitution in substitution_list: correct_pattern_str=correct_pattern_str.replace(substitution,".*") correct_pattern=re.compile(correct_pattern_str,re.IGNORECASE) if correct_pattern.search(translation_in) is not None: choices = ["Continue","Modify the word"] reply=easygui.buttonbox(msg="Good Answer",title="Good Answer",choices=choices) if reply=="Modify the word": self.modify_word(french_word) return None self.__content[french_word]["Group"]+=1 self.__content[french_word]["Last Interogation Date"]=datetime.datetime.now() self.__content[french_word]["Number of Days since the last interogation"]=0 value=copy.copy(self.__content[french_word]) self.__content[french_word]["Number of Days before the next interogation"]=fibonacci.fib(int(value["Group"])-int(value["Number of Days since the last interogation"])) self.save(self.__uploaded_dictionary_file_path) return 1 else: last_group=self.__content[french_word]["Group"] if self.__content[french_word]["Group"]==0: pass elif self.__content[french_word]["Group"]==1: self.__content[french_word]["Group"]=0 else: self.__content[french_word]["Group"]-=2 self.__content[french_word]["Last Interogation Date"]=datetime.datetime.now() self.save(self.__uploaded_dictionary_file_path) request_index=0 while correct_pattern.search(translation_in) is None: translation_in=easygui.enterbox( msg="Correct Anwswer for\n-->" +french_word+"\n is\n-->" +self.__content[french_word]["Definition/Translation/Association"]+ "\n------------------------------\nYour Anwswer was\n-->"+translation_in+ "\n------------------------------\nWrite the GOOD Answer or 'iwr' (I was right) or 'c' (continue)", title="Wrong Answer") request_index+=1 if translation_in==None or translation_in=="-q": return None if (translation_in=="I was right" or translation_in=="iwr") and request_index==1: self.__content[french_word]["Group"]==last_group+1 self.__content[french_word]["Last Interogation Date"]=datetime.datetime.now() self.__content[french_word]["Number of Days since the last interogation"]=0 value=copy.copy(self.__content[french_word]) self.__content[french_word]["Number of Days before the next interogation"]=fibonacci.fib(int(value["Group"])-int(value["Number of Days since the last interogation"])) self.save(self.__uploaded_dictionary_file_path) return 1 if translation_in=="c": translation_in=self.__content[french_word]["Definition/Translation/Association"] return 0 choices = ["Continue","Modify the word"] reply=easygui.buttonbox(msg="Good Answer",title="Flash Card Recto",choices=choices) if reply=="Modify the word": self.modify_word(french_word) return None return 0
def gamemenu(): gamefolder = os.path.expanduser(os.path.join("~",".screensavertest")) # ~ means home on linux . as first char will hide gamefile = os.path.join(gamefolder, "highscorelist.txt") # do not call it "file", that is a reserved word ! if os.path.isdir(gamefolder): print "directory already exist" else: print "directory does not exist yet" try: os.mkdir(gamefolder) except: raise UserWarning, "error at creating directory %s" % gamefolder exit() if os.path.isfile(gamefile): print "highscore file aready exist" else: try: f = file(gamefile, "w") # open for writing f.write("--- screensaver logfile ---\n") f.close() except: raise UserWarning, "error while creating file %s" % gamefile exit() # gamefile should now exist in gamefolder resolution = [640,480] fullscreen = False watched = 0 title = "please choose wisely:" buttons = ["watch screensaver", "change resolution", "toggle fullscreen", "view highscore", "quit"] #picture = None # gif file or make sure python-imaging-tk is installed correctly picture = "data/tux.gif" # ---- use pygame only to get a list of valid screen resolutions --- pygame.init() reslist = pygame.display.list_modes() pygame.quit() # ---- end of pygame ---------- # --- ask player name ---- playername = easygui.enterbox("What is you name?", "please enter you name and press ENTER or click ok", "Mister dunno") while True: #endless loop if fullscreen: msg = "Welcome at screensaver game menu.\nScreensaver will run with %ix%i resolution,\nfullscreen mode" % (resolution[0], resolution[1]) else: msg = "Welcome at screensaver game menu.\nScreensave will run with %ix%i resolution,\nwindow mode" % (resolution[0], resolution[1]) selection = easygui.buttonbox(msg, title, buttons, picture) if selection == "quit": easygui.msgbox("bye-bye", "such a sad decision...") break # leave loop elif selection == "toggle fullscreen": fullscreen = not fullscreen elif selection == "view highscore": try: f = file(gamefile, "r") # read text = f.read() f.close() except: raise UserWarning, "Error while reading higscore file %s" % gamefile exit() easygui.textbox("This is the Screensaver logfile", "displaying highscore", text) elif selection == "watch screensaver": watched += 1 playtime = screensaver.screensaver(resolution, fullscreen) easygui.msgbox("You watched the scrensaver %i x using this game menu \nYour screen was saved for %.2f seconds" % (watched, playtime)) # writing highscore-list try: f = file(gamefile, "a") # append f.write("date: %s player: %s playtime: %.2f seconds resolution: %ix%i fullscreen: %s \n" % (time.asctime(), playername, playtime, resolution[0], resolution[1], fullscreen)) f.close() except: raise UserWarning, "Error while writing higscore file %s" % gamefile exit() elif selection == "change resolution": answer = easygui.choicebox("Please select one of those screen resolutions", "x,y", reslist) # answer gives back a string like '(320, 200)' comma = answer.find(",") # position of the comma inside answer x = int(answer[1:comma]) y = int(answer[comma+1:-1]) resolution = (x,y) return
__author__ = 'Administrator' from lib import easygui import bad Hard_drive = [] # # def index_of_account(name) # for a in range (len(Hard_drive)): # account = Hard_drive[a] # print (str(account)) def index_of_account(name): for w in Hard_drive: print(str(w)) if (w.AccountName == name): return True def savetofile(list): filestring = '' for item in list: filestring += str(item) + '\n' print(filestring) myfiles = open('accountsfile.txt', 'w') myfiles.write(filestring) myfiles.close() def getFromfile(): try: ret = [] dan = open('accountsfile.txt', 'r') lines = dan.readlines()