Esempio n. 1
0
 def test_form_render(self):
     class Color(enum.Enum):
         RED = 1,
         BLUE = 2,
     data = edifice.StateManager({
         "a": 1,
         "b": "b",
         "c": 1.0,
         "d": (1, [1, 2, 3, 4]),
         "e": Color.RED,
         "f": datetime.date(1970, 1, 1),
         "g": lambda data: data["a"] + data["c"],
         "h": pathlib.Path("."),
         "i": True,
     })
     label_map = {
         "a": "A",
         "b": "B",
         "c": "C",
         "d": "D",
         "e": "E",
         "f": "F",
         "g": "G",
         "h": "H",
         "i": "I",
     }
     form = forms.Form(data, layout=["a", ["b", "c", "d"], ["e"], "f", "g", "h", "i"], defaults={"a": 1}, label_map=label_map)
     my_app = edifice.App(form, create_application=False)
     class MockQtApp(object):
         def exec_(self):
             pass
     my_app.app = MockQtApp()
     my_app.start()
Esempio n. 2
0
    def test_figure(self):
        my_app = edifice.App(plotting.Figure(lambda x: None),
                             create_application=False)

        class MockQtApp(object):
            def exec_(self):
                pass

        my_app.app = MockQtApp()
        my_app.start()
Esempio n. 3
0
            self.timer.stop()
        else:
            self.timer.start(50)
        self.set_state(playing=not self.playing)

    def render(self):
        return ed.View(layout="column")(
            ed.View(layout="row",
                    style={
                        "align": "left",
                        "margin-left": "10px"
                    })(
                        ed.Icon(name="chart-line", size=14).set_key("Icon"),
                        ed.Label("Market Data Viewer",
                                 style={
                                     "margin-left": "5px"
                                 }).set_key("Label"),
                        ed.IconButton(
                            name="pause" if self.playing else "play",
                            style=stylesheet.play_button,
                            size=10,
                            on_click=self.play,
                        ).set_key("Play"),
                    ).set_key("Controls"),
            Book(self.book).set_key("Book"),
        )


if __name__ == "__main__":
    ed.App(App(), inspector=True).start()
Esempio n. 4
0
import edifice as ed
from edifice.components.forms import FormDialog


class Color(enum.Enum):
    RED = 0
    GREEN = 1
    BLUE = 2


form_data = ed.StateManager({
    "Value 1":
    0.1,
    "Value 2":
    1.1,
    "Value 3":
    1.3,
    "Color":
    Color.RED,
    "File":
    pathlib.Path(""),
    "Date":
    datetime.date(1970, 1, 1),
    "Sum":
    lambda d: d["Value 1"] + d["Value 2"] + d["Value 3"]
})

ed.App(FormDialog(form_data)).start()
print(form_data.as_dict())
                        "min-width": "25px",
                        "max-width": "25px"
                    }).set_key("0"),
                ed.Label("%.02f" % t).set_key("1"),
            )


class MainComponent(ed.Component):
    @ed.register_props
    def __init__(self, level=2):
        super().__init__()
        self.t = ed.StateValue(5)

    def did_mount(self):
        self.timer = ed.Timer(self.increment_time)
        self.timer.start(16)

    def will_unmount(self):
        self.timer.stop()

    def increment_time(self):
        self.t.set(self.t.value + 0.016)
        # self.set_state(t=self.t + 0.016)

    def render(self):
        return RecurseTree(level=7, t=self.t)


if __name__ == "__main__":
    ed.App(MainComponent()).start()
Esempio n. 6
0
    @ed.register_props
    def __init__(self, from_unit, to_unit, factor):
        super().__init__()
        self.current_text = "0.0"

    def render(self):
        from_text = self.current_text
        to_text = "%.3f" % (str_to_float(from_text) * self.props.factor)

        from_label_style = {"width": 170}
        to_label_style = {"margin-left": 20, "width": 200}
        input_style = {"padding": 2, "width": 120}
        return ed.View(layout="row", style={"margin": 10, "width": 560})(
            Label(f"Measurement in {self.props.from_unit}:", style=from_label_style),
            TextInput(from_text, style=input_style,
                      on_change=lambda text: self.set_state(current_text=text)),
            Label(f"Measurement in {self.props.to_unit}: {to_text}", style=to_label_style),
        )

class MyApp(ed.Component):

    def render(self):
        return ed.View(layout="column", style={})(
            ConversionWidget("meters", "feet", METERS_TO_FEET),
            ConversionWidget("feet", "meters", 1 / METERS_TO_FEET),
        )

if __name__ == "__main__":
    ed.App(MyApp()).start()
Esempio n. 7
0
                                  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"
                             }),
                )))


if __name__ == "__main__":
    ed.App(Oscillator()).start()
Esempio n. 8
0
                ed.Label(self.display, style=display_style),
                ed.GridView(layout="""cs%/
                                      789*
                                      456-
                                      123+
                                      00.=""")(
                    unary_button("AC").set_key("c"),
                    unary_button("+/-").set_key("s"),
                    unary_button("%").set_key("%"),
                    binary_button("÷").set_key("/"),
                    digit_button(7).set_key("7"),
                    digit_button(8).set_key("8"),
                    digit_button(9).set_key("9"),
                    binary_button("×").set_key("*"),
                    digit_button(4).set_key("4"),
                    digit_button(5).set_key("5"),
                    digit_button(6).set_key("6"),
                    binary_button("-").set_key("-"),
                    digit_button(1).set_key("1"),
                    digit_button(2).set_key("2"),
                    digit_button(3).set_key("3"),
                    binary_button("+").set_key("+"),
                    digit_button(0, double_width=True).set_key("0"),
                    digit_button(".").set_key("."),
                    binary_button("=").set_key("="),
                )))


if __name__ == "__main__":
    ed.App(Calculator()).start()
Esempio n. 9
0
import edifice
from edifice import View, Label, TextInput

class App(edifice.Component):
    def __init__(self):
        super(App, self).__init__()
        self.text = ""

    def render(self):
        return View(layout="column")(
            Label("Hello world: " + self.text),
            TextInput(self.text, on_change=lambda text: self.set_state(text=text)),
            View(layout="row")(
                Label("Bonjour")
            )
        )

if __name__ == "__main__":
    edifice.App(App()).start()