Beispiel #1
0
 def digit_button(digit, double_width=False):
     # Create digits buttons, include the decimal point
     button_style = digits_style.copy()
     if double_width:
         button_style["width"] = 2 * button_style["width"]
     return ed.Button(str(digit),
                      style=button_style,
                      on_click=make_add_digit(digit))
Beispiel #2
0
        def unary_button(symbol):
            def apply_unary_operand(operator):
                with self.render_changes():
                    self.clear_display = True
                    self.display = "%.4f" % OPERATORS[operator](float(
                        self.display))

            return ed.Button(symbol,
                             style=unary_style,
                             on_click=lambda e: apply_unary_operand(symbol))
Beispiel #3
0
 def render(self):
     return ed.View()(
         ed.Label(self.a),
         ed.Label(self.b),
         ed.Slider(self.a,
                   min_value=0,
                   max_value=1,
                   on_change=self._on_change),
         ed.Button("Update b",
                   on_click=lambda e: self.set_state(b=self.b + 1)),
     )
Beispiel #4
0
 def render(self):
     return ed.View(layout="row")(
         ed.View(layout="column", style={
             "width": 720,
             "margin": 10
         })(
             ed.View(layout="row")(
                 ed.IconButton("pause" if self.is_playing else "play",
                               on_click=lambda e: self.set_state(
                                   is_playing=not self.is_playing)),
                 ed.Button(
                     "Reset",
                     on_click=lambda e: self.set_state(simulation_time=0)),
             ),
             plotting.Figure(lambda figure: self.plot(figure)),
             ed.View(layout="row", style={"margin": 10})(
                 ed.Label("Angular Frequency"),
                 ed.Slider(value=self.angular_frequency,
                           min_value=1,
                           max_value=10,
                           on_change=lambda value: self.set_state(
                               angular_frequency=value, simulation_time=0)),
                 ed.Label("Damping Factor"),
                 ed.Slider(value=self.damping,
                           min_value=-3,
                           max_value=0,
                           on_change=lambda value: self.set_state(
                               damping=value, simulation_time=0)),
             ),
             # We position the ball and the centroid using absolute positioning.
             # The label and ball offsets are different since we have to take into-account the size of the ball
             ed.View(layout="none",
                     style={
                         "width": 720,
                         "height": 10,
                         "margin-top": 40
                     })
             (
                 ed.Icon("bowling-ball",
                         size=20,
                         color=(255, 0, 0, 255),
                         style={
                             "left":
                             350 + 200 * self.calculate_harmonic_motion(
                                 self.simulation_time)
                         }),
                 ed.Label("|",
                          style={
                              "left": 356,
                              "font-size": 20,
                              "color": "blue"
                          }),
             )))
Beispiel #5
0
 def binary_button(symbol):
     # Qt layout is sometimes unintuitive, but you can definitely hack around it!
     button_style = binary_style.copy()
     return ed.Button(symbol,
                      style=button_style,
                      on_click=lambda e: apply_binary_operand(symbol))