Skip to main content

"PUI" Python Declarative UI Framework

Project description

What is PUI

PUI is a declarative UI framework with two-way data binding

Installation

pip install QPUIQ

Get Started

Hello World

# example/hello_world.py

from PUI.PySide6 import *

class Example(Application):
    def content(self):
        with Window(title="test", size=(320,240)):
            Label("Hello world")

root = Example()
root.run()

Hello World

State & Data Binding

# example/pyside6_textfield.py

from PUI.PySide6 import *

data = State()
data.var = 0

class QtExample(QtApplication):
    def content(self):
        with QtWindow(title="blah"):
            with QtVBox():
                with QtHBox():
                    QtButton("-", self.on_minus)
                    QtLabel(f"{data.var}")
                    QtButton("+", self.on_plus)

                QtLineEdit(data("var")) # binding

    def on_minus(self):
        data.var -= 1

    def on_plus(self):
        data.var += 1

root = QtExample()
root.run()

State & Data Binding

View Component

# example/bleak_list.py

....

@PUI # View Component
def DeviceView(device, advertising_data):
    Label(f"{device.address} {device.name} {advertising_data.rssi}")

class GUI(Application):
    def __init__(self, state):
        super().__init__()
        self.state = state

    def content(self):
        with Window(title="BLE List"):
            with VBox():
                Label(f"Found {len(self.state.scanned_devices)} devices")
                for device, advertising_data in self.state.scanned_devices:
                    DeviceView(device, advertising_data)

....

View Component

Layout & Styling

# example/pyside6_feedparser.py

...
with VBox():
    Label(title).qt(StyleSheet="font-weight:bold") # QT-specific

    with HBox():
        with Scroll():
            with VBox():
                for i,e in enumerate(entries):
                    Label(e.title).click(self.entry_selected, i)
                Spacer()

        with Scroll().layout(weight=1): # Generic Layout Parameter
            if 0 <= selected and selected < len(entries):
                (Text(entries[selected].description)
                    .layout(padding=10) # Generic Layout Parameter
                    .qt(StyleSheet="background-color:white; color:black")) # QT-specific
...

Layout & Styling

Canvas

# example/pyside6_canvas.py

from PUI.PySide6 import *

data = State()
data.var = 50

class QtExample(QtApplication):
    def content(self):
        with QtWindow(title="blah", size=(640,480)):
            with QtVBox():
                QtCanvas(self.painter, data.var)
                with QtHBox():
                    QtButton("-", self.on_minus)
                    QtLabel(f"{data.var}")
                    QtButton("+", self.on_plus)

    @staticmethod
    def painter(canvas, var):
        canvas.drawText(var, var/2, f"blah {var}")
        canvas.drawLine(var, var, var*2, var*3)

    def on_minus(self):
        data.var -= 1

    def on_plus(self):
        data.var += 1

root = QtExample()
root.run()

Canvas

Cookbook

python -m cookbook PySide6 (requires pygments for syntax highlight)

Cookbook 1 Cookbook 2

python -m cookbook textual Cookbook textual

Hot-Reload with Reloadium

Hot-Reload with Reloadium

Backends

Tier-1

  • PySide6

Lower Priority

Generic Expression

Elements

  • HBox()
  • VBox()
  • Spacer()
  • Button(text)
    • .click(callback, *cb_args, **cb_kwargs)
  • Label(text)
    • .click(callback, *cb_args, **cb_kwargs)
  • TextField(binding)
  • ProgressBar(progress 0-1)
  • Scroll()
  • Canvas
    • .drawText(x, y, text)
    • .drawLine(x1, y1, x2, y2, color=0xFF0000, width=2)
    • .drawPolyline([x1, y2, ..., xn, yn], color=0xFF0000, width=2)

Layout

  • .layout(width=320, height=240, weight=1)

Hot Reload

Add these lines to your view file and run with reloadium

import reloadium

# reloadium: after_reload
def after_reload(actions):
    PUIView.reload()

TODO

  • Use threading.locals() instead of inspect
  • State
    • Update Trigger
    • Binding
    • StateList
    • StateDict
    • Lazy UI?
  • StateObject decorator
  • Adapters
    • Split Application/Window, multi-windows
    • UI Flow
      • Navigation Stack
      • View Router
      • Model Window/Dialog
    • Label
    • Button
    • TextField
    • TimelimeView
    • Layout
      • HBox
      • VBox
      • ZBox
      • Grid
        • Row
        • Column
      • SwiftUI style overlay ??
    • Canvas
      • Text
      • Line
      • Rect
      • Arc
      • Image
      • ...
    • Table
    • Tree
    • Scrollbar (or as a layout setting)
  • Better DOM syncer
    • Prevent unnecessary nested update
    • Trace Event Source (TextField) and prevent update it DOM Sync
  • Pydantic State

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

QPUIQ-0.2.1.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

QPUIQ-0.2.1-py3-none-any.whl (38.2 kB view details)

Uploaded Python 3

File details

Details for the file QPUIQ-0.2.1.tar.gz.

File metadata

  • Download URL: QPUIQ-0.2.1.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for QPUIQ-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ff922ea4f8c5847725c8ad83aefed5c784d1c1860b109c093edaa53354030e78
MD5 b9f5a0cc58d04ab2e7441dccc6732892
BLAKE2b-256 e315fd199947b523c8f5233f31f661d08c00ace430c537d05c082fa5942f0893

See more details on using hashes here.

File details

Details for the file QPUIQ-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: QPUIQ-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 38.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for QPUIQ-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 506403d41a369080dfd67655227c1ac2548583a2f6f19a788d86f77b289aa541
MD5 0c88d194a1b91b580cf73f84524ebced
BLAKE2b-256 8849b773b385b4531a3674ee7cbb3107cc88fd1b1a76d4597b62d411f0210215

See more details on using hashes here.

Supported by

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