def __init__(self, start_point, rect_size, shape, position, clockwise=True): ''' (QPointF, QSizeF, str in self.SHAPES, str in self.POSITIONS, bool) ''' W, H = rect_size.width(), rect_size.height() vlarg('start_point', start_point, QPointF) vlarg('rect_size', rect_size, QSizeF) vlarg('position', position, str, self.POSITIONS) vlarg('shape', shape, str, self.SHAPES) vlarg('clockwise', clockwise, bool) GxPainterPath.__init__(self, start_point) if shape == 'trig': if clockwise: if position == 'top-right': self.lineToInc(W, H) elif position == 'bottom-right': self.lineToInc(-W, H) elif position == 'bottom-left': self.lineToInc(-W, -H) elif position == 'top-left': self.lineToInc(W, -H) else: if position == 'top-left': self.lineToInc(-W, H) elif position == 'bottom-left': self.lineToInc(W, H) elif position == 'bottom-right': self.lineToInc(W, -H) elif position == 'top-right': self.lineToInc(-W, -H) elif shape == 'arc': if clockwise: if position == 'top-right': self.arcTo(self.x - W, self.y, 2*W, 2*H, -270, -90) elif position == 'bottom-right': self.arcTo(self.x - 2*W, self.y - H, 2*W, 2*H, 0, -90) elif position == 'bottom-left': self.arcTo(self.x - W, self.y - 2*H, 2*W, 2*H, -90, -90) elif position == 'top-left': self.arcTo(self.x, self.y - H, 2*W, 2*H, -180, -90) else: if position == 'top-left': self.arcTo(self.x - W, self.y, 2*W, 2*H, 90, 90) elif position == 'bottom-left': self.arcTo(self.x, self.y - H, 2*W, 2*H, 180, 90) elif position == 'bottom-right': self.arcTo(self.x - W, self.y - 2*H, 2*W, 2*H, 270, 90) elif position == 'top-right': self.arcTo(self.x - 2*W, self.y - H, 2*W, 2*H, 0, 90) elif shape == 'rect': if clockwise: if position == 'top-right': self.lineToInc(dx = W) self.lineToInc(dy = H) elif position == 'bottom-right': self.lineToInc(dy = H) self.lineToInc(dx = -W) elif position == 'bottom-left': self.lineToInc(dx = -W) self.lineToInc(dy = -H) elif position == 'top-left': self.lineToInc(dy = -H) self.lineToInc(dx = W) else: if position == 'top-left': self.lineToInc(dx = -W) self.lineToInc(dy = H) elif position == 'bottom-left': self.lineToInc(dy = H) self.lineToInc(dx = W) elif position == 'bottom-right': self.lineToInc(dx = W) self.lineToInc(dy = -H) elif position == 'top-right': self.lineToInc(dy = -H) self.lineToInc(dx = -W)
def __init__(self, start_point, rect_size, shape, direction, facing): ''' :param start_point: ``QPointF`` Point from where this path will begin to draw. :param rect_size: ``QSizeF`` Size of the bounding rectangle for this path. :param shape: ``str`` in ``self.VALID_SHAPES`` Shape of the notch. :param direction: ``str`` in ``self.VALID_DIRECTIONS`` Indicates the direction of the drawing (using vectorial notation). :param facing: ``str`` in ``self.VALID_FACING_SIDES`` Indicates to which side the top of the trapezium is going to be pointing on. ''' if direction[1] == 'j': facing = vlarg('facing', facing.lower(), str, ('left', 'right')) else: facing = vlarg('facing', facing.lower(), str, ('up', 'down')) valid_shapes = [x.split('/')[0] for x in self.VALID_SHAPES] tf = 0.0 # top factor given_shape = shape shape = vlarg('shape', shape, str).strip() if not shape.count('/'): shape = vlarg('shape', shape, str, valid_shapes) else: sp = shape.split('/') shape = vlarg('shape', sp[0].strip(), str, valid_shapes) try: tf = float(sp[1]) if sp[1].strip() != '' else 0.0 except: raise ValueError("Argument 'shape' must have the format" +\ " '%%s/%%f'. Was given '%s'." % given_shape) tf = vlarg('shape', tf, float, range_='0.0|1.0') # setting up some useful dimensions W, H = rect_size.width(), rect_size.height() if direction[1] == 'j': tl = tf * H # top lenght (for vertical) ts = (H - tl)/2 # top spacing (for vertical) else: tl = tf * W # top lenght (for horizontal) ts = (W - tl)/2 # top spacing (for horizontal) QPainterPath.__init__(self, start_point) if shape == 'trig': if direction == '+j': if facing == 'left': self.lineToInc(-W, ts) self.lineToInc(dy = tl) self.lineToInc(W, ts) elif facing == 'right': self.lineToInc(W, ts) self.lineToInc(dy = tl) self.lineToInc(-W, ts) elif direction == '-j': if facing == 'left': self.lineToInc(-W, -ts) self.lineToInc(dy = -tl) self.lineToInc(W, -ts) elif facing == 'right': self.lineToInc(W, -ts) self.lineToInc(dy = -tl) self.lineToInc(-W, -ts) elif direction == '+i': if facing == 'up': self.lineToInc(ts, -H) self.lineToInc(dx = tl) self.lineToInc(ts, H) elif facing == 'down': self.lineToInc(ts, H) self.lineToInc(dx = tl) self.lineToInc(ts, -H) elif direction == '-i': if facing == 'up': self.lineToInc(-ts, -H) self.lineToInc(dx = -tl) self.lineToInc(-ts, H) elif facing == 'down': self.lineToInc(-ts, H) self.lineToInc(dx = -tl) self.lineToInc(-ts, -H) elif shape == 'arc': if direction == '+j': if facing == 'left': self.arcTo(self.x - W, self.y, 2*W, 2*ts, 90, 90) self.lineToInc(dy = tl) self.arcTo(self.x, self.y - ts, 2*W, 2*ts, 180, 90) elif facing == 'right': self.arcTo(self.x - W, self.y, 2*W, 2*ts, 90, -90) self.lineToInc(dy = tl) self.arcTo(self.x - 2*W, self.y - ts, 2*W, 2*ts, 0, -90) elif direction == '-j': if facing == 'left': self.arcTo(self.x - W, self.y - 2*ts, 2*W, 2*ts, -90, -90) self.lineToInc(dy = -tl) self.arcTo(self.x, self.y - ts, 2*W, 2*ts, 180, -90) elif facing == 'right': self.arcTo(self.x - W, self.y - 2*ts, 2*W, 2*ts, -90, 90) self.lineToInc(dy = -tl) self.arcTo(self.x - 2*W, self.y - ts, 2*W, 2*ts, 0, 90) elif direction == '+i': if facing == 'up': self.arcTo(self.x, self.y - H, 2*ts, 2*H, 180, -90) self.lineToInc(dx = tl) self.arcTo(self.x - ts, self.y, 2*ts, 2*H, 90, -90) elif facing == 'down': self.arcTo(self.x, self.y - H, 2*ts, 2*H, 180, 90) self.lineToInc(dx = tl) self.arcTo(self.x - ts, self.y - 2*H, 2*ts, 2*H, -90, 90) elif direction == '-i': if facing == 'up': self.arcTo(self.x - 2*ts, self.y - H, 2*ts, 2*H, 0, 90) self.lineToInc(dx = -tl) self.arcTo(self.x - ts, self.y, 2*ts, 2*H, 90, 90) elif facing == 'down': self.arcTo(self.x - 2*ts, self.y - H, 2*ts, 2*H, 0, -90) self.lineToInc(dx = -tl) self.arcTo(self.x - ts, self.y - 2*H, 2*ts, 2*H, -90, -90)
def __init__(self, start_point, rect_size, shape, direction, facing): ''' (QPointF, QSizeF, str in self.SHAPES, str in self.DIRECTIONS, str in self.FACING_SIDES) ''' vlarg('start_point', start_point, QPointF) vlarg('rect_size', rect_size, QSizeF) direction = vlarg('direction', direction.lower(), str, self.DIRECTIONS) vlarg('facing', facing, str) if direction[1] == 'j': facing = vlarg('facing', facing.lower(), str, ('left', 'right')) else: facing = vlarg('facing', facing.lower(), str, ('up', 'down')) valid_shapes = [x.split('/')[0] for x in self.SHAPES] tf = 0.0 # top factor given_shape = shape shape = vlarg('shape', shape, str).strip() if not shape.count('/'): shape = vlarg('shape', shape, str, valid_shapes) else: sp = shape.split('/') shape = vlarg('shape', sp[0].strip(), str, valid_shapes) try: tf = float(sp[1]) if sp[1].strip() != '' else 0.0 except: raise ValueError("Argument 'shape' must have the format" +\ " '%%s/%%f'. Was given '%s'." % given_shape) tf = vlarg('shape', tf, float, range_='0.0|1.0') # setting up some useful dimensions W, H = rect_size.width(), rect_size.height() if direction[1] == 'j': tl = tf * H # top lenght (for vertical) ts = (H - tl)/2 # top spacing (for vertical) else: tl = tf * W # top lenght (for horizontal) ts = (W - tl)/2 # top spacing (for horizontal) QPainterPath.__init__(self, start_point) if shape == 'trig': if direction == '+j': if facing == 'left': self.lineToInc(-W, ts) self.lineToInc(dy = tl) self.lineToInc(W, ts) elif facing == 'right': self.lineToInc(W, ts) self.lineToInc(dy = tl) self.lineToInc(-W, ts) elif direction == '-j': if facing == 'left': self.lineToInc(-W, -ts) self.lineToInc(dy = -tl) self.lineToInc(W, -ts) elif facing == 'right': self.lineToInc(W, -ts) self.lineToInc(dy = -tl) self.lineToInc(-W, -ts) elif direction == '+i': if facing == 'up': self.lineToInc(ts, -H) self.lineToInc(dx = tl) self.lineToInc(ts, H) elif facing == 'down': self.lineToInc(ts, H) self.lineToInc(dx = tl) self.lineToInc(ts, -H) elif direction == '-i': if facing == 'up': self.lineToInc(-ts, -H) self.lineToInc(dx = -tl) self.lineToInc(-ts, H) elif facing == 'down': self.lineToInc(-ts, H) self.lineToInc(dx = -tl) self.lineToInc(-ts, -H) elif shape == 'arc': if direction == '+j': if facing == 'left': self.arcTo(self.x - W, self.y, 2*W, 2*ts, 90, 90) self.lineToInc(dy = tl) self.arcTo(self.x, self.y - ts, 2*W, 2*ts, 180, 90) elif facing == 'right': self.arcTo(self.x - W, self.y, 2*W, 2*ts, 90, -90) self.lineToInc(dy = tl) self.arcTo(self.x - 2*W, self.y - ts, 2*W, 2*ts, 0, -90) elif direction == '-j': if facing == 'left': self.arcTo(self.x - W, self.y - 2*ts, 2*W, 2*ts, -90, -90) self.lineToInc(dy = -tl) self.arcTo(self.x, self.y - ts, 2*W, 2*ts, 180, -90) elif facing == 'right': self.arcTo(self.x - W, self.y - 2*ts, 2*W, 2*ts, -90, 90) self.lineToInc(dy = -tl) self.arcTo(self.x - 2*W, self.y - ts, 2*W, 2*ts, 0, 90) elif direction == '+i': if facing == 'up': self.arcTo(self.x, self.y - H, 2*ts, 2*H, 180, -90) self.lineToInc(dx = tl) self.arcTo(self.x - ts, self.y, 2*ts, 2*H, 90, -90) elif facing == 'down': self.arcTo(self.x, self.y - H, 2*ts, 2*H, 180, 90) self.lineToInc(dx = tl) self.arcTo(self.x - ts, self.y - 2*H, 2*ts, 2*H, -90, 90) elif direction == '-i': if facing == 'up': self.arcTo(self.x - 2*ts, self.y - H, 2*ts, 2*H, 0, 90) self.lineToInc(dx = -tl) self.arcTo(self.x - ts, self.y, 2*ts, 2*H, 90, 90) elif facing == 'down': self.arcTo(self.x - 2*ts, self.y - H, 2*ts, 2*H, 0, -90) self.lineToInc(dx = -tl) self.arcTo(self.x - ts, self.y - 2*H, 2*ts, 2*H, -90, -90)
def __init__(self, start_point, rect_size, shape, direction, facing): """ :param start_point: ``QPointF`` Point from where this path will begin to draw. :param rect_size: ``QSizeF`` Size of the bounding rectangle for this path. :param shape: ``str`` in ``self.VALID_SHAPES`` Shape of the notch. :param direction: ``str`` in ``self.VALID_DIRECTIONS`` Indicates the direction of the drawing (using vectorial notation). :param facing: ``str`` in ``self.VALID_FACING_SIDES`` Indicates to which side the top of the trapezium is going to be pointing on. """ if direction[1] == "j": facing = vlarg("facing", facing.lower(), str, ("left", "right")) else: facing = vlarg("facing", facing.lower(), str, ("up", "down")) valid_shapes = [x.split("/")[0] for x in self.VALID_SHAPES] tf = 0.0 # top factor given_shape = shape shape = vlarg("shape", shape, str).strip() if not shape.count("/"): shape = vlarg("shape", shape, str, valid_shapes) else: sp = shape.split("/") shape = vlarg("shape", sp[0].strip(), str, valid_shapes) try: tf = float(sp[1]) if sp[1].strip() != "" else 0.0 except: raise ValueError("Argument 'shape' must have the format" + " '%%s/%%f'. Was given '%s'." % given_shape) tf = vlarg("shape", tf, float, range_="0.0|1.0") # setting up some useful dimensions W, H = rect_size.width(), rect_size.height() if direction[1] == "j": tl = tf * H # top lenght (for vertical) ts = (H - tl) / 2 # top spacing (for vertical) else: tl = tf * W # top lenght (for horizontal) ts = (W - tl) / 2 # top spacing (for horizontal) QPainterPath.__init__(self, start_point) if shape == "trig": if direction == "+j": if facing == "left": self.lineToInc(-W, ts) self.lineToInc(dy=tl) self.lineToInc(W, ts) elif facing == "right": self.lineToInc(W, ts) self.lineToInc(dy=tl) self.lineToInc(-W, ts) elif direction == "-j": if facing == "left": self.lineToInc(-W, -ts) self.lineToInc(dy=-tl) self.lineToInc(W, -ts) elif facing == "right": self.lineToInc(W, -ts) self.lineToInc(dy=-tl) self.lineToInc(-W, -ts) elif direction == "+i": if facing == "up": self.lineToInc(ts, -H) self.lineToInc(dx=tl) self.lineToInc(ts, H) elif facing == "down": self.lineToInc(ts, H) self.lineToInc(dx=tl) self.lineToInc(ts, -H) elif direction == "-i": if facing == "up": self.lineToInc(-ts, -H) self.lineToInc(dx=-tl) self.lineToInc(-ts, H) elif facing == "down": self.lineToInc(-ts, H) self.lineToInc(dx=-tl) self.lineToInc(-ts, -H) elif shape == "arc": if direction == "+j": if facing == "left": self.arcTo(self.x - W, self.y, 2 * W, 2 * ts, 90, 90) self.lineToInc(dy=tl) self.arcTo(self.x, self.y - ts, 2 * W, 2 * ts, 180, 90) elif facing == "right": self.arcTo(self.x - W, self.y, 2 * W, 2 * ts, 90, -90) self.lineToInc(dy=tl) self.arcTo(self.x - 2 * W, self.y - ts, 2 * W, 2 * ts, 0, -90) elif direction == "-j": if facing == "left": self.arcTo(self.x - W, self.y - 2 * ts, 2 * W, 2 * ts, -90, -90) self.lineToInc(dy=-tl) self.arcTo(self.x, self.y - ts, 2 * W, 2 * ts, 180, -90) elif facing == "right": self.arcTo(self.x - W, self.y - 2 * ts, 2 * W, 2 * ts, -90, 90) self.lineToInc(dy=-tl) self.arcTo(self.x - 2 * W, self.y - ts, 2 * W, 2 * ts, 0, 90) elif direction == "+i": if facing == "up": self.arcTo(self.x, self.y - H, 2 * ts, 2 * H, 180, -90) self.lineToInc(dx=tl) self.arcTo(self.x - ts, self.y, 2 * ts, 2 * H, 90, -90) elif facing == "down": self.arcTo(self.x, self.y - H, 2 * ts, 2 * H, 180, 90) self.lineToInc(dx=tl) self.arcTo(self.x - ts, self.y - 2 * H, 2 * ts, 2 * H, -90, 90) elif direction == "-i": if facing == "up": self.arcTo(self.x - 2 * ts, self.y - H, 2 * ts, 2 * H, 0, 90) self.lineToInc(dx=-tl) self.arcTo(self.x - ts, self.y, 2 * ts, 2 * H, 90, 90) elif facing == "down": self.arcTo(self.x - 2 * ts, self.y - H, 2 * ts, 2 * H, 0, -90) self.lineToInc(dx=-tl) self.arcTo(self.x - ts, self.y - 2 * H, 2 * ts, 2 * H, -90, -90)