Jacob_DiDiodato icon

Survey layout

Jacob_DiDiodato | PRO | 07/23/17 04:47:11 PM UTC | 0 ⭐ | 247 👁️ | Never ⏰ | []
Python |

3.41 KB

|

None

|

0 👍

/

0 👎

import pygame, easygui, sys
 
def main():
    #All font and text
    font = pygame.font.SysFont("times", 30)
    choiceALabel = font.render("Choice A", 1, (255,255,255))
    choiceBLabel = font.render("Choice B", 1, (255,255,255))
    submitLabel = font.render("Submit", 1, (255,255,255))
    #End of font and text
    
    attributesList = []
    levelsDict = {}
    numTrials = 0
    attributesPerPage = 0
    try:
        attributesFile = open("surveyinfo.txt", "r")
        fileContents = attributesFile.read().split("\n")
        #Checking to see if the file contains the magic number
        if fileContents[0] != "040":
            easygui.msgbox(msg="Survey Error. File not setup properly. Please use the conjointSDT.py and export to Jacob-formatted TXT.",title="Error")
            return
        fileContentsNoMagicNumber = fileContents[1:]
        #Iterate everything besides the magic number to build the attributes and levels
        for i in range(len(fileContentsNoMagicNumber)):
            if i != len(fileContentsNoMagicNumber) - 1:
                attributesList.append(fileContentsNoMagicNumber[i].split(":")[0])
                levelsDict[attributesList[i]] = fileContentsNoMagicNumber[i].split(":")[1].split(",")
            else:
                numTrials = int(fileContentsNoMagicNumber[i])
    #If the file doesn't exist then exit the program
    except IOError:
        easygui.msgbox(msg="Survey Error. Missing file \"surveyinfo.txt\".",title="Error")
        return
 
    clock = pygame.time.Clock()
 
    screen = pygame.display.set_mode((640,480), pygame.NOFRAME)
    
    #Here we set a unique userID
    userID = 0
    try:
        #Here we read from the file if we can and get the unique ID of the user
        userIDFile = open("id.txt", "r")
        userID = int(userIDFile.read())
        userIDFile.close()
    except IOError:
        #If the file doesn't exist then we pass by the exception because it's not terrible
        pass
    
    #Here we replace the contents of the old file with a new userID 
    userIDFile = open("id.txt", "w")
    userIDFile.write(str(userID+1))
    userIDFile.close()
    #End of unique userID
    
    #Early questions here
    firstName = easygui.enterbox("Please enter your first name.")
    lastName = easygui.enterbox("Please enter your last name.")
    age = int(easygui.enterbox("Please enter your age."))
    #End of early questions
    
    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            if event.type == pygame.MOUSEBUTTONUP:
                print pygame.mouse.get_pos()
                
        screen.fill((211,211,211))
        
        pygame.draw.line(screen, (0,0,0), (453, 0), (453, 480))
        pygame.draw.line(screen, (0,0,0), (266, 0), (266, 480))
        pygame.draw.line(screen, (0,0,0), (0, 72), (640, 72))
        pygame.draw.line(screen, (0,0,0), (0, 144), (640, 144))
        pygame.draw.line(screen, (0,0,0), (0, 216), (640, 216))
        pygame.draw.line(screen, (0,0,0), (0, 288), (640, 288))
        pygame.draw.line(screen, (0,0,0), (0, 360), (640, 360))
        pygame.draw.line(screen, (0,0,0), (0, 432), (640, 432))
        pygame.draw.ellipse(screen, (255,255,255), (350,445,20,20))
        pygame.draw.ellipse(screen, (0,0,0), (349,444,22,22), 1)
        pygame.draw.ellipse(screen, (255,255,255), (535,445,20,20))
        pygame.draw.ellipse(screen, (0,0,0), (534,444,22,22), 1)
        screen.blit(choiceALabel, (303, 20))
        screen.blit(choiceBLabel, (490, 20))
        screen.blit(submitLabel, (screen.get_width()/5 - submitLabel.get_width()/2, screen.get_height() - 40))
    
        pygame.display.update()
        
        msElapsed = clock.tick(60)
 
if __name__ == "__main__":
    pygame.init()
    main()
    pygame.quit()

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