"PUI" Python Declarative UI Framework
Project description
What is PUI
PUI is a declarative UI framework with two-way data binding. PUI doesn't do UI itself, it turns imperative UI libraries into declarative flavor with virtual DOM and aims to maintain interoperability.
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()
State & Data Binding
# example/generic_textfield.py
from PUI.PySide6 import *
data = State()
class Example(Application):
def __init__(self):
super().__init__()
data.var = 0
def content(self):
with Window(title="blah"):
with VBox():
with HBox():
Button("-").click(self.on_minus)
Label(f"{data.var}")
Button("+").click(self.on_plus)
TextField(data("var")) # binding
def on_minus(self):
data.var -= 1
def on_plus(self):
data.var += 1
root = Example()
root.run()
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)
....
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
...
Canvas
# example/generic_canvas.py
from PUI.PySide6 import *
data = State()
class Example(Application):
def __init__(self):
super().__init__()
data.var = 50
def content(self):
with Window(title="blah", size=(640,480)):
with VBox():
Canvas(self.painter, data.var)
with HBox():
Button("-").click(self.on_minus)
Label(f"{data.var}").layout(weight=1)
Button("+").click(self.on_plus)
@staticmethod
def painter(canvas, var):
canvas.drawText(var, var/2, f"blah {var}")
canvas.drawLine(var, var, var*2, var*3, color=0xFFFF00)
def on_minus(self):
data.var -= 1
def on_plus(self):
data.var += 1
root = Example()
root.run()
Cookbook
python -m cookbook PySide6
(requires pygments for syntax highlight)
python -m cookbook textual
python -m cookbook flet
python -m cookbook tkinter
Hot-Reload with Reloadium
Backends
Tier-1
- PySide6
Lower Priority
- tkinter
- flet
- textual (Text Mode)
- no canvas
Components
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
- Toga
- [ISSUE] empty virtual node
- [ISSUE] textual layout sizing (cookbook scroll example)
- [ISSUE] flet layout sizing (cookbook scroll example)
- nested state trigger
- set state in PUIView init
- set state in setup() ?
- Tabs(
tabposition
) - Lazy List
- StateObject decorator
- UI Flow
- Navigation Stack
- View Router
- Model Window/Dialog
- Layout
- ZBox
- Grid
- Row
- Column
- SwiftUI style overlay ??
- Canvas
- Rect
- Arc
- Image
- ...
- Table
- Tree
- Dialog
- State with Pydantic support?
Project details
Release history Release notifications | RSS feed
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.3.2.tar.gz
(33.6 kB
view details)
Built Distribution
QPUIQ-0.3.2-py3-none-any.whl
(55.6 kB
view details)
File details
Details for the file QPUIQ-0.3.2.tar.gz
.
File metadata
- Download URL: QPUIQ-0.3.2.tar.gz
- Upload date:
- Size: 33.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92de7e8ad4fb84c6d36918c2b94aa2b08dec929893c242218238347be1abf4c6 |
|
MD5 | 76e5cb6465d1dc6ad2a251188f986b56 |
|
BLAKE2b-256 | 27765fbfef63c895739640aad49f18da1e7d9fa243f3a8c827f267164fb9900a |
File details
Details for the file QPUIQ-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: QPUIQ-0.3.2-py3-none-any.whl
- Upload date:
- Size: 55.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e201852d93d6fe3a3ffaeb15e35500c5d44fb0f2c3e7b3bbc6f513e5eb71d253 |
|
MD5 | 21273de6d4153555b50134b5820ee289 |
|
BLAKE2b-256 | dcae8295b71303e117cc0ad71fdb8a839025f9a56cb85796e51a2f3185b12d3a |