Declarative Components
Imperative Dialogs
Example
Decorators
@PUIApp
@PUIApp
def Example():
...
is equivalent to
class Example(Application):
def content(self):
...
@PUI
@PUI
def SubView():
...
is equivalent to
class SubView(PUIView):
def content(self):
...
Callback Interface
All callback interfaces accept an event object as the first argument. Other args/kwargs will be passed through to the callback function.
For example
def button_cb(event, data):
print(data)
Button("button").click(button_cb, 1)
will invoke
button_cb(event, 1)
when the event is emitted.
Event Object
click
dblclick
- .x, .y: double click position
mousedown
- .x, .y: mouse down position
mouseup
- .x, .y: mosue up position
mousemove
- .x, .y: mouse move position
wheel
- .x, .y: wheel position
- .x_delta, .y_delta: pixel delta
- .h_delta, .v_delta: angle delta
input
Triggered when typing in `TextField`
- .value: text in edit buffer
change
Triggered when editing is finished in `TextField`
Declarative Components
Common Modifiers
- .layout(width=320, height=240, weight=1, padding=, margin=)
- .style(color=0xFF0000, bgColor=0x333333, fontSize=16, fontWeight="bold", fontFamily="Arial")
- .qt(HorizontalPolicy=, VerticalPolicy=, SizeConstraint=, StyleSheet={})
- .flet(k=v)
Application
Top level element of an application
Application().qt(Style="fusion")
Window
flet and textual backends only support single window
Window([title=str][,size=(w,h)][,maximize=bool][,fullscreen=bool])
Modal
Modal window
Example
Modal(model[,offValue=None][,title=str][,size=(w,h)][,maximize=bool][,fullscreen=bool])
HBox
Horizontal Linear Layout Container
Example
HBox()
VBox
Vertical Linear Layout Container
Example
VBox()
Grid
Grid Layout Container
Example
with Grid():
Text("A").grid(row=0, column=0)
Text("B").grid(row=1, column=0, rowspan=2)
Spacer
Spacer inside linear layout containers
Example
with HBox():
Text("Left")
Spacer()
Text("Right")
Divider
Divider inside linear layout containers
Example
with VBox():
Text("Top")
Divider()
Text("Bottom")
Scrollable container
Example
with Scroll().layout(weight=1).scrollY(Scroll.END):
with VBox():
for i in range(100):
Label(f"Row {i+1}")
Single line clickable text with button appearance
Example
Button(text).click(callback, *cb_args, **cb_kwargs)
### Callbacks
* .click
Label
Single line clickable text
Example
Label(text).click(callback, *cb_args, **cb_kwargs)
### Callbacks
* .click
Text
Multiple line text viewer
Example
Text(text)
Html
HTML viewer (only supported by PySide6 backend)
Example
Html(html)
Markdown
Markdown viewer (not supported by tkinter backend)
Example
Markdown(md)
Combobox
Editable Dropdown List
Example
with ComboBox(editable=True, index_model=state("index"), text_model=state("text")):
ComboBoxItem("Item 1")
ComboBoxItem("Item 2")
ComboBoxItem("Item 3")
with ComboBox(editable=False, text_model=state("text")):
ComboBoxItem("Item 1", "Value 1")
ComboBoxItem("Item 2", "Value 2")
ComboBoxItem("Item 3", "Value 3")
TextField
Single line text editor
Example
TextField(binding, edit_buffer_binding=None)
Callbacks
- .input: edit buffer changed
- .change: editing finished
ProgressBar
Linear progress indicator
Example
ProgressBar(progress `0-1`)
Checkbox
Example
Checkbox(label, model)
Callbacks
Example
RadioButton(label, value, model)
Canvas
Example
def painter(canvas):
canvas.drawText(x, y, text, w=None, h=None, size=12, color=None, rotate=0, anchor=Anchor.LEFT_TOP)
canvas.drawLine(x1, y1, x2, y2, color=0xFF0000, width=1)
canvas.drawPolyline([x1, y2, ..., xn, yn], color=0xFF0000, width=1)
canvas.drawRect(x1, y1, x2, y2, fill=0xFF0000, stroke=0x00FF00, width=1)
canvas.drawShapely(shape, fill=0xFF0000, stroke=0x00FF00, width=1)
Canvas(painter)
Callbacks
- .dblclick
- .mousedown
- .mouseup
- .mousemove
- .wheel
MatplotlibCanvas
Example
data = [(0,0), (1,3), (2,2)]
def plot(figure, data):
figure.clear()
sp = figure.add_subplot(111)
sp.axes.plot([d[0] for d in data], [d[1] for d in data])
MatplotlibCanvas(plot, data)
Splitter
Splitter(vertical=False)
with Splitter():
Label("Left")
Label("Right")
Tabs and Tab
Example
with Tabs():
with Tab("Tab 1"):
Label("Tab Content 1")
with Tab("Tab 2"):
Label("Tab Content 2")
Table
Table widget
Example with TableNode
with Table():
with TableNode():
TableNode("A1")
TableNode("A2")
with TableNode():
TableNode("B1")
TableNode("B2")
Example with adapter
Table(adapter)
Tree
Single column tree widget
There should be a `TreeTable` for multi/fixed-column trees and a `NestedTable` for variable-column trees, but they have not been implemented yet
Example with TreeNode
with Tree():
with TreeNode("Root"):
with TreeNode("Sub 1"):
TreeNode("Sub 1-1")
TreeNode("Sub 1-2")
TreeNode("Sub 2")
with TreeNode("Sub 3"):
TreeNode("Sub 3-1")
Example with adapter
Tree(adapter)
Interop
QtInPui
Wrapper for embedding native widget instance into PUI
Currently only supported by PySide6 backend
Example
PuiInQt
Wrapper for embedding PUI view into existing QT view hierarchy
Currently only supported by PySide6 backend
Example