def tryit(*args): window = context.get_jsobject("window") window.alert("Test of setTimeout callback into Python") def import_element(): window = context.get_jsobject("window") window.setTimeout(tryit, 100) global color_block color_block = context.get_jsobject("color_block", can_call=False) assert (color_block) webview.on_view_ready(import_element) #set up a loop to continually increment the color color = int("00FF00", 16) def update_color(increment): global color hex_color = "#%0.6X" % color # make a javascript to set set the color: color_block.set_color(hex_color) # keep changing color: color += increment + (increment / 2) * 256 + (increment / 4) * 256 * 256 if color > int('FFFFFF', 16): color = 0 return False
#must get the object only when javascript has been processed, #so setup callback context = webview.get_main_frame().get_global_context() def tryit(*args): window = context.get_jsobject("window") window.alert("Test of setTimeout callback into Python") def import_element(): window = context.get_jsobject("window") window.setTimeout( tryit ,100) global color_block color_block = context.get_jsobject("color_block", can_call=False) assert(color_block) webview.on_view_ready( import_element ) #set up a loop to continually increment the color color = int("00FF00",16) def update_color( increment ): global color hex_color = "#%0.6X"%color # make a javascript to set set the color: color_block.set_color( hex_color ) # keep changing color: color += increment + (increment/2)*256 + (increment/4)*256*256 if color > int('FFFFFF',16): color = 0 return False import threading