@@ -14,7 +14,6 @@ mod graphics;
1414use graphics:: { Geometry , Graphics , Image , Topology , get_graphics, get_graphics_mut} ;
1515use pyo3:: {
1616 exceptions:: PyRuntimeError ,
17- ffi:: c_str,
1817 prelude:: * ,
1918 types:: { PyDict , PyTuple } ,
2019} ;
@@ -84,16 +83,30 @@ fn get_sketch_root() -> PyResult<String> {
8483 } )
8584}
8685
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" ) ?;
93+ let basename = path. getattr ( "basename" ) ?. call1 ( ( filename, ) ) ?;
94+ Ok ( basename. to_string ( ) )
95+ } )
96+ }
97+
8798#[ pyfunction]
8899#[ pyo3( pass_module) ]
89100fn size ( module : & Bound < ' _ , PyModule > , width : u32 , height : u32 ) -> PyResult < ( ) > {
90101 let asset_path: String = get_asset_root ( ) ?;
91102 let sketch_root_path: String = get_sketch_root ( ) ?;
103+ let sketch_filename: String = get_sketch_filename ( ) ?;
92104 let graphics = Graphics :: new (
93105 width,
94106 height,
95107 asset_path. as_str ( ) ,
96108 sketch_root_path. as_str ( ) ,
109+ sketch_filename. as_str ( ) ,
97110 ) ?;
98111 module. setattr ( "_graphics" , graphics) ?;
99112 Ok ( ( ) )
0 commit comments