@@ -33,7 +33,7 @@ class Canvas(DOMWidget):
3333
3434 def __init__ (self , * args , ** kwargs ):
3535 self .caching = kwargs .get ('caching' , False )
36- self .commands_cache = []
36+ self ._commands_cache = []
3737
3838 super (Canvas , self ).__init__ (* args , ** kwargs )
3939 self .layout .width = str (self .size [0 ]) + 'px'
@@ -87,14 +87,20 @@ def quadratic_curve_to(self, cp1x, cp1y, x, y):
8787 def bezier_curve_to (self , cp1x , cp1y , cp2x , cp2y , x , y ):
8888 self ._send_canvas_command ('bezierCurveTo' , cp1x , cp1y , cp2x , cp2y , x , y )
8989
90+ def clear (self ):
91+ """Clear the entire canvas."""
92+ self ._commands_cache = []
93+ self .send ({'name' : 'clear' })
94+
9095 def flush (self ):
96+ """Flush all the cached commands."""
9197 if not self .caching :
9298 return
9399
94- self .send (self .commands_cache )
100+ self .send (self ._commands_cache )
95101
96102 self .caching = False
97- self .commands_cache = []
103+ self ._commands_cache = []
98104
99105 @observe ('fill_style' , 'stroke_style' , 'global_alpha' )
100106 def _on_set_attr (self , change ):
@@ -110,6 +116,6 @@ def _send_canvas_command(self, name, *args):
110116
111117 def _send_command (self , command ):
112118 if self .caching :
113- self .commands_cache .append (command )
119+ self ._commands_cache .append (command )
114120 else :
115121 self .send (command )
0 commit comments