Examples#

Calculator#

It’s easy to create a good-looking program with Edifice. In this example, we imitate the look of the MacOS Calculator app in 100 lines of code (most of which is implementing the calculator state machine).

The code is available at calculator.py.

_images/example_calculator.png
Run in Python environment#
python examples/calculator.py
Run in Python environment with Edifice Runner#
python -m edifice --inspect examples/calculator.py Main
Run with Nix#
nix run github:pyedifice/pyedifice#example-calculator

Financial Charting#

In this example, we create a reactive charting application with Edifice. We allow arbitrary number of plots to be made on the same axis. For each plot, the source for the x-axis and y-axis data can be specified by the user. The source data could be the date, the close price, or the volume of a stock. The data in each axis can also be transformed by an EMA operator, which computes a moving average over the past n days (with n adjustable by a slider). And of course, everything is reactive — there’s no “plot” button that the user needs to press to render the chart.

All this is possible in under 200 lines of code and straightforward logic: there’s an underlying description of everything that is plotted. This description is shown to the user in two ways: the “textual” description via dropdowns and input elements, and a visual rendering in the form of a graph. Users can interact with the textual display and thereby update the plot description.

The code is available at financial_charts.py.

_images/example_financial_charting1.png
_images/example_financial_charting2.png
Run in Python environment#
python examples/financial_charts.py
Run in Python environment with Edifice Runner#
python -m edifice --inspect examples/financial_charts.py Main
Run with Nix#
nix run github:pyedifice/pyedifice#example-financial-charting

TodoMVC#

An implementation of TodoMVC in Edifice.

TodoMVC is a simple todo list program written in many JavaScript frameworks, so that web developers can compare the frameworks by comparing the TodoMVC implementations.

For comparison, the Edifice TodoMVC program is available at todomvc.py.

_images/example_todomvc.png
Run in Python environment#
python examples/todomvc.py
Run in Python environment with Edifice Runner#
python -m edifice --inspect examples/todomvc.py Main
Run with Nix#
nix run github:pyedifice/pyedifice#example-todomvc

Harmonic Oscillator#

An example showing animation. The animation was rendered at 30 FPS (the GIF is only at 12 FPS so you won’t be able to tell). You can interactively set the frequency and damping factors and instantly see the result, both in a graph and in the animation. Python of course has great numeric libraries, so we can work with complex numbers.

The code is available at harmonic_oscillator.py.

_images/example_harmonic_oscillator.gif
Run in Python environment#
python examples/harmonic_oscillator.py
Run in Python environment with Edifice Runner#
python -m edifice --inspect examples/harmonic_oscillator.py Main
Run with Nix#
nix run github:pyedifice/pyedifice#example-harmonic-oscillator