Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(examples): add integrate with nicegui example nicegui-app #55

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Docs

- [#55](https://github.com/WSH032/pytauri/pull/55) - Add `integrate with nicegui` example `nicegui-app`. See `examples/nicegui-app`.
- [#52](https://github.com/WSH032/pytauri/pull/52) - update `examples/tauri-app` `main.rs` for new API to prepare python interpreter.
- [#52](https://github.com/WSH032/pytauri/pull/52) - add the usage of `multiprocessing.freeze_support` in `examples/tauri-app` `__main__.py`.

Expand Down
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["crates/*", "examples/tauri-app/src-tauri"]
members = ["crates/*", "examples/tauri-app/src-tauri", "examples/nicegui-app"]
resolver = "2"


Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Source Code: <https://github.com/WSH032/pytauri/>
}
```

- Can be integrated with [nicegui]/[gradio]/[FastAPI] to achieve a full-stack Python development experience (i.g., without `Node.js`). See [examples/nicegui-app](https://github.com/WSH032/pytauri/tree/main/examples/nicegui-app).

## Release

We follow [Semantic Versioning 2.0.0](https://semver.org/).
Expand Down Expand Up @@ -147,10 +149,6 @@ Through [Pyo3], I hope Rust developers can better utilize the Python ecosystem (

Although Rust's lifetime and ownership system makes Rust code safer, Python's garbage collection (GC) will make life easier. 😆

### The Future

In the future, I hope PyTauri can integrate with [nicegui] and [gradio], bringing you a Python full-stack (i.g., without `Node.js`) development experience.

[pywebview]: https://github.com/r0x0r/pywebview
[Pystray]: https://github.com/moses-palmer/pystray
[electron]: https://github.com/electron/electron
Expand Down
81 changes: 81 additions & 0 deletions examples/nicegui-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Generated by Cargo
# will have compiled files and executables
/target/

# Generated by Tauri
# will have schema files for capabilities auto-completion
/gen/schemas

# Byte-compiled / optimized / DLL files
__pycache__/
.pytest_cache/
*.pdb
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
.venv/
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
include/
man/
venv/
*.egg-info/
.installed.cfg
*.egg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt
pip-selfcheck.json

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# Rope
.ropeproject

# Django stuff:
*.log
*.pot

.DS_Store

# Sphinx documentation
docs/_build/

# PyCharm
.idea/

# VSCode
.vscode/

# Pyenv
.python-version

/pyembed/
4 changes: 4 additions & 0 deletions examples/nicegui-app/.taurignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# See: <https://tauri.app/develop/#reacting-to-source-code-changes>

__pycache__
/pyembed/
38 changes: 38 additions & 0 deletions examples/nicegui-app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "nicegui-app"
version = "0.1.0"
description = "A NiceGui App built with Tauri"
authors = ["you"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "nicegui_app_lib"
# `cdylib` is required for building python extension modules files
crate-type = ["staticlib", "cdylib", "rlib"]

[[bin]]
# the same as the package name
name = "nicegui-app"
path = "src/main.rs"
required-features = ["pytauri/standalone"]


[build-dependencies]
tauri-build = { workspace = true, features = [] }

[dependencies]
tauri = { workspace = true, features = [] }
tauri-plugin-opener = "2"
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }

pyo3 = { workspace = true }
pytauri = { workspace = true }
tauri-plugin-pytauri = { workspace = true }
tauri-plugin-notification = { workspace = true }
pytauri-plugin-notification = { workspace = true }
45 changes: 45 additions & 0 deletions examples/nicegui-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# PyTauri + Vanilla TS

```bash
cd examples/nicegui-app
```

and follow the tutorial section in Documentation.

**NOTE**: **When using `tauri dev`, you must pass `--no-dev-server-wait`**, because the uvicorn server only starts after running the executable.

---

or you are hurry, just wanna see/run the demo:

> Make sure you have already installed `rust`, `uv`, `pnpm`, `node.js` and Tauri Prerequisites.
>
> > Because you have directly pulled the development repository, you need `pnpm` to manually build frontend assets.
> >
> > In actual use, this step has already been completed for `pytauri` on `crates.io`, which means only `rust` and `python` are required.
>
> You can find that in tutorial section in Documentation.

```bash
git clone https://github.com/WSH032/pytauri.git
cd pytauri

cd examples/nicegui-app

# build frontend assets
pnpm install
pnpm -r run build

# activate virtual environment
uv venv
source .venv/bin/activate
# or powershell: .venv\Scripts\Activate.ps1

# install the example package
# (need some time to compile rust code,
# you can pass `--verbose` to see the progress)
uv pip install --reinstall -e .

# run the example
python -m nicegui_app
```
3 changes: 3 additions & 0 deletions examples/nicegui-app/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}
12 changes: 12 additions & 0 deletions examples/nicegui-app/capabilities/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"opener:default",
"pytauri:default",
"notification:default"
]
}
Binary file added examples/nicegui-app/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nicegui-app/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nicegui-app/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/nicegui-app/icons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Credits

## Icon Source

![NiceGUI Logo](https://github.com/zauberzeug/nicegui/raw/v2.9.1/website/favicon/android-chrome-384x384.png)
Binary file added examples/nicegui-app/icons/Square107x107Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nicegui-app/icons/Square142x142Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nicegui-app/icons/Square284x284Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nicegui-app/icons/Square30x30Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nicegui-app/icons/Square310x310Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nicegui-app/icons/Square44x44Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nicegui-app/icons/Square71x71Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nicegui-app/icons/Square89x89Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nicegui-app/icons/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/nicegui-app/icons/icon.icns
Binary file not shown.
Binary file added examples/nicegui-app/icons/icon.ico
Binary file not shown.
Binary file added examples/nicegui-app/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions examples/nicegui-app/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[project]
name = "nicegui-app"
version = "0.1.0"
description = "Add your description here"
requires-python = ">=3.9"
dependencies = [
"nicegui >= 2.9.1, < 3",
"fastapi >= 0.115.6",
"uvicorn >= 0.34",
"pytauri == 0.1.*",
"anyio == 4.*",
"pytauri-plugin-notification == 0.1.*",
"typing-extensions >= 4",
]

[project.entry-points.pytauri]
# - "nicegui_app" -> `python/nicegui_app/`
# - "ext_mod" -> `#[pyo3(name = "ext_mod")]` in rust
ext_mod = "nicegui_app.ext_mod"

[build-system]
requires = ["setuptools>=61", "setuptools-rust==1.*", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages]
find = { where = ["python"] }

# see: <https://www.maturin.rs/config>
[tool.maturin]
# the same as [tool.setuptools.packages.find.where]
python-source = "python"
# the same as `[project.entry-points.pytauri.ext_mod]`,
# i.e., `target` in `setup.py`
module-name = "nicegui_app.ext_mod"
# see `setup.py`
features = ["pyo3/extension-module", "tauri/custom-protocol", "pyo3/abi3-py39"]
# equivalent to `setuptools_scm`
sdist-generator = "git"


[tool.uv.sources]
pytauri = { workspace = true }
pytauri-plugin-notification = { workspace = true }
Loading
Loading