def buttonPressed(self, buttonID): if buttonID == "cartesianGrid": self.cartesian = True self.polar = False self.buttons["cartesianGrid"].setState(True) self.buttons["polarGrid"].setState(False) elif buttonID == "polarGrid": self.cartesian = False self.polar = True self.buttons["cartesianGrid"].setState(False) self.buttons["polarGrid"].setState(True) elif buttonID == "snapToGrid": self.snapGrid = not self.snapGrid self.buttons["snapToGrid"].setState(self.snapGrid) elif buttonID == "snapToPoint": self.snapPoint = not self.snapPoint self.buttons["snapToPoint"].setState(self.snapPoint) elif buttonID == "point": if self.pointAdding: self.pointAdding = False else: self.pointAdding = True self.pinAdding = False self.segmentAdding = False self.buttons["pin"].setState(False) self.buttons["segment"].setState(False) self.buttons["point"].setState(self.pointAdding) elif buttonID == "pin": if self.pinAdding: self.pinAdding = False else: self.pinAdding = True self.segmentAdding = False self.pointAdding = False self.buttons["point"].setState(False) self.buttons["segment"].setState(False) self.buttons["pin"].setState(self.pinAdding) elif buttonID == "segment": if self.segmentAdding: self.segmentAdding = False else: self.segmentAdding = True self.pointAdding = False self.pinAdding = False self.buttons["point"].setState(False) self.buttons["pin"].setState(False) self.buttons["segment"].setState(self.segmentAdding) elif buttonID == "undo": if len(self.allGeometry) > 0: self.allGeometry.pop() elif len(self.prevGeometry) > 0: for geom in self.prevGeometry: self.allGeometry.append(geom) self.prevGeometry = [] self.buttons["undo"].setState(True) elif buttonID == "delete": if len(self.allGeometry) > 0: for geom in self.allGeometry: self.prevGeometry.append(geom) self.allGeometry = [] self.buttons["delete"].setState(True) elif buttonID == "run": if not self.runningSimulation: if len(self.allGeometry) > 0: self.diagram, self.varList, self.angleDict = StaticDrawing.makeDiagram( self.allGeometry, self.origin ) self.traj, tempLag = Driver.drive(self.diagram, self.varList, self.angleDict) frame = DisplayLagrangeWindow(None, "Euler-Lagrange Equations", tempLag) # app.MainLoop() self.runSimulationStart() self.buttons["run"].setState(True) else: if self.simulationPaused: self.simulationPaused = False self.buttons["pause"].setState(False) elif buttonID == "pause": if self.runningSimulation: self.simulationPaused = not self.simulationPaused self.buttons["pause"].setState(self.simulationPaused) elif buttonID == "restart": if self.runningSimulation: self.runningSimulation = False self.buttons["run"].setState(False) self.buttons["pause"].setState(False)
def buttonPressed(self, buttonID): if buttonID == "cartesianGrid": self.cartesian = True self.polar = False self.buttons["cartesianGrid"].setState(True) self.buttons["polarGrid"].setState(False) elif buttonID == "polarGrid": self.cartesian = False self.polar = True self.buttons["cartesianGrid"].setState(False) self.buttons["polarGrid"].setState(True) elif buttonID == "snapToGrid": self.snapGrid = not self.snapGrid self.buttons["snapToGrid"].setState(self.snapGrid) elif buttonID == "snapToPoint": self.snapPoint = not self.snapPoint self.buttons["snapToPoint"].setState(self.snapPoint) elif buttonID == "point": if self.pointAdding: self.pointAdding = False else: self.pointAdding = True self.pinAdding = False self.segmentAdding = False self.buttons["pin"].setState(False) self.buttons["segment"].setState(False) self.buttons["point"].setState(self.pointAdding) elif buttonID == "pin": if self.pinAdding: self.pinAdding = False else: self.pinAdding = True self.segmentAdding = False self.pointAdding = False self.buttons["point"].setState(False) self.buttons["segment"].setState(False) self.buttons["pin"].setState(self.pinAdding) elif buttonID == "segment": if self.segmentAdding: self.segmentAdding = False else: self.segmentAdding = True self.pointAdding = False self.pinAdding = False self.buttons["point"].setState(False) self.buttons["pin"].setState(False) self.buttons["segment"].setState(self.segmentAdding) elif buttonID == "undo": if len(self.allGeometry) > 0: self.allGeometry.pop() elif len(self.prevGeometry) > 0: for geom in self.prevGeometry: self.allGeometry.append(geom) self.prevGeometry = [] self.buttons["undo"].setState(True) elif buttonID == "delete": if len(self.allGeometry) > 0: for geom in self.allGeometry: self.prevGeometry.append(geom) self.allGeometry = [] self.buttons["delete"].setState(True) elif buttonID == "run": if len(self.allGeometry) > 0: self.diagram, self.varList, self.angleDict = StaticDrawing.makeDiagram(self.allGeometry, self.origin) self.traj = Driver.drive(self.diagram, self.varList, self.angleDict) self.runSimulationStart() self.buttons["run"].setState(True)