def __init__(self, brushinfo=None, painting_only=False): """Initialize :param brushinfo: the lib.brush.BrushInfo instance to use :param painting_only: only use painting layers If painting_only is true, then no tempdir will be created by the document when it is initialized or cleared. """ object.__init__(self) if not brushinfo: brushinfo = brush.BrushInfo() brushinfo.load_defaults() self._layers = layer.RootLayerStack(self) self._layers.layer_content_changed += self._canvas_modified_cb self.brush = brush.Brush(brushinfo) self.brush.brushinfo.observers.append(self.brushsettings_changed_cb) self.stroke = None self.command_stack = command.CommandStack() self._painting_only = painting_only self._tempdir = None # Optional page area and resolution information self._frame = [0, 0, 0, 0] self._frame_enabled = False self._xres = None self._yres = None # Backgrounds for rendering blank_arr = numpy.zeros((N, N, 4), dtype='uint16') self._blank_bg_surface = tiledsurface.Background(blank_arr) self.clear()
def clear(self, init=False): self.split_stroke() if not init: bbox = self.get_bbox() # throw everything away, including undo stack self.command_stack = command.CommandStack() self.command_stack.stack_observers = self.command_stack_observers self.set_background((255, 255, 255)) self.layers = [] self.layer_idx = None self.add_layer(0) # disallow undo of the first layer self.command_stack.clear() self.unsaved_painting_time = 0.0 if not init: for f in self.canvas_observers: f(*bbox) self.call_doc_observers()