Exemplo n.º 1
0
 def load_map(self):
     """Loads a map from a JSON-formatted file."""
     # Prompt user for the map file to open
     map_file = easygui.fileopenbox("Select the map file to open.")
     # Stop and return to start if user canceled/closed the window
     if map_file == None:
         return
     # Open the file and process the JSON data
     with open(map_file, 'r') as f:
         json_data = None
         try:
             # Load file's JSON data into python objects
             json_data = json.loads(f.read())
             # Load tile map
             self.common.tile_map = json_data['tile_map']
             # Create generator with the loaded map's parameters
             self.MapGen = genmap.MapGenerator(self.common, json_data['generator_data'])
             # Switch to map edit phase
             self.common.edit_phase = True
         # JSON could not load data from the file or it is not correctly formatted
         except (ValueError, KeyError):
             # Display info to user
             msg = "\"{name}\" is not a valid GenEditor JSON formatted map file.".format(
                 name=os.path.basename(map_file)
                 )
             easygui.msgbox(msg, "Invalid Map")
         finally:
             # Clear JSON data to save memory
             del json_data
Exemplo n.º 2
0
def createAccount():
    usr = easygui.multpasswordbox('Creating Account','new Account',('Name','Password'))

    if usr != None:
        for item in usr:
            if len(item) == 0:
                easygui.msgbox('Fields can not be empty')
                createAccount()
Exemplo n.º 3
0
 def FatalExternalError(self, msg=""):
     """Used to terminate the program with a message when a serious issue occurs.
     This includes file/directory permission issues, etc.
     """
     print msg
     # Display message
     easygui.msgbox(str(msg)+"  The program will now be terminated.",
         "A Fatal External Error Has Occurred")
     self.quit()
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 
Exemplo n.º 5
0
def accessAccount():
    usr = easygui.multpasswordbox('Access Account','ELiTE CS BANK',('Name','Password'))

    if usr != None:
        for item in usr:
            if len(item) == 0:
                easygui.msgbox('Fields can not be empty')
                accessAccount()

        #TODO: access user account here


    else:
        main()
Exemplo n.º 6
0
    def create_new_interogation (self,list,number_of_word_to_learn,day_in_advance,mode=""):
        '''
        Create an interogation of words
        '''
        
        total_point=0
        number_of_word=0
        vocabulary_list=list
        
        if len(list)==0 or mode=="marathon":
            for word,value in self.__content.items():
                if len(vocabulary_list)<number_of_word_to_learn:
                    if word in vocabulary_list:
                        pass
                    elif value["Group"]==0:
                        vocabulary_list.append(word)
                    elif fibonacci.fib(int(value["Group"]))-int(value["Number of Days since the last interogation"])-int(day_in_advance)<=0:
                        vocabulary_list.append(word)
                else :
                    break;
    
        
        unknown_vocabulary=[]
        known_vocabulary=[]
        

        random.shuffle(vocabulary_list)
        #pprint.pprint(vocabulary_list)
        for french_word in vocabulary_list:
        
            value=self.__content[french_word]

            number_of_word+=1
            point=self.please_translate(french_word,mode)
            if point==None:
                return;
            elif point==0:
                unknown_vocabulary.append(french_word)
            else:
                known_vocabulary.append(french_word)
            total_point+=point
      
        self.save(self.__uploaded_dictionary_file_path)
        if len(unknown_vocabulary)==0 and len(known_vocabulary)==0:
            easygui.msgbox(msg="No new Vocabulary for today",title="Learn")
            return ;
        
        if not total_point==number_of_word:
            self.create_new_interogation(unknown_vocabulary,number_of_word_to_learn=number_of_word_to_learn,day_in_advance=day_in_advance,mode=mode)
Exemplo n.º 7
0
 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")
Exemplo n.º 8
0
 def unimplemented_feature(self):
     """Indicates to the user that a feature they tried to use hasn't been
     implemented yet.
     """
     # Display message box
     easygui.msgbox("That Feature is not yet available.", "Sorry!")
Exemplo n.º 9
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
Exemplo n.º 10
0
from lib import easygui
import math
q=easygui.enterbox(int(raw_input('This little app will help yo find the factorial of any number.Please enter a number'))

 math.factorial(r)
 easygui.msgbox('this is the factorial',r,'ok')



Exemplo n.º 11
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 
Exemplo n.º 12
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()