Skip to main content

Reactive user interfaces

Project description

PyPI version CI status

Collagraph 📓

Reactive user interfaces.

The word Collagraphy is derived from the Greek word koll or kolla, meaning glue, and graph, meaning the activity of drawing.

Inspired by Vue and React.

Features

Write your Python interfaces in a declarative manner with plain render functions, component classes or even single-file components using Vue-like syntax, but with Python!

  • Reactivity (made possible by leveraging observ)
  • Function components
  • Class components with local state and life-cycle methods/hooks
  • Single-file components with Vue-like syntax (.cgx files)
  • Custom renderers

Here is an example that shows a simple counter, made with a function component:

from PySide6 import QtWidgets
from observ import reactive
import collagraph as cg

# Declare some reactive state
state = reactive({"count": 0})

# Define function that adjusts the state
def bump():
    state["count"] += 1

# Declare how the state should be rendered
def Counter(props):
    return cg.h(
        "widget",
        {},
        cg.h("label", {"text": f"Count: {props['count']}"}),
        cg.h("button", {"text": "Bump", "on_clicked": bump}),
    )

# Create a Collagraph instance with a PySide renderer 
# and register with the Qt event loop
gui = cg.Collagraph(
    renderer=cg.PySideRenderer(),
    event_loop_type=cg.EventLoopType.QT,
)
# Render the function component into a container 
# (in this case the app but can be another widget)
app = QtWidgets.QApplication()
gui.render(cg.h(Counter, state), app)
app.exec()

For more examples, please take a look at the examples folder.

Currently there are two renderers:

It is possible to create a custom Renderer using the Renderer interface, to render to other UI frameworks, for instance wxPython, or even the browser DOM.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

collagraph-0.3.0.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

collagraph-0.3.0-py3-none-any.whl (31.8 kB view details)

Uploaded Python 3

File details

Details for the file collagraph-0.3.0.tar.gz.

File metadata

  • Download URL: collagraph-0.3.0.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for collagraph-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5133da0c3b2e4de36ccfa8af74ea900f7d65fb8f01a667fce2a5a526ecb26a71
MD5 1ac204e7fa3565cd98318dff1d4da850
BLAKE2b-256 03fb99fc68e26c7887a6795258749511b9b418789cbc42d9e5ba449259063604

See more details on using hashes here.

File details

Details for the file collagraph-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: collagraph-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 31.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for collagraph-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14560428f44aa506693bdf6e59b669cd22851f755fb7b3904f930e45a47e570a
MD5 5c120084c6693d2e4f27b1328027ee9a
BLAKE2b-256 5aec3522374f9f4e4a7d231aa50723b9686ac7e5373deb1230386105aad70034

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page