예제 #1
0
 def ellipse(self, x, y, width, height, draw=True, **kwargs):
     '''Draw an ellipse starting from (x,y)'''
     path = self.BezierPath(**kwargs)
     path.ellipse(x,y,width,height)
     if draw:
         path.draw()
     return path
예제 #2
0
 def ellipse(self, x, y, width, height, draw=True, **kwargs):
     '''Draw an ellipse starting from (x,y)'''
     path = self.BezierPath(**kwargs)
     path.ellipse(x, y, width, height, self.ellipsemode)
     if draw:
         path.draw()
     return path
예제 #3
0
    def text(self,
             txt,
             x,
             y,
             width=None,
             height=1000000,
             outline=False,
             draw=True,
             **kwargs):
        """Draws a string of text according to the current font settings.

        :param txt: Text to output
        :param x: x-coordinate of the top left corner
        :param y: y-coordinate of the top left corner
        :param width: text width
        :param height: text height
        :param outline: If True, draws a path instead of a text object (defaults to False)
        :param draw: Set to False to inhibit immediate drawing (defaults to True)
        :return: Path object representing the text.
        """
        txt = self.Text(txt,
                        x,
                        y,
                        width,
                        height,
                        outline=outline,
                        ctx=None,
                        **kwargs)
        if outline:
            path = txt.path
            if draw:
                path.draw()
            return path
        return txt
예제 #4
0
 def oval(self, x, y, width, height, draw=True, **kwargs):
     '''Draw an ellipse starting from (x,y) -  ovals and ellipses are not the same'''
     path = self.BezierPath(**kwargs)
     path.ellipse(x, y, width, height)
     if draw:
         path.draw()
     return path
예제 #5
0
    def load(self, dir=''):
        print("Detected pickled data, unpickling...")

        # Load the tree from the pickled json string
        pickleFile = open(dir + self.pickleID, 'r')
        jsonString = pickleFile.read()
        pickleFile.close()

        saved = jsonpickle.decode(jsonString)

        self.tree = saved['tree']
        self.paths = np.array(saved['paths'])
        self.seedAmt = saved['seeds']
        self.state = saved['state']

        self.mergeAmt = len(self.paths) - self.seedAmt

        startState = self.state

        if startState > 0:
            self.treeDone()
        if startState > 1:
            for path in self.paths[:self.seedAmt]:
                path.draw(self, mode=self.ui.ColorValue.currentIndex())
            self.pathsDone()
        if startState > 2:
            self.hierDone()

        print("Restored data with state %d" % startState)
예제 #6
0
    def textpath(self,
                 txt,
                 x,
                 y,
                 width=None,
                 height=1000000,
                 draw=False,
                 **kwargs):
        '''
        Generates an outlined path of the input text.

        :param txt: Text to output
        :param x: x-coordinate of the top left corner
        :param y: y-coordinate of the top left corner
        :param width: text width
        :param height: text height
        :param draw: Set to False to inhibit immediate drawing (defaults to False)
        :return: Path object representing the text.
        '''
        txt = self.Text(txt,
                        x,
                        y,
                        width,
                        height,
                        enableRendering=False,
                        **kwargs)
        path = txt.path
        if draw:
            path.draw()
        return path
예제 #7
0
 def oval(self, x, y, width, height, draw=True, **kwargs):
     '''Draw an ellipse starting from (x,y) -  ovals and ellipses are not the same'''
     path = self.BezierPath(**kwargs)
     path.ellipse(x, y, width, height, self.ellipsemode)
     if draw:
         path.draw()
     return path
예제 #8
0
파일: drawing.py 프로젝트: nedbat/zellij
 def multi_stroke(self, paths, styles):
     for width, color in styles:
         self.set_line_width(width)
         for path in paths:
             path.draw(self)
             if callable(color):
                 self.set_source_rgb(*color())
             else:
                 self.set_source_rgb(*color)
             self.stroke()
