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 __init__(self, disp): super(AnimationEngine, self).__init__(disp) self.app = exp.Experiment(self.disp) self.app.engine = self self.rect = self.app.get_render_area() self.startHeight = None self.endHeight = None self.heightInterval = None self.currentHeight = None self.runStarted = True self.equipment = pygame.sprite.Group() self.ruler = MEquip.Ruler(110, 5, 380) self.ball = MEquip.Ball(100, 375, 20) self.clampStand = MEquip.ClampStand(115, 0, 400) self.equipment.add(self.ruler) self.equipment.add(self.ball) self.equipment.add(self.clampStand) self.rulerLabel = template.DiagramLabelPointToPoint( (325, 30), (self.ruler.rect.right, 30), False, False, "Ruler") self.clampLabel = template.DiagramLabelPointToPoint( (325, 100), (250, 100), False, False, "Clamp Stand")
def okBtn_cb(): #Takes currently inputted values minIV = minIVUserInput.value maxIV = maxIVUserInput.value interval = intervalIVUserInput.value #Runs through validation algorithm self.isValidated, error = validation.validateInputs( minIV, maxIV, interval, exp.maxRange, exp.minRange) if not self.isValidated: #If they aren't valid # Show error errorDlg = template.ErrorDlg(error) self.open(errorDlg) else: #Set object variables if int(maxIV) - int(minIV) > 100: self.isValidated = True self.minIVValue = int(minIV) self.maxIVValue = int(maxIV) self.intervalValue = int(interval) self.close() else: errorDlg = template.ErrorDlg( "Have a range of at least 100") errorDlg.open()
def startExperiment_cb(): if self.variablesDlg.isValidated: # If the user inputs are valid if not (self.app.animationRunning ): # And if the animation hasn't started yet self.app.animationRunning = True # Tell the rest of the program that the animation can now run else: errorDlg = template.ErrorDlg( "Experiment is already running") errorDlg.open() else: errorDlg = template.ErrorDlg("You haven't set the variables") errorDlg.open()
def graph_cb(): if self.app.experimentFinished: graphDlg = dlgs.GraphDialog(self.app.tableArea) self.open(graphDlg) else: errorDlg = template.ErrorDlg("Finish the Experiment") self.app.open(errorDlg)
def __init__(self, screen): super(Experiment, self).__init__(screen) gui.Desktop.__init__(self) self.connect(gui.QUIT, self.quit) self.engine = None self.animationAreaWidth = 650 self.animationAreaHeight = 400 self.animationArea = template.DrawingArea(self.animationAreaWidth, self.animationAreaHeight) self.menuArea = areaObjects.MenuArea( screen.get_width() - self.animationAreaWidth, self.animationAreaHeight, self) self.tableArea = areaObjects.TableArea(screen.get_width(), 200, self) topTbl = gui.Table() topTbl.tr() topTbl.td(self.animationArea) topTbl.td(self.menuArea) screenTbl = gui.Table(height=screen.get_height(), width=screen.get_width()) screenTbl.tr() screenTbl.td(topTbl) screenTbl.tr() screenTbl.td(self.tableArea) self.init(screenTbl, screen)
def okBtn_cb(): #Takes currently inputted values if optionsGroup.value == 1: interval = "50" elif optionsGroup.value == 2: interval = "100" elif optionsGroup.value == 3: interval = "150" else: interval = "" cartWeights = minIVUserInput.value massHolderWeights = maxIVUserInput.value #Runs through validation algorithm self.isValidated,error = validation.validateNewton2ndLaw(cartWeights,massHolderWeights,interval,exp.minRange,exp.maxRange) if not self.isValidated:#If they aren't valid # Show error errorDlg = template.ErrorDlg(error) self.open(errorDlg) else: #Set object variables self.isValidated = True self.cartWeights = int(cartWeights) self.massHolderWeights = int(massHolderWeights) self.weightSize = round(int(interval) /1000,2) self.close()
def __init__(self, disp): super(AnimationEngine, self).__init__(disp) self.app = exp.Experiment(self.disp) self.app.engine = self self.rect = self.app.get_render_area() self.beaker = pEquip.WaterBeaker(self.rect.centerx, self.rect.centery, self.rect.height - 50) self.pressureGauge = pEquip.PressureGauge(self.beaker.rect.right - 63, self.rect.centery, 50) self.thermometer = pEquip.Thermometer(self.beaker.rect.left + 55, self.rect.centery, 300) self.bulbBeaker = pEquip.BulbBeaker(self.thermometer.minTemp, self.thermometer.maxTemp) self.equipment = pygame.sprite.Group() self.equipment.add(self.beaker) self.equipment.add(self.pressureGauge) self.equipment.add(self.thermometer) self.currentTemp = 20 self.pressure = self.genValues() # Get values for pressure self.thermometer.setupMarker(self.disp, self.currentTemp) self.pressureGauge.setupPointer(self.genValues(), self.disp) self.isSetup = False self.endTempCalculated = False thermometerLbl = template.DiagramLabel(self.thermometer.rect.left - 70, self.thermometer.rect.centery, self.thermometer, False, False, "Thermometer") pressureGaugeLbl = template.DiagramLabel( self.pressureGauge.rect.centerx, self.pressureGauge.rect.bottom + 60, self.pressureGauge, True, False, "Pressure Gauge") bulbBeakerLbl = template.DiagramLabel(self.bulbBeaker.rect.centerx, self.bulbBeaker.rect.bottom + 40, self.bulbBeaker, True, False, "Bulb Beaker") self.labels = [] self.labels.append(thermometerLbl) self.labels.append(pressureGaugeLbl) self.labels.append(bulbBeakerLbl)
def graph_cb(): if self.app.experimentFinished: xPoints = self.app.tableArea.xPoints yPoints = self.app.tableArea.yPoints graphDlg = dlgs.GraphDialog(xPoints, yPoints) self.open(graphDlg) else: errorDlg = template.ErrorDlg("Finish the Experiment") self.app.open(errorDlg)
def variables_cb(): if not self.app.variablesInputted: self.variablesDlg.open() if self.variablesDlg.isValidated: #Updates the values of the Experiment Object self.app.variablesInputted = True self.app.minIV = self.variablesDlg.minIVValue self.app.maxIV = self.variablesDlg.maxIVValue self.app.interval = self.variablesDlg.intervalValue self.app.tableArea.setup() else: self.app.open(template.ErrorDlg("You have already inputted variables."))
def variables_cb(): if not self.app.variablesInputted: self.variablesDlg.open() if self.variablesDlg.isValidated: # Updates the values of the Experiment Object self.app.variablesInputted = True self.app.engine.startHeight = self.variablesDlg.startHeight self.app.engine.endHeight = self.variablesDlg.endHeight self.app.engine.heightInterval = self.variablesDlg.heightInterval self.app.tableArea.setup() else: self.app.open( template.ErrorDlg("You have already inputted variables."))
def variables_cb(): if not self.app.variablesInputted: self.variablesDlg.open() if self.variablesDlg.isValidated: #Updates the values of the Experiment Object self.app.variablesInputted = True self.app.engine.cartWeights = self.variablesDlg.cartWeights self.app.engine.massHolderWeights = self.variablesDlg.massHolderWeights self.app.engine.weightSize = self.variablesDlg.weightSize self.app.tableArea.setup() else: self.app.open( template.ErrorDlg("You have already inputted variables."))
def render(self, rect): self.disp.fill( colours.BLUE) # Background Colour to complement menu colour self.equipment.draw(self.disp) if self.app.showLabels: ballLabel = template.DiagramLabel(self.ball.rect.left - 40, self.ball.rect.centery, self.ball, False, False, "Ball") self.rulerLabel.draw(self.disp) self.clampLabel.draw(self.disp) ballLabel.draw(self.disp) if not self.isSetup and self.app.variablesInputted: self.setExperimentVariables() self.isSetup = True if not self.isPaused and self.app.animationRunning and not self.app.experimentFinished: if not self.runStarted: if self.currentHeight < self.endHeight: #Until currentHeight == endHeight self.currentHeight += self.heightInterval self.setBall( ) # self.ball.rect.bottom = self.ruler.getStartPositionY(self.currentHeight,400) self.runStarted = True elif self.currentHeight == self.endHeight: #Last Iteration of self.setBall() print("Ball Bottom:", self.ball.rect.bottom) print("Ruler Top:", self.ruler.rect.top) self.runStarted = True else: self.ball.setSpeed(self.time) if self.ball.rect.bottom < self.ruler.rect.bottom: self.ball.move() else: self.ball.rect.bottom = self.ruler.rect.bottom self.runStarted = False self.sendValues(self.getTime()) pygame.time.wait(100) if self.currentHeight == self.endHeight and self.ball.rect.bottom == self.ruler.rect.bottom: self.app.experimentFinished = True self.time += 1 / 2 return rect, # Give back rect that has been drawn on
def __init__(self, disp): super(AnimationEngine, self).__init__(disp) self.app = exp.Experiment(self.disp) self.app.engine = self self.rect = self.app.get_render_area() self.startTime = None self.endTime = None self.interval = None self.currentTime = 0 self.nextRecordPoint = 0 self.wireColour = colours.BLACK self.block = sEquip.CopperBlock(10, 100, 400, 300) self.block.insertThermometer() self.block.insertHeater() self.blockRight = self.block.x + self.block.width midBetweenBlockAndEdge = self.block.x + self.block.width + ( self.rect.right - (self.block.x + self.block.width)) // 2 batteryFactor = 1 ammeterFactor = 40 voltmeterFactor = 40 self.battery = eEquip.Battery(midBetweenBlockAndEdge, self.rect.bottom - 60, int(57 * batteryFactor), int(48 * batteryFactor)) self.ammeter = eEquip.Ammeter(self.rect.right - 30, self.rect.centery, int(ammeterFactor * 1)) self.voltmeter = eEquip.Voltmeter(midBetweenBlockAndEdge, 100, int(voltmeterFactor * 1)) self.equipment = pygame.sprite.Group() self.equipment.add(self.block.thermometer) self.equipment.add(self.block.heater) self.equipment.add(self.ammeter) self.equipment.add(self.voltmeter) self.equipment.add(self.battery) self.block.thermometer.setupMarker(self.disp, 20) self.arrowGroup = pygame.sprite.Group() nOfArrows = 7 spacing = 30 y = self.block.y for i in range(nOfArrows): if i == nOfArrows - 1: x = self.block.heaterBasePoint y += spacing angle = 90 elif i % 2 == 0: x = self.block.heaterBasePoint - 40 y += spacing angle = 0 else: x = self.block.heaterBasePoint + 40 angle = 180 a = sEquip.HeatArrow(x, y, angle, 2) self.arrowGroup.add(a) thermometerLabel = template.DiagramLabel( self.block.thermometerBasePoint, self.rect.bottom - 40, self.block.thermometer, True, False, "Thermometer") heaterLabel = template.DiagramLabel(self.block.heaterBasePoint, self.rect.bottom - 30, self.block.heater, True, False, "Heater") blockLabel = template.DiagramLabelPointToPoint( (70, 30), (70, self.block.y), True, True, "1kg Metal Block") ammeterReading = template.DiagramLabel(midBetweenBlockAndEdge, self.ammeter.centerY, self.ammeter, False, False, "Reading: 4A") voltemeterReading = template.DiagramLabel(midBetweenBlockAndEdge, self.voltmeter.centerY - 40, self.voltmeter, True, True, "Reading: 10V") self.labels = [] self.labels.append(thermometerLabel) self.labels.append(heaterLabel) self.labels.append(blockLabel) self.labels.append(ammeterReading) self.labels.append(voltemeterReading)