0

How can Brython wait for an image to load similarly to how Jquery/Javascript does before proceeding with execution?

In the above Brython code errors list is never appended to because img.bind('load', on_load) does not block execution. How can I block execution before proceeding?

Feel free offer up suggestions or an alternative approach to dealing with waits/blocking in Brython.

error = []
img = html.IMG(src=blob)
document <= img
def on_load(event):
   if img.height*img.width > 2:
       errors.append(f"Image dimensions are too large.")
       print(errors) # The above error does indeed exist in errors.
img.bind('load', on_load)
if errors:
    print(errors) # errors is empty because this was declared as img.bind was running
Pyramid Power
  • 35
  • 1
  • 6

1 Answers1

0

Is there a place where you call img.load(), or is this supposed to happen automatically?

If not, then the current behaviour is expected because on_load() was declared and bound to img, but img's load() function is never called. Thus on_load() never actually runs.