예제 #9
0
 def drawpath(self,path, **kwargs):
     if isinstance(path, BezierPath):
         p = self.BezierPath(path=path, **kwargs)
         p.draw()
     elif isinstance(path, Image):
         path.draw() # Is this right ? - added to make test_clip_4.bot work
     elif hasattr(path, '__iter__'):
         p = self.BezierPath()
         for point in path:
             p.addpoint(point)
         p.draw()
예제 #10
0
 def drawpath(self, path, **kwargs):
     if isinstance(path, BezierPath):
         p = self.BezierPath(path=path, **kwargs)
         p.draw()
     elif isinstance(path, Image):
         path.draw()  # Is this right ? - added to make test_clip_4.bot work
     elif hasattr(path, '__iter__'):
         p = self.BezierPath()
         for point in path:
             p.addpoint(point)
         p.draw()
예제 #11
0
    def ellipse(self, x, y, width, height, draw=True, **kwargs):
        """Draw an ellipse.

        :param x: top left x-coordinate
        :param y: top left y-coordinate
        :param width: ellipse width
        :param height: ellipse height
        :param boolean draw: whether to draw the shape on the canvas or not
        :return: BezierPath representing the ellipse
        """

        path = self.BezierPath(**kwargs)
        path.ellipse(x, y, width, height, self.ellipsemode)
        if draw:
            path.draw()
        return path
예제 #12
0
    def textpath(self, txt, x, y, width=None, height=1000000, draw=False, **kwargs):
        '''
        Generates an outlined path of the input text.

        :param txt: Text to output
        :param x: x-coordinate of the top left corner
        :param y: y-coordinate of the top left corner
        :param width: text width
        :param height: text height
        :param draw: Set to False to inhibit immediate drawing (defaults to False)
        :return: Path object representing the text.
        '''
        txt = self.Text(txt, x, y, width, height, enableRendering=False, **kwargs)
        path = txt.path
        if draw:
            path.draw()
        return path
예제 #13
0
    def arrow(self, x, y, width, type=NORMAL, draw=True, **kwargs):
        '''Draw an arrow.

        Arrows can be two types: NORMAL or FORTYFIVE.

        :param x: top left x-coordinate
        :param y: top left y-coordinate
        :param width: width of arrow
        :param type:  NORMAL or FORTYFIVE
        :draw:  If True draws arrow immediately

        :return: Path object representing the arrow.
        '''
        # Taken from Nodebox
        path = self.BezierPath(**kwargs)
        if type == self.NORMAL:
            head = width * .4
            tail = width * .2
            path.moveto(x, y)
            path.lineto(x - head, y + head)
            path.lineto(x - head, y + tail)
            path.lineto(x - width, y + tail)
            path.lineto(x - width, y - tail)
            path.lineto(x - head, y - tail)
            path.lineto(x - head, y - head)
            path.lineto(x, y)
        elif type == self.FORTYFIVE:
            head = .3
            tail = 1 + head
            path.moveto(x, y)
            path.lineto(x, y + width * (1 - head))
            path.lineto(x - width * head, y + width)
            path.lineto(x - width * head, y + width * tail * .4)
            path.lineto(x - width * tail * .6, y + width)
            path.lineto(x - width, y + width * tail * .6)
            path.lineto(x - width * tail * .4, y + width * head)
            path.lineto(x - width, y + width * head)
            path.lineto(x - width * (1 - head), y)
            path.lineto(x, y)
        else:
            raise NameError(
                _("arrow: available types for arrow() are NORMAL and FORTYFIVE\n"
                  ))
        if draw:
            path.draw()
        return path
예제 #14
0
    def rect(self, x, y, width, height, roundness=0.0, draw=True, **kwargs):
        """Draw a rectangle.

        :param x: top left x-coordinate
        :param y: top left y-coordinate
        :param width: rectangle width
        :param height: rectangle height
        :param roundness: rounded corner radius
        :param boolean draw: whether to draw the shape on the canvas or not
        :param fill: fill color
        :return: BezierPath representing the rectangle
        """
        path = self.BezierPath(**kwargs)
        path.rect(x, y, width, height, roundness, self.rectmode)
        if draw:
            path.draw()
        return path
