Skip to content
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
100 changes: 100 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bevy = { git = "https://github.com/bevyengine/bevy", branch = "main", no-default
"bevy_color",
] }
processing = { path = "." }
processing_pyo3 = { path = "crates/processing_pyo3" }
processing_render = { path = "crates/processing_render" }

[dependencies]
Expand Down
72 changes: 72 additions & 0 deletions crates/processing_pyo3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/target

# Byte-compiled / optimized / DLL files
__pycache__/
.pytest_cache/
*.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
19 changes: 19 additions & 0 deletions crates/processing_pyo3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "processing_pyo3"
version = "0.1.0"
edition = "2024"

[lints]
workspace = true

[lib]
name = "pycessing"
crate-type = ["cdylib"]

[dependencies]
pyo3 = "0.27.0"
processing = { workspace = true }
glfw = "0.60.0"

[target.'cfg(target_os = "linux")'.dependencies]
glfw = { version = "0.60.0", features = ["wayland"] }
19 changes: 19 additions & 0 deletions crates/processing_pyo3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Pycessing

Prototype for python bindings to libprocessing

## To Get Started

### Install venv and maturin
Follow these [installation instructions](https://pyo3.rs/v0.27.2/getting-started.html)

### Running code
```
$ maturin develop
#
# ...
#
$ python
>>> import pycessing
>>> pycessing.size(500, 500)
```
16 changes: 16 additions & 0 deletions crates/processing_pyo3/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[build-system]
requires = ["maturin>=1.10,<2.0"]
build-backend = "maturin"

[project]
name = "pycessing"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]

[tool.maturin]
manifest-path = "Cargo.toml"
69 changes: 69 additions & 0 deletions crates/processing_pyo3/src/glfw.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/// Minimal GLFW helper for Processing examples
use glfw::{Glfw, GlfwReceiver, PWindow, WindowEvent, WindowMode};
use processing::prelude::error::Result;

pub struct GlfwContext {
glfw: Glfw,
window: PWindow,
events: GlfwReceiver<(f64, WindowEvent)>,
}

impl GlfwContext {
pub fn new(width: u32, height: u32) -> Result<Self> {
let mut glfw = glfw::init(glfw::fail_on_errors).unwrap();

glfw.window_hint(glfw::WindowHint::ClientApi(glfw::ClientApiHint::NoApi));
glfw.window_hint(glfw::WindowHint::Visible(false));

let (mut window, events) = glfw
.create_window(width, height, "Processing", WindowMode::Windowed)
.unwrap();

window.set_all_polling(true);
window.show();

Ok(Self {
glfw,
window,
events,
})
}

#[cfg(target_os = "macos")]
pub fn get_window(&self) -> u64 {
self.window.get_cocoa_window() as u64
}

#[cfg(target_os = "windows")]
pub fn get_window(&self) -> u64 {
self.window.get_win32_window() as u64
}

#[cfg(target_os = "linux")]
pub fn get_window(&self) -> u64 {
self.window.get_wayland_window() as u64
}

#[cfg(not(target_os = "linux"))]
pub fn get_display(&self) -> u64 {
0
}

#[cfg(target_os = "linux")]
pub fn get_display(&self) -> u64 {
self.glfw.get_wayland_display() as u64
}

pub fn poll_events(&mut self) -> bool {
self.glfw.poll_events();

for (_, event) in glfw::flush_messages(&self.events) {
match event {
WindowEvent::Close => return false,
_ => {}
}
}

!self.window.should_close()
}
}
40 changes: 40 additions & 0 deletions crates/processing_pyo3/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
mod glfw;
use pyo3::prelude::*;

#[pymodule]
mod pycessing {
use crate::glfw::GlfwContext;
use processing::prelude::*;
use pyo3::prelude::*;

/// create surface
#[pyfunction]
fn size(width: u32, height: u32) -> PyResult<String> {
let mut glfw_ctx = GlfwContext::new(400, 400).unwrap();
init().unwrap();

let window_handle = glfw_ctx.get_window();
let display_handle = glfw_ctx.get_display();
let surface = surface_create(window_handle, display_handle, width, height, 1.0).unwrap();

while glfw_ctx.poll_events() {
begin_draw(surface).unwrap();

record_command(
surface,
DrawCommand::Rect {
x: 10.0,
y: 10.0,
w: 100.0,
h: 100.0,
radii: [0.0, 0.0, 0.0, 0.0],
},
)
.unwrap();

end_draw(surface).unwrap();
}

Ok("OK".to_string())
}
}
Loading