@@ -82,11 +82,11 @@ def __init__(
82
82
"""The background colour of the canvas itself."""
83
83
self ._pen_colour = pen_color
84
84
"""The default pen colour, used when drawing pixels."""
85
- self ._canvas : list [list [Color | None ]] = self . _blank_canvas
85
+ self ._canvas : list [list [Color | None ]] = []
86
86
"""The canvas itself."""
87
87
self ._refreshing = True
88
- """Are we refreshing by default? """
89
- self .virtual_size = Size ( width , ceil ( height / 2 ) )
88
+ """The current default refresh state. """
89
+ self .clear ( )
90
90
91
91
@property
92
92
def _blank_canvas (self ) -> list [list [Color | None ]]:
@@ -169,24 +169,36 @@ def _pixel_check(self, x: int, y: int) -> None:
169
169
f"x={ x } , x={ y } is not within 0, 0, { self ._width } , { self ._height } "
170
170
)
171
171
172
- def clear (self , color : Color | None = None ) -> Self :
172
+ def clear (
173
+ self ,
174
+ color : Color | None = None ,
175
+ width : int | None = None ,
176
+ height : int | None = None ,
177
+ ) -> Self :
173
178
"""Clear the canvas.
174
179
175
180
Args:
176
181
color: Optional default colour for the canvas.
182
+ width: Optional width for the canvas.
183
+ height: Optional height for the canvas.
177
184
178
185
Returns:
179
186
The canvas.
180
187
181
- Note:
182
- If the color isn't provided, then the color used when first
183
- making the canvas is used, this in turn becomes the new default
184
- color (and will then be used for subsequent clears, unless
185
- another color is provided).
188
+ If the color isn't provided, then the color used when first making
189
+ the canvas is used, this in turn becomes the new default color (and
190
+ will then be used for subsequent clears, unless another color is
191
+ provided).
192
+
193
+ Explicitly setting the colour to [`None`][None] will set the canvas
194
+ colour to whatever the widget's `background` colour is.
186
195
187
- Explicitly setting the colour to [`None`][None] will set the
188
- canvas colour to whatever the widget's `background` colour is .
196
+ If `width` or `height` are omitted then the current value for those
197
+ dimensions will be used .
189
198
"""
199
+ self ._width = self ._width if width is None else width
200
+ self ._height = self ._height if height is None else height
201
+ self .virtual_size = Size (self ._width , ceil (self ._height / 2 ))
190
202
self ._canvas_colour = color or self ._canvas_colour
191
203
self ._canvas = self ._blank_canvas
192
204
return self .refresh ()
0 commit comments