Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from customWidgets import *
- from PyQt5 import uic
- from PyQt5.QtCore import *
- from PyQt5.QtGui import *
- from PyQt5.QtWidgets import *
- QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
- app = QApplication([])
- window = uic.loadUi("experimentThree.ui")
- file = open('all_results.csv', 'w')
- file.write("age, gender, education, race\n") # Headers of data file
- window.consent_error_lbl.hide()
- window.o_gender.hide()
- window.o_race.hide()
- def next_page(): # Takes user to the next page
- current_page = window.stackedWidget.currentIndex()
- if current_page == 0:
- consent_checker()
- elif current_page == 1:
- demographics_checker()
- else:
- window.stackedWidget.setCurrentIndex(current_page + 1)
- def consent_checker(): # Confirms user's consent and that they understand the criteria to do the study
- current_page = window.stackedWidget.currentIndex()
- if not window.checkBox_1.isChecked() or not window.checkBox_2.isChecked() or not window.checkBox_3.isChecked() \
- or not window.checkBox_4.isChecked() or not window.checkBox_5.isChecked() or not \
- window.checkBox_6.isChecked():
- window.consent_error_lbl.show() # If not all clicked when clicking 'next', error appears
- else:
- window.stackedWidget.setCurrentIndex(current_page + 1) # Next page, when user fully consents
- def demographics_checker(): # Confirms all demographic information inputted by the user is appropriate
- error_demographics = []
- current_page = window.stackedWidget.currentIndex()
- if other.isChecked(): # Provides text boxes if user's gender and racial identity aren't immediate options
- window.o_gender.show()
- else:
- window.o_gender.hide()
- if window.race.currentText() == "Other":
- window.o_race.show()
- else:
- window.o_race.hide()
- if window.age.value() < 18: # Demographic confirmation
- error_demographics.append("age")
- if (not male.isChecked() and not female.isChecked() and not other.isChecked()) \
- or (other.isChecked() and window.o_gender.text() == ""):
- error_demographics.append("gender")
- if window.race.currentText() == "---" or (window.race.currentText() == "Other" and window.o_race.text() == ""):
- error_demographics.append("race")
- if not school.isChecked() and not undergrad.isChecked() and not masters.isChecked() and not phd.isChecked():
- error_demographics.append("education level")
- if len(error_demographics) > 0:
- window.demographics_error_lbl.setText(f"ERROR: Please input an appropriate value for the following "
- f"demographics: \n\n {', '.join(error_demographics)}")
- else:
- window.demographics_error_lbl.hide()
- if male.isChecked(): # Storing chosen gender
- gender = 'Male'
- elif female.isChecked():
- gender = 'Female'
- elif other.isChecked():
- gender = window.o_gender.text()
- if school.isChecked(): # Storing chosen education level
- education = 'High School'
- elif undergrad.isChecked():
- education = 'Undergraduate Degree'
- elif masters.isChecked():
- education = 'Masters Degree'
- elif phd.isChecked():
- education = 'PhD'
- if window.race.currentText() != "Other": # Writing demographic information into data file
- file.write(f'{window.age.value()}, {gender}, {education}, {window.race.currentText()}')
- else:
- file.write(f'{window.age.value()}, {gender}, {education}, {window.o_race.text()}')
- file.close()
- window.stackedWidget.setCurrentIndex(current_page + 1) # Next page, when appropriate demographics inputted
- window.next_button.clicked.connect(next_page)
- # Gender demographics
- male = colouredButton(window.gender_group)
- male.setStyle(0, 0, 400, 50, 'Male')
- male.setIcon(QIcon('male.png'))
- female = colouredButton(window.gender_group)
- female.setStyle(410, 0, 400, 50, 'Female')
- female.setIcon(QIcon('female.png'))
- other = colouredButton(window.gender_group)
- other.setStyle(0, 60, 400, 50, 'Other')
- # Education level demographics
- school = colouredButton(window.education_group)
- school.setStyle(0, 0, 400, 50, 'High School')
- undergrad = colouredButton(window.education_group)
- undergrad.setStyle(410, 0, 400, 50, 'Undergraduate Degree')
- masters = colouredButton(window.education_group)
- masters.setStyle(0, 60, 400, 50, 'Masters Degree')
- phd = colouredButton(window.education_group)
- phd.setStyle(410, 60, 400, 50, 'PhD')
- def dot_updirection():
- window.dot.show()
- current_y = window.dot.y()
- if window.dot.y() == 250:
- window.dot.hide()
- window.dot.setGeometry(540, 300, 20, 20)
- else:
- window.dot.setGeometry(540, current_y - 10, 20, 20)
- def dot_leftdirection():
- window.dot.show()
- current_x = window.dot.x()
- if window.dot.x() == 490:
- window.dot.hide()
- window.dot.setGeometry(540, 300, 20, 20)
- else:
- window.dot.setGeometry(current_x - 10, 300, 20, 20)
- def dot_rightdirection():
- window.dot.show()
- current_x = window.dot.x()
- if window.dot.x() == 590:
- window.dot.hide()
- window.dot.setGeometry(540, 300, 20, 20)
- else:
- window.dot.setGeometry(current_x + 10, 300, 20, 20)
- def dot_downdirection():
- window.dot.show()
- current_y = window.dot.y()
- if window.dot.y() == 350:
- window.dot.hide()
- window.dot.setGeometry(540, 300, 20, 20)
- else:
- window.dot.setGeometry(540, current_y + 10, 20, 20)
- window.dot.hide()
- timerUP = QTimer()
- timerUP.timeout.connect(dot_updirection)
- timerDOWN = QTimer()
- timerDOWN.timeout.connect(dot_downdirection)
- timerLEFT = QTimer()
- timerLEFT.timeout.connect(dot_leftdirection)
- timerRIGHT = QTimer()
- timerRIGHT.timeout.connect(dot_rightdirection)
- def dot_upmotion():
- timerUP.start(100)
- def dot_leftmotion():
- timerLEFT.start(100)
- def dot_rightmotion():
- timerRIGHT.start(100)
- def dot_downmotion():
- timerDOWN.start(100)
- # Adding keyboard key images to screen; connecting click of image to respective exemplar motion of dot
- i = clickLabel(window.page_3)
- i.setStyle('i_key.png', 140, 240, 60, 60)
- i.clicked.connect(dot_upmotion)
- j = clickLabel(window.page_3)
- j.setStyle('j_key.png', 90, 300, 60, 60)
- j.clicked.connect(dot_leftmotion)
- k = clickLabel(window.page_3)
- k.setStyle('k_key.png', 180, 300, 60, 60)
- k.clicked.connect(dot_rightmotion)
- m = clickLabel(window.page_3)
- m.setStyle('m_key.png', 130, 360, 60, 60)
- m.clicked.connect(dot_downmotion)
- window.show()
- app.exec_()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement