@@ -162,11 +162,7 @@ fn dispatch_event_callbacks(locals: &Bound<'_, PyAny>) -> PyResult<()> {
162162 Ok ( ( ) )
163163}
164164
165- fn create_graphics_context (
166- module : & Bound < ' _ , PyModule > ,
167- width : u32 ,
168- height : u32 ,
169- ) -> PyResult < ( ) > {
165+ fn create_graphics_context ( module : & Bound < ' _ , PyModule > , width : u32 , height : u32 ) -> PyResult < ( ) > {
170166 let py = module. py ( ) ;
171167 let env = detect_environment ( py) ?;
172168
@@ -185,8 +181,7 @@ fn create_graphics_context(
185181 match env. as_str ( ) {
186182 "jupyter" => {
187183 let asset_path = get_asset_root ( ) ?;
188- let graphics =
189- Graphics :: new_offscreen ( width, height, asset_path. as_str ( ) , log_level) ?;
184+ let graphics = Graphics :: new_offscreen ( width, height, asset_path. as_str ( ) , log_level) ?;
190185 module. setattr ( "_graphics" , graphics) ?;
191186
192187 if !has_existing {
@@ -217,9 +212,7 @@ fn create_graphics_context(
217212
218213 let post_code = CString :: new ( IPYTHON_POST_EXECUTE_CODE ) ?;
219214 py. run ( post_code. as_c_str ( ) , None , None ) . map_err ( |e| {
220- PyRuntimeError :: new_err ( format ! (
221- "Failed to register post-execute hook: {e}"
222- ) )
215+ PyRuntimeError :: new_err ( format ! ( "Failed to register post-execute hook: {e}" ) )
223216 } ) ?;
224217 }
225218 }
@@ -894,9 +887,15 @@ mod mewnala {
894887 frame. getattr ( "f_globals" ) ?
895888 } ;
896889 sync_globals ( module, & globals) ?;
897-
898- // if there's no draw fn, we enter an idle loop
890+
891+ // no draw is defined. flush any top level code and then idle
899892 if draw_fn. is_none ( ) {
893+ {
894+ let mut graphics = get_graphics_mut ( module) ?
895+ . ok_or_else ( || PyRuntimeError :: new_err ( "call size() first" ) ) ?;
896+ graphics. surface . poll_events ( ) ;
897+ }
898+
900899 get_graphics ( module) ?
901900 . ok_or_else ( || PyRuntimeError :: new_err ( "call size() first" ) ) ?
902901 . end_draw ( ) ?;
@@ -917,7 +916,6 @@ mod mewnala {
917916 }
918917 let draw_fn_ref = draw_fn. as_mut ( ) . expect ( "checked above" ) ;
919918
920- // start draw loop
921919 loop {
922920 {
923921 let mut graphics = get_graphics_mut ( module) ?
0 commit comments