def __init__(self,app): #Needs access to the app use open method self.app = app tdStyle = {'padding':10} #The controlled variables lbl1 = gui.Label("The equations below show the line the equation for the graph") dataTbl = gui.Table() dataTbl.tr() dataTbl.td(lbl1) #The equation needed equationImg = gui.Image(resM.absoluteZero) imgTable = gui.Table() imgTable.td(gui.Image(resM.measuregEquation)) #The question questionLbl = gui.Label("What is g to 2dp?") questionTable = gui.Table() questionTable.tr() questionTable.td(questionLbl) #The Options for answers answerTbl = gui.Table() gLbl = gui.Label("g") gAns = gui.Input() answerTbl.tr() answerTbl.td(gLbl) answerTbl.td(gAns,style = tdStyle) #Checking User Answers checkAnswerBtn = gui.Button("Check Answer",width=100,height=30) def checkAnswer(): if gAns.value == "9.81": dlg = gui.Dialog(gui.Label("Your answer was..."),gui.Label("Correct. Well Done")) else: dlg = gui.Dialog(gui.Label("Your answer was..."),gui.Label("Wrong. Try Again")) self.app.open(dlg) checkAnswerBtn.connect(gui.CLICK,checkAnswer) #Adding the labels to the table tbl = gui.Table() tbl.tr() tbl.td(dataTbl,style = tdStyle) tbl.tr() tbl.td(imgTable,style = tdStyle) tbl.tr() tbl.td(questionTable,style = tdStyle) tbl.tr() tbl.td(answerTbl,style = tdStyle) tbl.tr() tbl.td(checkAnswerBtn,style = tdStyle) gui.Dialog.__init__(self,gui.Label("Question"),tbl)
def calcPoint(self, rulerRect): self.app.gameArea.save_background(False) if self.currentLength == 0: self.crocPoint = rulerRect.left, rulerRect.center[1] - 20 current = 0 resistance = 0 self.currentLength += self.app.interval elif self.currentLength >= self.maxVar: self.crocPoint = rulerRect.left + (rulerRect.width * self.currentLength / 100), rulerRect.center[1] - 20 current, resistance = genValues(self.currentLength) createGraph(self.graphx, self.graphy) self.experimentDone = True else: self.crocPoint = rulerRect.left + (rulerRect.width * self.currentLength / 100), rulerRect.center[1] - 20 current, resistance = genValues(self.currentLength) self.currentLength += self.app.interval self.graphx.append(self.currentLength) self.graphy.append(resistance) self.app.tableArea.td(gui.Label(str(current)), col=self.colCount, row=1, style={'border': 1}) self.app.tableArea.td(gui.Label(str(resistance)), col=self.colCount, row=2, style={'border': 1})
def checkAnswer(): if optionsGroup.value == 1: dlg = gui.Dialog(gui.Label("Your answer was..."),gui.Label("Correct. Well Done")) else: dlg = gui.Dialog(gui.Label("Your answer was..."),gui.Label("Wrong. Try Again")) self.app.open(dlg)
def addValuesToTable(self, time): # Creates Label and adds it to its relevant Row timeLbl = gui.Label(str(round(time, 2))) self.td(timeLbl, col=self.currentColumn, row=1, style={'border': 1}) timeLbl = gui.Label(str(round(time**2, 2))) self.td(timeLbl, col=self.currentColumn, row=2, style={'border': 1}) self.yPoints.append(time**2) self.currentColumn += 1
def checkAnswer(): if gAns.value == str(exp.SHC): dlg = gui.Dialog(gui.Label("Your answer was..."), gui.Label("Correct. Well Done")) else: dlg = gui.Dialog(gui.Label("Your answer was..."), gui.Label("Wrong. Try Again")) self.app.open(dlg)
def addValuesToTable(self, iVel, fVel, acc): #Creates Label and adds it to its relevant Row velLbl = gui.Label(str(round(iVel, 2))) self.td(velLbl, col=self.currentColumn, row=2, style={'border': 1}) velLbl = gui.Label(str(round(fVel, 2))) self.td(velLbl, col=self.currentColumn, row=3, style={'border': 1}) accLbl = gui.Label(str(round(acc, 2))) #Sends Acceleration to Graph self.yPoints.append(acc) self.td(accLbl, col=self.currentColumn, row=4, style={'border': 1}) self.currentColumn += 1
def addToTable(self, current, resistance): currentLbl = gui.Label(str(round(current, 2))) #Round the values to make resistanceLbl = gui.Label(str(round(resistance, 2))) #them more presentable self.app.tableArea.td(currentLbl, col=self.currentColumn, row=1, style={'border': 1}) #Adding the values self.app.tableArea.td(resistanceLbl, col=self.currentColumn, row=2, style={'border': 1}) #To the tables self.yPoints.append(resistance) #Adds the unrounded values to y-points self.currentColumn += 1 # Increments columnCount for the add next value
def addToTable(self,current,voltage): currentLbl = gui.Label(str(round(current,3))) #Round the values to make voltageLbl = gui.Label(str(round(voltage,2))) self.td(currentLbl, col=self.currentColumn, row=1, style={'border': 1})#Adding the values self.td(voltageLbl, col=self.currentColumn, row=2, style={'border': 1}) #To the tables self.voltageCurrentGraph.xPoints.append(current) self.voltageCurrentGraph.yPoints.append(voltage) if current != 0: self.resistanceCurrentGraph.xPoints.append(1/current) else: self.resistanceCurrentGraph.xPoints.append(0) self.currentColumn += 1 # Increments columnCount for the add next value
def setupTable(self): tbl = self.tableArea currentNum = self.minVar tbl.tr() tbl.td(gui.Label("Length of wire"), style={'border': 1}) while currentNum != self.maxVar: tbl.td(gui.Label(str(currentNum)), style={'border': 1}) currentNum += self.interval tbl.td(gui.Label(str(self.maxVar)), style={'border': 1}) tbl.tr() tbl.td(gui.Label("Current(A)"), style={'border': 1}) tbl.tr() tbl.td(gui.Label("Resistance()"), style={'border': 1})
def __init__(self, xPoints, yPoints): gradient, yIntercept = graph.createGraph(xPoints, yPoints, "Current Length/cm", "Resistance/Ω") gradientLbl = gui.Label("Gradient:" + str(round(gradient, 3))) yInterceptLbl = gui.Label("Y-Intercept:" + str(round(yIntercept, 3))) tbl = gui.Table() tbl.tr() tbl.td(gui.Image("graph.png")) tbl.tr() tbl.td(gradientLbl) tbl.tr() tbl.td(yInterceptLbl) gui.Dialog.__init__(self, gui.Label("Graph"), tbl)
def createButton(imgName, text): splitText = textwrap.wrap( text, width=30) # Splits text and sets width of line to 30 characters #Loads Image img = pygame.image.load(imgName) #Stretches Image keeping height:width ratio constant height = int(250 * img.get_height() / img.get_width()) img = pygame.transform.scale(img, (250, height)) #If the image is too tall if img.get_height() > 80: #Resize with max height height = 80 width = int(height * img.get_width() / img.get_height()) img = pygame.transform.scale(img, (width, height)) #Add Image and label to table main = gui.Table() main.tr() main.td(gui.Image(img)) for each in splitText: # Puts each line in a label then adds it to the widget main.tr() main.td(gui.Label(each)) return gui.Button(main, height=130, width=250)
def __init__(self,table): self.tableArea = table xPoints = self.tableArea.xPoints yPoints = self.tableArea.yPoints gradient,yIntercept = graph.createGraph(xPoints,yPoints,"Height/m","Time²/s²") gradientLbl = gui.Label("Gradient:" + str(round(gradient,6))) yInterceptLbl = gui.Label("Y-Intercept:" + str(round(yIntercept,3))) tbl = gui.Table() tbl.tr() tbl.td(gui.Image("graph.png")) tbl.tr() tbl.td(gradientLbl) tbl.tr() tbl.td(yInterceptLbl) gui.Dialog.__init__(self,gui.Label("Graph"),tbl)
def __init__(self,table): self.tableArea = table xPoints = self.tableArea.xPoints yPoints = self.tableArea.yPoints gradient,yIntercept = graph.createGraph(xPoints,yPoints,"Weight Force of Mass Holder/N","Acceleration/(m/s²)") gradientLbl = gui.Label("Gradient:" + str(round(gradient,6))) yInterceptLbl = gui.Label("Y-Intercept:" + str(round(yIntercept,3))) tbl = gui.Table() tbl.tr() tbl.td(gui.Image("graph.png")) tbl.tr() tbl.td(gradientLbl) tbl.tr() tbl.td(yInterceptLbl) gui.Dialog.__init__(self,gui.Label("Graph"),tbl)
def __init__(self,table): self.tableArea = table xPoints = self.tableArea.xPoints yPoints = self.tableArea.yPoints gradient,yIntercept = graph.createGraph(xPoints,yPoints,"Temperature/°C","Pressure/kPa") gradientLbl = gui.Label("Gradient:" + str(round(gradient,3))) yInterceptLbl = gui.Label("Y-Intercept:" + str(round(yIntercept,3))) tbl = gui.Table() tbl.tr() tbl.td(gui.Image("graph.png")) tbl.tr() tbl.td(gradientLbl) tbl.tr() tbl.td(yInterceptLbl) gui.Dialog.__init__(self,gui.Label("Graph"),tbl)
def setup(self): minIV = self.app.minIV maxIV = self.app.maxIV interval = self.app.interval cellStyle = {'border': 1} currentNum = minIV self.tr() self.td(gui.Label("Time/s"), style=cellStyle) while currentNum <= maxIV: self.xPoints.append(int(currentNum)) lbl = gui.Label(str(currentNum)) self.td(lbl, style=cellStyle) currentNum += interval self.tr() self.td(gui.Label("Temperature/°C"), style=cellStyle)
def addToTable(self, pressure): pressureLbl = gui.Label(str(round(pressure, 2))) #Round the values to make self.app.tableArea.td(pressureLbl, col=self.currentColumn, row=1, style={'border': 1}) #Adding the values self.yPoints.append(pressure) #Adds the unrounded values to y-points self.currentColumn += 1 # Increments columnCount for the add next value
def createSection(self,graph,isExponential): graphDataTbl = gui.Table() gradient = graph.gradient graphDataTbl.td(gui.Label("Gradient:")) graphDataTbl.td(gui.Label(str(gradient))) graphDataTbl.tr() yInt = graph.yInt graphDataTbl.td(gui.Label("Y-Intercept:")) graphDataTbl.td(gui.Label(str(yInt))) tbl = gui.Table() tbl.tr() tbl.td(gui.Label(graph.graphName)) if not isExponential: tbl.tr() tbl.td(graphDataTbl) return tbl
def setup(self): minIV = self.app.minIV maxIV = self.app.maxIV interval = self.app.interval cellStyle = {'border': 1} currentNum = minIV self.tr() self.td(gui.Label("Length of Wire/cm"), style=cellStyle) while currentNum <= maxIV: self.xPoints.append(int(currentNum)) lbl = gui.Label(str(currentNum)) self.td(lbl, style=cellStyle) currentNum += interval self.tr() self.td(gui.Label("Current"), style=cellStyle) self.tr() self.td(gui.Label("Resistance"), style=cellStyle)
def setup(self): minIV = self.app.minIV maxIV = self.app.maxIV interval = self.app.interval cellStyle = {'border':1} currentNum = minIV self.tr() self.td(gui.Label("Resistance/Ω"),style = cellStyle) while currentNum <= maxIV: self.resistanceCurrentGraph.yPoints.append(int(currentNum)) lbl = gui.Label(str(currentNum)) self.td(lbl,style = cellStyle) currentNum += interval self.tr() self.td(gui.Label("Current"),style = cellStyle) self.tr() self.td(gui.Label("Voltage"),style = cellStyle)
def __init__(self): constantsLbl = gui.Label("Constants") batteryVoltageLbl = gui.Label("Battery Voltage = 1.5 Volts") wireAreaLbl = gui.Label("Wire Cross Sectional Area = 0.00785 cm²") wireTypeLbl = gui.Label("Wire Type = Nichrome") tbl = gui.Table() lblStyle = {'padding': 5} tbl.tr() tbl.td(constantsLbl, style=lblStyle) tbl.tr() tbl.td(batteryVoltageLbl, style=lblStyle) tbl.tr() tbl.td(wireAreaLbl, style=lblStyle) tbl.tr() tbl.td(wireTypeLbl, style=lblStyle) gui.Dialog.__init__(self, gui.Label("CONSTANTS"), tbl)
def setup(self): # Get Variables minIV = self.app.engine.startHeight maxIV = self.app.engine.endHeight interval = self.app.engine.heightInterval # Standardises the cell style cellStyle = {'border': 1} currentNum = minIV self.tr() # New Row self.td(gui.Label("Height/m"), style=cellStyle) # Add Row Heading while currentNum <= maxIV: # Keep going till maxIV is in the table self.xPoints.append(currentNum / 100) # Adds to x points lbl = gui.Label(str(currentNum)) # Creates Labels self.td(lbl, style=cellStyle) currentNum += interval self.tr() self.td(gui.Label("Time,s"), style=cellStyle) # Adds row heading for measured variable self.tr() self.td(gui.Label("Time²/s²"), style=cellStyle) # Adds row heading for calculated variable
def setup(self): #Get Variables cartWeights = self.app.engine.cartWeights massHolderWeights = self.app.engine.massHolderWeights weightSize = self.app.engine.weightSize cellStyle = {'border': 1} #Sets border for each cell self.tr() self.td(gui.Label("Weight Force on Mass Holder/kg"), style=cellStyle) #First Table heading while cartWeights >= 0: #Adds each weight which the mass holder will have on it weightInKg = massHolderWeights * weightSize lbl = gui.Label(str(round(weightInKg, 2))) self.td(lbl, style=cellStyle) #Shifts weight from cart to massHolder cartWeights -= 1 massHolderWeights += 1 #Renew Variables cartWeights = self.app.engine.cartWeights massHolderWeights = self.app.engine.massHolderWeights weightSize = self.app.engine.weightSize self.tr() self.td(gui.Label("Weight Force of Mass Holder/N"), style=cellStyle) #2nd Table Header while cartWeights >= 0: #Adds Weight Force for Mass Holder weightInN = massHolderWeights * weightSize * 9.81 self.xPoints.append(weightInN) lbl = gui.Label(str(round(weightInN, 3))) self.td(lbl, style=cellStyle) cartWeights -= 1 massHolderWeights += 1 #Adds columns for velocities and acceleration equation self.tr() self.td(gui.Label("Initial Velocity/(m/s)"), style=cellStyle) self.tr() self.td(gui.Label("Final Velocity/(m/s)"), style=cellStyle) self.tr() self.td(gui.Image(resM.accelerationEquation, height=48, width=84), style=cellStyle)
def __init__(self,app): self.app = app menuBtn = gui.Button("Back to Menu",width = 200,height=50) restartBtn = gui.Button("Restart Experiment",width = 200,height=50) def restartExperimentBtn_cb(): self.app.restart() restartBtn.connect(gui.CLICK, restartExperimentBtn_cb) def menuBtn_cb(): import MainMenu as m m.run() menuBtn.connect(gui.CLICK, menuBtn_cb) tbl = gui.Table() tbl.tr() tbl.td(menuBtn) tbl.tr() tbl.td(restartBtn) gui.Dialog.__init__(self,gui.Label("Options"),tbl)
def __init__(self,tableArea): firstGraph = tableArea.exponentialGraph secondGraph = tableArea.lnGraph firstGraph.drawGraph(True) secondGraph.drawGraph(False) s1 = self.createSection(firstGraph,True) s2 = self.createSection(secondGraph,False) subTbl = gui.Table(width = 640) subTbl.tr() subTbl.td(s1) subTbl.td(s2) tbl = gui.Table() tbl.tr() tbl.td(gui.Image("graphs.png")) tbl.tr() tbl.td(subTbl) gui.Dialog.__init__(self,gui.Label("Graphs"),tbl)
def __init__(self): instructions = """<p> 1. Look at the Instructions Dialog<br> 2. Input your variables<br> 3. Click start experiment to begin the animation<br> 4. While the animation is running, you can pause it by using the pause button or toggle labels using the show labels button<br> 5. Once all the values in the table have been filled in, try and plot the graph<br> 6. After plotting the graph yourself, you can look at the graph that should have been plotted<br> 7. Finally answer the question to see if you have understood the experiment correctly<br> </p> """ #Adding the method to the document which html doc = html.HTML(instructions, width=800) tbl = gui.Table() tbl.tr() tbl.td(gui.Image(resourceManager.exampleExperiment)) tbl.tr() tbl.td(doc) #tbl.td(instructions) gui.Dialog.__init__(self, gui.Label("Help"), tbl)
def generateLayout(app): pygame.font.init() font = pygame.font.SysFont("cambria", 60) text = font.render("Main Menu", True, (0, 128, 0)) menuTable = gui.Table(width=800, height=600) btnStyle = {"padding": 10} def help_cb(): dlg = HelpDialog() dlg.open() help = gui.Button("Help", height=50, width=100) help.connect(gui.CLICK, help_cb) menuTable.tr() menuTable.td(gui.Label("")) menuTable.td(gui.Image(text)) menuTable.td(help) menuTable.tr() def btn1_cb(): import Experiments.ResistivityOfAMetal.experiment as e e.run() btn1 = createButton(resourceManager.menuResistivity, "Determination of the Resistivity of a Metal") menuTable.td(btn1, style=btnStyle) btn1.connect(gui.CLICK, btn1_cb) def btn2_cb(): import Experiments.InternalResistance.experiment as e e.run() btn2 = createButton(resourceManager.menuInternalResistance, "Determination of the Internal Resistance of a Cell") menuTable.td(btn2, style=btnStyle) btn2.connect(gui.CLICK, btn2_cb) def btn3_cb(): import Experiments.EstimateAbsoluteZero.experiment as e e.run() btn3 = createButton(resourceManager.menuAbsoluteZero, "Estimation of Absolute Zero by Use of the Gas Laws") menuTable.td(btn3, style=btnStyle) btn3.connect(gui.CLICK, btn3_cb) menuTable.tr() def btn4_cb(): import Experiments.Newtons2ndLaw.experiment as e e.run() btn4 = createButton(resourceManager.menuNewtons2ndLaw, "Investigation of Newton's 2nd Law") menuTable.td(btn4, style=btnStyle) btn4.connect(gui.CLICK, btn4_cb) def btn5_cb(): import Experiments.RadioactiveDecay.experiment as e e.run() btn5 = createButton(resourceManager.menuRadioactiveDecay, "Investigation of Radioactive Decay") menuTable.td(btn5, style=btnStyle) btn5.connect(gui.CLICK, btn5_cb) def btn6_cb(): import Experiments.Measureg.experiment as e e.run() btn6 = createButton(resourceManager.menugByFrefall, "Measurement of g by free-fall") menuTable.td(btn6, style=btnStyle) btn6.connect(gui.CLICK, btn6_cb) menuTable.tr() def btn7_cb(): import Experiments.SHCofSolid.experiment as e e.run() btn7 = createButton( resourceManager.menuSHC, "Measurement of the Specific Heat Capacity for a Solid") menuTable.td(btn7, col=1, style=btnStyle) btn7.connect(gui.CLICK, btn7_cb) return menuTable
def __init__(self,defaultVals): #Object can tell menu that inputs are valid if isValidated is True self.isValidated = False #Allows menu object to access these variables one defined self.startTime = None self.endTime = None self.timeInterval = None self.defaultVals = defaultVals #Explaining the paremeters of the input dialog explainLbl = gui.Label("Input your variables below") nOfResultsLbl = gui.Label("Have between 5-10 recordings") rangeStr = str("The time range is " + str(exp.minRange) + " to " + str(exp.maxRange)) rangeLbl = gui.Label(rangeStr) # THe labels for each input minIVUserLbl = gui.Label("Start Time") maxIVUserLbl = gui.Label("End Time") intervalUserLbl = gui.Label("Time Interval") # The input boxes minIVUserInput = gui.Input() maxIVUserInput = gui.Input() intervalIVUserInput = gui.Input() # The units for each input minIVUnitLbl = gui.Label("s") maxIVUnitLbl = gui.Label("s") intervalIVUnitLbl = gui.Label("s") #Standard width and height for buttons in this dialog buttonHeight = 50 buttonWidth = 120 #Making buttons then giving them functions okBtn = gui.Button("Enter",height=buttonHeight, width=buttonWidth) defaultBtn = gui.Button("Default Values",height=buttonHeight, width=buttonWidth) def okBtn_cb(): #Takes currently inputted values minIV = minIVUserInput.value maxIV = maxIVUserInput.value interval = intervalIVUserInput.value #Runs through validation algorithm isValidated,error = validation.validateInputs(minIV,maxIV,interval,exp.maxRange,exp.minRange) if not isValidated:#If they aren't valid # Show error errorDlg = template.ErrorDlg(error) self.open(errorDlg) else: if int(maxIV) - int(minIV) >= 200: #Set object variables self.isValidated = True self.startTime = int(minIV) self.endTime = int(maxIV) self.timeInterval = int(interval) self.close() else: errorDlg = template.ErrorDlg("Make the range at least 200") self.open(errorDlg) def defaultBtn_cb(): #A set of values if the user can't decide minIVUserInput.value = self.defaultVals[0] maxIVUserInput.value = self.defaultVals[1] intervalIVUserInput.value = self.defaultVals[2] #Links buttons with functions on click okBtn.connect(gui.CLICK,okBtn_cb) defaultBtn.connect(gui.CLICK,defaultBtn_cb) #Wraps all widgets into tables then put into one large table textTbl = gui.Table() inputTbl = gui.Table() buttonTbl = gui.Table() textTbl.tr() textTbl.td(explainLbl) textTbl.tr() textTbl.td(nOfResultsLbl) textTbl.tr() textTbl.td(rangeLbl) inputTblStyle = {'padding':10} inputTbl.tr() inputTbl.td(minIVUserLbl,style=inputTblStyle) inputTbl.td(minIVUserInput,style=inputTblStyle) inputTbl.td(minIVUnitLbl,style=inputTblStyle) inputTbl.tr() inputTbl.td(maxIVUserLbl,style=inputTblStyle) inputTbl.td(maxIVUserInput,style=inputTblStyle) inputTbl.td(maxIVUnitLbl,style=inputTblStyle) inputTbl.tr() inputTbl.td(intervalUserLbl,style=inputTblStyle) inputTbl.td(intervalIVUserInput,style=inputTblStyle) inputTbl.td(intervalIVUnitLbl,style=inputTblStyle) buttonTbl.tr() buttonTbl.td(okBtn,style=inputTblStyle) buttonTbl.td(defaultBtn,style=inputTblStyle) tbl = gui.Table() tbl.tr() tbl.td(textTbl) tbl.tr() tbl.td(inputTbl) tbl.tr() tbl.td(buttonTbl) gui.Dialog.__init__(self,gui.Label("Variables"),tbl)
def __init__(self, app): #Needs access to the app use open method self.app = app #The controlled variables materialLbl = gui.Label("Material: Constantan") CSALbl = gui.Label("Cross-Sectional Area: 2.01 x 10^-8") voltageLbl = gui.Label("Voltage:" + str(exp.voltage) + "V") dataTbl = gui.Table() dataTbl.tr() dataTbl.td(materialLbl) dataTbl.tr() dataTbl.td(CSALbl) dataTbl.tr() dataTbl.td(voltageLbl) #The equation needed equationImg = gui.Image(resM.resistivityEquations, width=210, height=150) defintionsImg = gui.Image(resM.resistivityDefinitions, width=210, height=150) imgTable = gui.Table() imgTable.td(equationImg) imgTable.td(defintionsImg) #The question questionLbl = gui.Label( "Find the resistivity of constantan using the equation above and the gradient of the graph" ) answerPrompt = gui.Label( "Select one of the options below then click answer") questionTable = gui.Table() questionTable.tr() questionTable.td(questionLbl) questionTable.tr() questionTable.td(answerPrompt) #The Options for answers optionsTbl = gui.Table() optionsGroup = gui.Group() correctAnswer = gui.Label("4.9 x 10^-7 Ωm") correctAnswerCheckBox = gui.Radio(optionsGroup, value=1) incorrectAnswer1 = gui.Label("6.7 x 10 ^ -11 Ωm") incorrectAnswer1CheckBox = gui.Radio(optionsGroup, value=2) incorrectAnswer2 = gui.Label("2.2 x 10 ^ -9 Ωm") incorrectAnswer2CheckBox = gui.Radio(optionsGroup, value=3) tdStyle = {'padding': 10} optionsTbl.td(correctAnswer, style=tdStyle) optionsTbl.td(incorrectAnswer1, style=tdStyle) optionsTbl.td(incorrectAnswer2, style=tdStyle) optionsTbl.tr() optionsTbl.td(correctAnswerCheckBox) optionsTbl.td(incorrectAnswer1CheckBox) optionsTbl.td(incorrectAnswer2CheckBox) #Checking User Answers checkAnswerBtn = gui.Button("Check Answer", width=100, height=30) def checkAnswer(): if optionsGroup.value == 1: dlg = gui.Dialog(gui.Label("Your answer was..."), gui.Label("Correct. Well Done")) else: dlg = gui.Dialog(gui.Label("Your answer was..."), gui.Label("Wrong. Try Again")) self.app.open(dlg) checkAnswerBtn.connect(gui.CLICK, checkAnswer) #Adding the labels to the table tbl = gui.Table() tbl.tr() tbl.td(dataTbl, style=tdStyle) tbl.tr() tbl.td(imgTable, style=tdStyle) tbl.tr() tbl.td(questionTable, style=tdStyle) tbl.tr() tbl.td(optionsTbl, style=tdStyle) tbl.tr() tbl.td(checkAnswerBtn, style=tdStyle) gui.Dialog.__init__(self, gui.Label("Question"), tbl)
def __init__(self,app): #Needs access to the app use open method self.app = app tdStyle = {'padding':10} #The controlled variables lbl1 = gui.Label("The equations below show the line the equation for the graph") dataTbl = gui.Table() dataTbl.tr() dataTbl.td(lbl1) #The equation needed equationImg = gui.Image(resM.radioactiveDecayEquations) imgTable = gui.Table() imgTable.td(equationImg) #The question questionLbl = gui.Label("Which radioactive isotope was used in this experiment?") questionTable = gui.Table() questionTable.tr() questionTable.td(questionLbl) #The Options for answers optionsTbl = gui.Table() optionsGroup = gui.Group() correctAnswer = gui.Label("Fermium - 252") correctAnswerCheckBox = gui.Radio(optionsGroup,value=1) incorrectAnswer1 = gui.Label("Gold - 196") incorrectAnswer1CheckBox = gui.Radio(optionsGroup,value=2) incorrectAnswer2 = gui.Label("Uranium - 236") incorrectAnswer2CheckBox = gui.Radio(optionsGroup,value=3) tdStyle = {'padding':10} optionsTbl.td(incorrectAnswer1,style = tdStyle) optionsTbl.td(incorrectAnswer2,style = tdStyle) optionsTbl.td(correctAnswer,style = tdStyle) optionsTbl.tr() optionsTbl.td(incorrectAnswer1CheckBox) optionsTbl.td(incorrectAnswer2CheckBox) optionsTbl.td(correctAnswerCheckBox) #Checking User Answers checkAnswerBtn = gui.Button("Check Answer",width=100,height=30) def checkAnswer(): if optionsGroup.value == 1: dlg = gui.Dialog(gui.Label("Your answer was..."),gui.Label("Correct. Well Done")) else: dlg = gui.Dialog(gui.Label("Your answer was..."),gui.Label("Wrong. Try Again")) self.app.open(dlg) checkAnswerBtn.connect(gui.CLICK,checkAnswer) #Adding the labels to the table tbl = gui.Table() tbl.tr() tbl.td(dataTbl,style = tdStyle) tbl.tr() tbl.td(imgTable,style = tdStyle) tbl.tr() tbl.td(questionTable,style = tdStyle) tbl.tr() tbl.td(optionsTbl,style = tdStyle) tbl.tr() tbl.td(checkAnswerBtn,style = tdStyle) gui.Dialog.__init__(self,gui.Label("Question"),tbl)
def __init__(self): #The method method = """<p> 1. This experiment is dependent on observations rather than a practical method<br> 2. The radioactive isotope shown is to be determined by you<br> 3. The undecayed nuclei will be red while the decayed are yellow<br> 4. When this isotope decays, it releases a electron and increases the proton number by one<br> 5. Therefore it is beta decay<br> 6. Take regular recordings of the number of undecayed nuclei<br> 7. Plot the ln(n of undecayed nuclei) against the time(x-axis)<br> 8. Rearrange and use the gradient to find the decay constant </p> """ #Adding the method to the document which html doc = html.HTML(method,width = 600) #Links to the useful websites link1 = "https://en.wikipedia.org/wiki/List_of_radioactive_isotopes_by_half-life#100_seconds" link2 = "http://www.a-levelphysicstutor.com/nucphys-radioactivity.php" link3 = "https://phet.colorado.edu/en/simulation/alpha-decay" pdf = "file:///D:/My%20Docs/School/Computer%20Science/Programming%20Project/physicssimulationapp/resources/Methods/RadioactiveDecay.pdf" #Linking websites to buttons def link1_cb(): webbrowser.open(link1) def link2_cb(): webbrowser.open(link2) def link3_cb(): webbrowser.open(link3) def link4_cb(): webbrowser.open(pdf) btnWidth = 200 btnHeight = 50 link1Btn = gui.Button("List of Radioactive Isotopes",width = btnWidth, height=btnHeight) link1Btn.connect(gui.CLICK,link1_cb) link2Btn = gui.Button("Information on Radioactivity",width = btnWidth, height=btnHeight) link2Btn.connect(gui.CLICK, link2_cb) link3Btn = gui.Button("Alternative Simulation",width = btnWidth, height=btnHeight) link3Btn.connect(gui.CLICK, link3_cb) link4Btn = gui.Button("Eduqas Practical Sheet", width=btnWidth, height=btnHeight) link4Btn.connect(gui.CLICK, link4_cb) #Adding buttons to the dialog tbl = gui.Table() tbl.tr() tbl.td(doc) tbl.tr() tbl.td(gui.Label("Links")) topBtnTbl = gui.Table() topBtnTbl.tr() topBtnTbl.td(link2Btn) topBtnTbl.td(link1Btn) bottomBtnTbl = gui.Table() bottomBtnTbl.tr() bottomBtnTbl.td(link3Btn) bottomBtnTbl.td(link4Btn) tbl.tr() tbl.td(topBtnTbl) tbl.tr() tbl.td(bottomBtnTbl) gui.Dialog.__init__(self,gui.Label("Instructions and Links"), tbl)