dhxpyt
DHX PyTincture WASM Based Widgetset
Overview
The DHX PyTincture Widgetset is a Python library that integrates DHTMLX JavaScript UI components with the pyTincture framework using Pyodide. It enables building interactive, browser-based user interfaces directly in Python, supporting cross-platform GUI development with rich widgets like grids, charts, and forms.
Features
- Direct integration with DHTMLX UI components
- Pyodide-powered Python execution in the browser
- Cross-platform compatibility
- Customizable and reusable widgets
- Event handling for interactive experiences
Detailed class and API documentation is available in the sidebar.
Installation
Prerequisites
- Python 3.13+
- Pyodide
Steps
- Clone the repository:
bash git clone https://github.com/pytincture/dhx_pytincture_widgetset.git cd dhx_pytincture_widgetset;
QuickStart
Windows
Install UV / pytincture / dhxpyt on Powershell
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
$env:Path += ";$env:USERPROFILE\.cargoin"
[Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::User)
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
New-Item -ItemType Directory -Name dhxpyt_quickstart; Set-Location dhxpyt_quickstart
uv venv --python 3.13; .\.venv\Scripts\Activate.ps1
uv pip install dhxpyt pyodide-py js pytincture itsdangerous
Invoke-WebRequest -Uri https://pytincture.com/quickstart.py -OutFile quickstart.py
$env:PYTHONUTF8 = "1"
uv run quickstart.py
Linux / MacOS
Install UV / pytincture / dhxpyt on Bash
curl -LsSf https://astral.sh/uv/install.sh | sh
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
uv --version
mkdir dhxpyt_quickstart;cd dhxpyt_quickstart
uv venv --python 3.13 && source .venv/bin/activate
uv pip install dhxpyt pyodide-py js pytincture itsdangerous
curl -O https://pytincture.com/quickstart.py
uv run quickstart.py
Open in Browser: http://localhost:8070/quickstart
Example Code
import sys
from dhxpyt.layout import MainWindow, Layout, LayoutConfig, CellConfig
from dhxpyt.toolbar import ButtonConfig, ToolbarConfig
from dhxpyt.sidebar import NavItemConfig, SidebarConfig
from dhxpyt.grid import GridConfig, GridColumnConfig
from pyodide.ffi import create_proxy
# Sample data for the grid
SAMPLE_DATA = [
{"id": 1, "name": "Item 1", "value": 100},
{"id": 2, "name": "Item 2", "value": 200},
{"id": 3, "name": "Item 3", "value": 300}
]
class QuickstartMain(Layout):
layout_config = LayoutConfig(
type="line",
cols=[
CellConfig(id="sidebar", width="auto"),
CellConfig(id="content")
]
)
def load_ui(self):
# Sidebar configuration
sidebar_items = [
NavItemConfig(id="hamburger", icon="mdi mdi-menu"),
NavItemConfig(id="items", value="Items", icon="mdi mdi-view-list")
]
sidebar_config = SidebarConfig(data=sidebar_items, collapsed=False)
self.sidebar = self.add_sidebar(id="sidebar", sidebar_config=sidebar_config)
self.sidebar.on_click(create_proxy(self.handle_sidebar_click))
# Content layout with toolbar and grid
content_layout_config = LayoutConfig(
type="line",
rows=[
CellConfig(id="toolbar", height="auto"),
CellConfig(id="grid")
]
)
self.content_layout = self.add_layout("content", content_layout_config)
# Toolbar configuration
toolbar_config = ToolbarConfig(data=[
ButtonConfig(id="add", value="Add Item", icon="mdi mdi-plus"),
ButtonConfig(id="refresh", value="Refresh", icon="mdi mdi-refresh")
])
self.toolbar = self.content_layout.add_toolbar(id="toolbar", toolbar_config=toolbar_config)
# Grid configuration
grid_columns = [
GridColumnConfig(id="id", width=100, header=[{"text": "ID"}]),
GridColumnConfig(id="name", width=200, header=[{"text": "Name"}]),
GridColumnConfig(id="value", width=150, header=[{"text": "Value"}])
]
grid_config = GridConfig(columns=grid_columns, data=SAMPLE_DATA)
self.grid = self.content_layout.add_grid(id="grid", grid_config=grid_config)
def handle_sidebar_click(self, id, event):
if id == "hamburger":
self.sidebar.toggle()
class QuickstartApp(MainWindow):
def load_ui(self):
self.set_theme("dark")
self.main_layout = QuickstartMain(parent=self)
self.attach("mainwindow", self.main_layout.layout)
if __name__ == "__main__" and sys.platform != "emscripten":
from pytincture import launch_service
launch_service()
1""" 2# DHX PyTincture WASM Based Widgetset 3 4<img src="tincture.jpeg" alt="DHX PyTincture Widgetset Logo" width="400" style="display: block; margin: 0 auto;"> 5 6## Overview 7 8The DHX PyTincture Widgetset is a Python library that integrates DHTMLX JavaScript UI components with the pyTincture framework using Pyodide. It enables building interactive, browser-based user interfaces directly in Python, supporting cross-platform GUI development with rich widgets like grids, charts, and forms. 9 10## Features 11 12- Direct integration with DHTMLX UI components 13- Pyodide-powered Python execution in the browser 14- Cross-platform compatibility 15- Customizable and reusable widgets 16- Event handling for interactive experiences 17 18Detailed class and API documentation is available in the sidebar. 19 20## Installation 21 22### Prerequisites 23- Python 3.13+ 24- Pyodide 25 26### Steps 271. Clone the repository: 28 ```bash 29 git clone https://github.com/pytincture/dhx_pytincture_widgetset.git 30 cd dhx_pytincture_widgetset;``` 31 32## QuickStart 33 34## Windows 35#### Install UV / pytincture / dhxpyt on Powershell 36``` 37powershell -c "irm https://astral.sh/uv/install.ps1 | iex" 38$env:Path += ";$env:USERPROFILE\.cargo\bin" 39[Environment]::SetEnvironmentVariable("Path", $env:Path, [System.EnvironmentVariableTarget]::User) 40$env:Path = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) 41New-Item -ItemType Directory -Name dhxpyt_quickstart; Set-Location dhxpyt_quickstart 42uv venv --python 3.13; .\.venv\Scripts\Activate.ps1 43uv pip install dhxpyt pyodide-py js pytincture itsdangerous 44Invoke-WebRequest -Uri https://pytincture.com/quickstart.py -OutFile quickstart.py 45$env:PYTHONUTF8 = "1" 46uv run quickstart.py 47``` 48 49## Linux / MacOS 50#### Install UV / pytincture / dhxpyt on Bash 51``` 52curl -LsSf https://astral.sh/uv/install.sh | sh 53echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc 54source ~/.bashrc 55uv --version 56mkdir dhxpyt_quickstart;cd dhxpyt_quickstart 57uv venv --python 3.13 && source .venv/bin/activate 58uv pip install dhxpyt pyodide-py js pytincture itsdangerous 59curl -O https://pytincture.com/quickstart.py 60uv run quickstart.py 61``` 62 63Open in Browser: 64http://localhost:8070/quickstart 65 66 67### Example Code 68```python 69import sys 70from dhxpyt.layout import MainWindow, Layout, LayoutConfig, CellConfig 71from dhxpyt.toolbar import ButtonConfig, ToolbarConfig 72from dhxpyt.sidebar import NavItemConfig, SidebarConfig 73from dhxpyt.grid import GridConfig, GridColumnConfig 74from pyodide.ffi import create_proxy 75 76# Sample data for the grid 77SAMPLE_DATA = [ 78 {"id": 1, "name": "Item 1", "value": 100}, 79 {"id": 2, "name": "Item 2", "value": 200}, 80 {"id": 3, "name": "Item 3", "value": 300} 81] 82 83class QuickstartMain(Layout): 84 layout_config = LayoutConfig( 85 type="line", 86 cols=[ 87 CellConfig(id="sidebar", width="auto"), 88 CellConfig(id="content") 89 ] 90 ) 91 92 def load_ui(self): 93 # Sidebar configuration 94 sidebar_items = [ 95 NavItemConfig(id="hamburger", icon="mdi mdi-menu"), 96 NavItemConfig(id="items", value="Items", icon="mdi mdi-view-list") 97 ] 98 sidebar_config = SidebarConfig(data=sidebar_items, collapsed=False) 99 self.sidebar = self.add_sidebar(id="sidebar", sidebar_config=sidebar_config) 100 self.sidebar.on_click(create_proxy(self.handle_sidebar_click)) 101 102 # Content layout with toolbar and grid 103 content_layout_config = LayoutConfig( 104 type="line", 105 rows=[ 106 CellConfig(id="toolbar", height="auto"), 107 CellConfig(id="grid") 108 ] 109 ) 110 self.content_layout = self.add_layout("content", content_layout_config) 111 112 # Toolbar configuration 113 toolbar_config = ToolbarConfig(data=[ 114 ButtonConfig(id="add", value="Add Item", icon="mdi mdi-plus"), 115 ButtonConfig(id="refresh", value="Refresh", icon="mdi mdi-refresh") 116 ]) 117 self.toolbar = self.content_layout.add_toolbar(id="toolbar", toolbar_config=toolbar_config) 118 119 # Grid configuration 120 grid_columns = [ 121 GridColumnConfig(id="id", width=100, header=[{"text": "ID"}]), 122 GridColumnConfig(id="name", width=200, header=[{"text": "Name"}]), 123 GridColumnConfig(id="value", width=150, header=[{"text": "Value"}]) 124 ] 125 grid_config = GridConfig(columns=grid_columns, data=SAMPLE_DATA) 126 self.grid = self.content_layout.add_grid(id="grid", grid_config=grid_config) 127 128 def handle_sidebar_click(self, id, event): 129 if id == "hamburger": 130 self.sidebar.toggle() 131 132class QuickstartApp(MainWindow): 133 def load_ui(self): 134 self.set_theme("dark") 135 self.main_layout = QuickstartMain(parent=self) 136 self.attach("mainwindow", self.main_layout.layout) 137 138if __name__ == "__main__" and sys.platform != "emscripten": 139 from pytincture import launch_service 140 launch_service() 141 142``` 143""" 144 145__widgetset__ = "dhxpyt" 146__version__ = "0.8.1" 147__version_tuple__ = tuple(map(int, __version__.split('.'))) 148__description__ = "Python wrapper for DHTMLX widgets"