Skip to content

Commit ba6752f

Browse files
committed
get_sketch_info function
1 parent 6e3d866 commit ba6752f

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

crates/processing_pyo3/examples/rectangle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def draw():
88

99
fill(255, 0, 100)
1010
stroke(1)
11-
stroke_weight(25)
11+
stroke_weight(2)
1212
rect(100, 100, 200, 150)
1313

1414
# TODO: this should happen implicitly on module load somehow

crates/processing_pyo3/src/lib.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn get_asset_root() -> PyResult<String> {
7070
})
7171
}
7272

73-
fn get_sketch_root() -> PyResult<String> {
73+
fn get_sketch_info() -> PyResult<(String, String)> {
7474
Python::attach(|py| {
7575
let sys = PyModule::import(py, "sys")?;
7676
let argv: Vec<String> = sys.getattr("argv")?.extract()?;
@@ -79,28 +79,18 @@ fn get_sketch_root() -> PyResult<String> {
7979
let path = os.getattr("path")?;
8080
let dirname = path.getattr("dirname")?.call1((filename,))?;
8181
let abspath = path.getattr("abspath")?.call1((dirname,))?;
82-
Ok(abspath.to_string())
83-
})
84-
}
85-
86-
fn get_sketch_filename() -> PyResult<String> {
87-
Python::attach(|py| {
88-
let sys = PyModule::import(py, "sys")?;
89-
let argv: Vec<String> = sys.getattr("argv")?.extract()?;
90-
let filename: &str = argv[0].as_str();
91-
let os = PyModule::import(py, "os")?;
92-
let path = os.getattr("path")?;
9382
let basename = path.getattr("basename")?.call1((filename,))?;
94-
Ok(basename.to_string())
83+
Ok((abspath.to_string(), basename.to_string()))
9584
})
9685
}
9786

9887
#[pyfunction]
9988
#[pyo3(pass_module)]
10089
fn size(module: &Bound<'_, PyModule>, width: u32, height: u32) -> PyResult<()> {
10190
let asset_path: String = get_asset_root()?;
102-
let sketch_root_path: String = get_sketch_root()?;
103-
let sketch_filename: String = get_sketch_filename()?;
91+
let (sketch_root_path, sketch_filename) = get_sketch_info()?;
92+
// let sketch_root_path: String = get_sketch_root()?;
93+
// let sketch_filename: String = get_sketch_filename()?;
10494
let graphics = Graphics::new(
10595
width,
10696
height,

0 commit comments

Comments
 (0)