Exemple #1
0
    def add_word(self):
        '''
        Method which Allow adding a word in the dictionary by a GUI
        '''
        word_input=easygui.multenterbox(msg='Add Word', title='Add Word',fields=('Word',"Definition/Translation/Association"), values=("Bonjour","Guten Tag"))
        
        if not word_input==None:
            word=word_input[0]
            translation=word_input[1]
            Group=0
            Last_Interogation_Date=None
            Time_since_the_last_interogation=None
            Time_before_the_next_interogation=0

            self.__content[word]={"Word":word,"Definition/Translation/Association":translation,"Group":Group,
                                  "Last Interogation Date":Last_Interogation_Date,
                                  "Number of Days since the last interogation":Time_since_the_last_interogation,
                                  "Number of Days before the next interogation":Time_before_the_next_interogation}
            self.save(self.__uploaded_dictionary_file_path)
            msg   = "We have add the word: "+word+" (Translation: "+translation+") in the dictionry"
            choices = ["Add Word Again","Main Menu","Cancel"]
            reply=easygui.buttonbox(msg,choices=choices)
        else:
            reply="Main Menu"
        if reply=="Add Word Again":
            self.add_word()
        elif reply=="Cancel":
            del  self.__content[word]
        else :
            pass
 def main_menu(self):
     """The main menu that contains actions like new map and loading."""
     # Ask if the user wants to load a map or create a new one
     prompt = "Welcome to GenEditor for Tile Maps!"
     title = "Main Menu"
     options = ["New Map", "Load Map"]
     # Separate options for start up and other phases
     if self.common.edit_phase:
         options.append("Close Menu")
     else:
         options.append("Quit")
     # Display the window/prompt and get the user decision
     decision = easygui.buttonbox(prompt, title, options)
     # User wants to make a new map
     if decision == "New Map":
         self.new_map()
     # User wants to load a map
     elif decision == "Load Map":
         self.load_map()
     # Close the menu
     elif decision == "Close Menu":
         return
     # Quit the program
     elif decision == "Quit":
         self.quit()
     # Quit if response is not one of the known options
     else:
         self.quit()
Exemple #3
0
def main():
    r = easygui.buttonbox('Welcome to ELiTE CS BANK \n please select an option','ELiTE CS BANK',(CREATE_ACC,ACCESS_ACC,EXIT))

    if r == EXIT:
        sys.exit()
    elif r == CREATE_ACC:
        createAccount()
    elif r == ACCESS_ACC:
        accessAccount()
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 save_map(self):
     """Writes the map data to a text file and image file."""
     # Prompt for the save location
     save_path = easygui.filesavebox("Two files will be created, one image and one text file.")
     # User cancels the save operation
     if save_path is None:
         return
     # Get a complete rendering of the map
     img = self.GFX.render_full_map()
     # Check if that is already a file(s) with that name(s), and if it ok to override it
     msg = "There is already a file in this location with that name.  Override?"
     if (os.path.exists(save_path+".bmp") or os.path.exists(save_path+".json")) and easygui.buttonbox(msg, "Continue?", ("Yes", "No")) == "No":
         return
     # Otherwise save the map files
     else:
         # Save image to file
         pygame.image.save(img, save_path + ".bmp")
         # Save map data as JSON data
         with open(save_path + ".json", 'w') as f:
             json.dump({'generator_data' : self.MapGen.params, 'tile_map' : self.common.tile_map}, f)
         # Indicate saving is complete
         easygui.msgbox("\"" + str(os.path.basename(save_path)) + "\" saved successfully", "Save Complete")
Exemple #6
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
Exemple #7
0
    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 
Exemple #9
0
__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()