Пример #1
0
    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()
Пример #2
0
    def __init__(self, brushinfo=None):
        if not brushinfo:
            brushinfo = brush.BrushInfo()
            brushinfo.load_defaults()
        self.layers = []
        self.brush = brush.Brush(brushinfo)
        self.ani = animation.Animation(self)

        self.brush.brushinfo.observers.append(self.brushsettings_changed_cb)
        self.stroke = None
        self.canvas_observers = []  #: See `layer_modified_cb()`
        self.stroke_observers = []  #: See `split_stroke()`
        self.doc_observers = []  #: See `call_doc_observers()`
        self.frame_observers = []
        self.command_stack_observers = []
        self.symmetry_observers = []  #: See `set_symmetry_axis()`
        self.__symmetry_axis = None
        self.default_background = (255, 255, 255)
        self.clear(True)

        self._frame = [0, 0, 0, 0]
        self._frame_enabled = False

        # Used by move_frame() to accumulate values
        self._frame_dx = 0.0
        self._frame_dy = 0.0
Пример #3
0
def migrate_brushes_to_json(dirpath):

    files = os.listdir(dirpath)
    files = [
        os.path.join(dirpath, fn) for fn in files
        if os.path.splitext(fn)[1] == '.myb'
    ]

    for fpath in files:
        b = brush.BrushInfo(open(fpath, 'r').read())
        open(fpath, 'w').write(b.to_json())
Пример #4
0
    def __init__(self, brushinfo=None):
        if not brushinfo:
            brushinfo = brush.BrushInfo()
            brushinfo.load_defaults()
        self.brush = brush.Brush(brushinfo)
        self.stroke = None
        self.canvas_observers = []
        self.stroke_observers = [] # callback arguments: stroke, brush (brush is a temporary read-only convenience object)
        self.doc_observers = []
        self.frame_observers = []
        self.command_stack_observers = []
        self.clear(True)

        self._frame = [0, 0, 0, 0]
        self._frame_enabled = False
        # Used by move_frame() to accumulate values
        self._frame_dx = 0.0
        self._frame_dy = 0.0
Пример #5
0
    def render(self, surface):
        assert self.finished

        # OPTIMIZE: check if parsing of settings is a performance bottleneck
        b = brush.Brush(brush.BrushInfo(self.brush_settings))

        states = numpy.fromstring(self.brush_state, dtype='float32')
        b.set_state(states)

        #b.set_print_inputs(1)
        #print 'replaying', len(self.stroke_data), 'bytes'

        version, data = self.stroke_data[0], self.stroke_data[1:]
        assert version == '2'
        data = numpy.fromstring(data, dtype='float64')
        data.shape = (len(data) / 6, 6)

        surface.begin_atomic()
        for dtime, x, y, pressure, xtilt, ytilt in data:
            b.stroke_to(surface, x, y, pressure, xtilt, ytilt, dtime)
        surface.end_atomic()