예제 #15
0
    def arrow(self, x, y, width, type=NORMAL, draw=True, **kwargs):
        '''Draw an arrow.

        Arrows can be two types: NORMAL or FORTYFIVE.

        :param x: top left x-coordinate
        :param y: top left y-coordinate
        :param width: width of arrow
        :param type:  NORMAL or FORTYFIVE
        :draw:  If True draws arrow immediately

        :return: Path object representing the arrow. 
        '''
        # Taken from Nodebox
        path = self.BezierPath(**kwargs)
        if type == self.NORMAL:
            head = width * .4
            tail = width * .2
            path.moveto(x, y)
            path.lineto(x-head, y+head)
            path.lineto(x-head, y+tail)
            path.lineto(x-width, y+tail)
            path.lineto(x-width, y-tail)
            path.lineto(x-head, y-tail)
            path.lineto(x-head, y-head)
            path.lineto(x, y)
        elif type == self.FORTYFIVE:
            head = .3 
            tail = 1 + head
            path.moveto(x, y)
            path.lineto(x, y+width*(1-head))
            path.lineto(x-width*head, y+width)
            path.lineto(x-width*head, y+width*tail*.4)
            path.lineto(x-width*tail*.6, y+width)
            path.lineto(x-width, y+width*tail*.6)
            path.lineto(x-width*tail*.4, y+width*head)
            path.lineto(x-width, y+width*head)
            path.lineto(x-width*(1-head), y)
            path.lineto(x, y)
        else:
            raise NameError(_("arrow: available types for arrow() are NORMAL and FORTYFIVE\n"))
        if draw:
            path.draw()
        return path
예제 #16
0
    def rect(self, x, y, width, height, roundness=0.0, draw=True, **kwargs):
        '''
        Draw a rectangle from x, y of width, height.

        :param startx: top left x-coordinate
        :param starty: top left y-coordinate

        :param width: height  Size of rectangle.
        :roundness: Corner roundness defaults to 0.0 (a right-angle).
        :draw: If True draws immediately.
        :fill: Optionally pass a fill color.

        :return: path representing the rectangle.

        '''
        path = self.BezierPath(**kwargs)
        path.rect(x, y, width, height, roundness, self.rectmode)
        if draw:
            path.draw()
        return path
예제 #17
0
    def rect(self, x, y, width, height, roundness=0.0, draw=True, **kwargs):
        '''
        Draw a rectangle from x, y of width, height.

        :param startx: top left x-coordinate
        :param starty: top left y-coordinate

        :param width: height  Size of rectangle.
        :roundness: Corner roundness defaults to 0.0 (a right-angle).
        :draw: If True draws immediately.
        :fill: Optionally pass a fill color.

        :return: path representing the rectangle.

        '''
        path = self.BezierPath(**kwargs)
        path.rect(x, y, width, height, roundness, self.rectmode)
        if draw:
            path.draw()
        return path
예제 #18
0
    def text(self, txt, x, y, width=None, height=1000000, outline=False, draw=True, **kwargs):
        '''
        Draws a string of text according to current font settings.

        :param txt: Text to output
        :param x: x-coordinate of the top left corner
        :param y: y-coordinate of the top left corner
        :param width: text width
        :param height: text height
        :param outline: If True draws outline text (defaults to False)
        :param draw: Set to False to inhibit immediate drawing (defaults to True)
        :return: Path object representing the text.
        '''
        txt = self.Text(txt, x, y, width, height, outline=outline, ctx=None, **kwargs)
        if outline:
          path = txt.path
          if draw:
              path.draw()
          return path
        else:
          return txt
예제 #19
0
파일: drawing.py 프로젝트: nedbat/zellij
 def draw_paths(self, paths, **style_kwargs):
     with self.style(**style_kwargs):
         for path in paths:
             path.draw(self)
         self.stroke()
예제 #20
0
파일: drawing.py 프로젝트: nedbat/zellij
 def draw_path(self, path, **style_kwargs):
     with self.style(**style_kwargs):
         path.draw(self)
         self.stroke()