def build(self): # Will hold the painting canvas and the buttons (could also use layout) parent = Widget() self.painter = MyPaintWidget() # Create the necessary buttons circle = Button(text='Circle') rect = Button(text='Rectangle') triangle = Button(text='Triangle') clear = Button(text='Clear') circle.set_center_y(150) rect.set_center_y(250) triangle.set_center_y(350) # Bind the buttons' on release events to callback functions circle.bind(on_release=self.painter.add_circle) rect.bind(on_release=self.painter.add_rect) triangle.bind(on_release=self.painter.add_triangle) clear.bind(on_release=self.clear_canvas) # Make the canvas and the button children of the dummy widget parent.add_widget(self.painter) parent.add_widget(circle) parent.add_widget(rect) parent.add_widget(triangle) parent.add_widget(clear) return parent
def build(self): # The parent widget that will hold everything parent = Widget() # Create the simulation self.simulation = GravitySimulation() # Add the haptic mouse avatar self.simulation.add_cursor() # Schedule a simulation update every 100 hz Clock.schedule_interval(self.simulation.update, 1.0 / 100.0) # This button will clear the canvas of any circles clear = Button(text="clear") clear.bind(on_release=self.clear_canvas) # This button will increase the force of gravity increase = Button(text="+") increase.bind(on_release=self.increase_gravity) # This button will decrease the force of gravity decrease = Button(text="-") decrease.bind(on_release=self.decrease_gravity) # Position the buttons increase.set_center_y(150) decrease.set_center_y(250) # Add widgets to the main parent widget parent.add_widget(self.simulation) parent.add_widget(clear) parent.add_widget(increase) parent.add_widget(decrease) # Tell server we're ready self.simulation.socket.send_string("ready") return parent
def build(self): # The parent widget that will hold everything parent = Widget() # Create the canvas simulation self.simulation = Simulation() # Schedule a simulation update every 100 hz Clock.schedule_interval(self.simulation.update, 1.0 / 100.0) # This button will clear the canvas of any circles clear = Button(text="clear") clear.bind(on_release=self.clear_canvas) # This button will add a rectangle rect = Button(text="rect") rect.bind(on_release=lambda s: self.simulation.add_shape("rect")) # This button will add a circle circle = Button(text="circle") circle.bind(on_release=lambda s: self.simulation.add_shape("circle")) # This button will add a triangle triangle = Button(text="triangle") triangle.bind(on_release=lambda s: self.simulation.add_shape("triangle")) # Position the buttons rect.set_center_y(150) circle.set_center_y(250) triangle.set_center_y(350) # Add widgets to the main parent widget parent.add_widget(self.simulation) parent.add_widget(clear) parent.add_widget(rect) parent.add_widget(circle) parent.add_widget(triangle) # Tell server we're ready # self.simulation.socket.send_string("ready") return parent