<s> from pyjamas import DOM <EOL> from pyjamas . ui . Image import Image <EOL> from pyjamas . ui . FocusWidget import FocusWidget <EOL> from pyjamas . ui import Event <EOL> from pyjamas . ui import MouseListener <EOL> from pyjamas . ui import KeyboardListener <EOL> from pyjamas . ui import Focus <EOL> from pyjamas . ui import FocusListener <EOL> from __pyjamas__ import JS <EOL> class Canvas ( FocusWidget ) : <EOL> def __init__ ( self , Width = <NUM_LIT:0> , Height = <NUM_LIT:0> , ** kwargs ) : <EOL> if not kwargs . has_key ( '<STR_LIT>' ) : <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> kwargs [ '<STR_LIT>' ] = Width <EOL> kwargs [ '<STR_LIT>' ] = Height <EOL> self . context = None <EOL> focusable = Focus . createFocusable ( ) <EOL> self . canvas = DOM . createElement ( "<STR_LIT>" ) <EOL> DOM . appendChild ( focusable , self . canvas ) <EOL> FocusWidget . __init__ ( self , focusable , ** kwargs ) <EOL> self . init ( ) <EOL> self . context . fillStyle = "<STR_LIT>" <EOL> self . context . strokeStyle = "<STR_LIT>" <EOL> def setWidth ( self , width ) : <EOL> FocusWidget . setWidth ( self , width ) <EOL> self . canvas . width = width <EOL> def setHeight ( self , height ) : <EOL> FocusWidget . setHeight ( self , height ) <EOL> self . canvas . height = height <EOL> def getContext ( self ) : <EOL> return self . context <EOL> def isEmulation ( self ) : <EOL> return False <EOL> def init ( self ) : <EOL> el = self . getElement ( ) . firstChild <EOL> ctx = el . getContext ( "<STR_LIT>" ) <EOL> """<STR_LIT>""" <EOL> self . context = ctx <EOL> class CanvasImage ( Image ) : <EOL> def __init__ ( self , url = "<STR_LIT>" , load_listener = None ) : <EOL> Image . __init__ ( self , url ) <EOL> if load_listener : <EOL> self . addLoadListener ( load_listener ) <EOL> self . onAttach ( ) <EOL> def isLoaded ( self ) : <EOL> return self . getElement ( ) . complete <EOL> class ImageLoadListener : <EOL> def __init__ ( self , listener = None ) : <EOL> self . wait_list = [ ] <EOL> self . loadListeners = [ ] <EOL> if listener : <EOL> self . addLoadListener ( listener ) <EOL> def add ( self , sender ) : <EOL> self . wait_list . append ( sender ) <EOL> sender . addLoadListener ( self ) <EOL> def addLoadListener ( self , listener ) : <EOL> self . loadListeners . append ( listener ) <EOL> def isLoaded ( self ) : <EOL> if len ( self . wait_list ) : <EOL> return False <EOL> return True <EOL> def onError ( self , sender ) : <EOL> for listener in self . loadListeners : <EOL> listener . onError ( sender ) <EOL> def onLoad ( self , sender ) : <EOL> self . wait_list . remove ( sender ) <EOL> if self . isLoaded ( ) : <EOL> for listener in self . loadListeners : <EOL> listener . onLoad ( self ) </s>
