Jacob_DiDiodato

Survey layout

Jul 23rd, 2017
300
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.41 KB | None | 0 0
  1. import pygame, easygui, sys
  2.  
  3. def main():
  4.     #All font and text
  5.     font = pygame.font.SysFont("times", 30)
  6.     choiceALabel = font.render("Choice A", 1, (255,255,255))
  7.     choiceBLabel = font.render("Choice B", 1, (255,255,255))
  8.     submitLabel = font.render("Submit", 1, (255,255,255))
  9.     #End of font and text
  10.    
  11.     attributesList = []
  12.     levelsDict = {}
  13.     numTrials = 0
  14.     attributesPerPage = 0
  15.     try:
  16.         attributesFile = open("surveyinfo.txt", "r")
  17.         fileContents = attributesFile.read().split("\n")
  18.         #Checking to see if the file contains the magic number
  19.         if fileContents[0] != "040":
  20.             easygui.msgbox(msg="Survey Error. File not setup properly. Please use the conjointSDT.py and export to Jacob-formatted TXT.",title="Error")
  21.             return
  22.         fileContentsNoMagicNumber = fileContents[1:]
  23.         #Iterate everything besides the magic number to build the attributes and levels
  24.         for i in range(len(fileContentsNoMagicNumber)):
  25.             if i != len(fileContentsNoMagicNumber) - 1:
  26.                 attributesList.append(fileContentsNoMagicNumber[i].split(":")[0])
  27.                 levelsDict[attributesList[i]] = fileContentsNoMagicNumber[i].split(":")[1].split(",")
  28.             else:
  29.                 numTrials = int(fileContentsNoMagicNumber[i])
  30.     #If the file doesn't exist then exit the program
  31.     except IOError:
  32.         easygui.msgbox(msg="Survey Error. Missing file \"surveyinfo.txt\".",title="Error")
  33.         return
  34.  
  35.     clock = pygame.time.Clock()
  36.  
  37.     screen = pygame.display.set_mode((640,480), pygame.NOFRAME)
  38.    
  39.     #Here we set a unique userID
  40.     userID = 0
  41.     try:
  42.         #Here we read from the file if we can and get the unique ID of the user
  43.         userIDFile = open("id.txt", "r")
  44.         userID = int(userIDFile.read())
  45.         userIDFile.close()
  46.     except IOError:
  47.         #If the file doesn't exist then we pass by the exception because it's not terrible
  48.         pass
  49.    
  50.     #Here we replace the contents of the old file with a new userID
  51.     userIDFile = open("id.txt", "w")
  52.     userIDFile.write(str(userID+1))
  53.     userIDFile.close()
  54.     #End of unique userID
  55.    
  56.     #Early questions here
  57.     firstName = easygui.enterbox("Please enter your first name.")
  58.     lastName = easygui.enterbox("Please enter your last name.")
  59.     age = int(easygui.enterbox("Please enter your age."))
  60.     #End of early questions
  61.    
  62.     running = True
  63.     while running:
  64.         for event in pygame.event.get():
  65.             if event.type == pygame.QUIT:
  66.                 running = False
  67.             if event.type == pygame.MOUSEBUTTONUP:
  68.                 print pygame.mouse.get_pos()
  69.                
  70.         screen.fill((211,211,211))
  71.        
  72.         pygame.draw.line(screen, (0,0,0), (453, 0), (453, 480))
  73.         pygame.draw.line(screen, (0,0,0), (266, 0), (266, 480))
  74.         pygame.draw.line(screen, (0,0,0), (0, 72), (640, 72))
  75.         pygame.draw.line(screen, (0,0,0), (0, 144), (640, 144))
  76.         pygame.draw.line(screen, (0,0,0), (0, 216), (640, 216))
  77.         pygame.draw.line(screen, (0,0,0), (0, 288), (640, 288))
  78.         pygame.draw.line(screen, (0,0,0), (0, 360), (640, 360))
  79.         pygame.draw.line(screen, (0,0,0), (0, 432), (640, 432))
  80.         pygame.draw.ellipse(screen, (255,255,255), (350,445,20,20))
  81.         pygame.draw.ellipse(screen, (0,0,0), (349,444,22,22), 1)
  82.         pygame.draw.ellipse(screen, (255,255,255), (535,445,20,20))
  83.         pygame.draw.ellipse(screen, (0,0,0), (534,444,22,22), 1)
  84.         screen.blit(choiceALabel, (303, 20))
  85.         screen.blit(choiceBLabel, (490, 20))
  86.         screen.blit(submitLabel, (screen.get_width()/5 - submitLabel.get_width()/2, screen.get_height() - 40))
  87.    
  88.         pygame.display.update()
  89.        
  90.         msElapsed = clock.tick(60)
  91.  
  92. if __name__ == "__main__":
  93.     pygame.init()
  94.     main()
  95.     pygame.quit()
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment