示例#1
0
 def size(self, width, height):
     CanvasContext.size(self, width, height)
     # To keep the WIDTH and HEIGHT properties up to date in the executing script,
     # the Context object must have access to its namespace. Normally, we passed this
     # during construction time.
     self._ns["WIDTH"] = width
     self._ns["HEIGHT"] = height
示例#2
0
 def font(self, fontname=None, fontsize=None):
     if fontname is not None and fontsize is not None:
         return CanvasContext.font(self, fontname, fontsize)
     elif fontname is not None:
         return CanvasContext.font(self, fontname)
     elif fontsize is not None:
         CanvasContext.fontsize(self, fontsize)
     return CanvasContext.font(self)
示例#3
0
 def rect(self, x, y, width, height, roundness=0.0, draw=True, **kwargs):
     if roundness == 0:
         p = CanvasContext.rect(self, x, y, width, height, Boolean(draw))
     else:
         rw = roundness * width * 0.5
         rh = roundness * height * 0.5
         p = CanvasContext.rect(self, x, y, width, height, rw, rh, Boolean(draw))
     self._setAttributesFromKwargs(p, **kwargs)
     return p
示例#4
0
 def __init__(self, canvas=None, ns=None):
     args = canvas is not None and [canvas] or []
     CanvasContext.__init__(self, *args)
     if ns is None:
         ns = {}
     self._ns = ns
     
     # todo: better way to handle mouse events
     self._ns["MOUSEX"] = 0
     self._ns["MOUSEY"] = 0
     self._ns["mousedown"] = False
示例#5
0
 def text(self, txt, x, y, width=0, height=0, outline=False, draw=True, **kwargs):
     if outline:
         t = CanvasContext.text(self, unicode(txt), x, y, width, height, Boolean(False))
         p = t.path
         self._setAttributesFromKwargs(p, **kwargs)
         if draw:
             self.addPath(p)
         return p
     else:
         t = CanvasContext.text(self, unicode(txt), x, y, width, height, Boolean(draw))
         self._setAttributesFromKwargs(t, **kwargs)
         return t
示例#6
0
 def imagesize(self, path, data=None):
     if data is not None:
         from nodebox.graphics import Image
         arg = Image.fromData(data).awtImage
     else:
         arg = path
     return CanvasContext.imagesize(self, arg)
示例#7
0
 def image(self, path, x, y, width=None, height=None, alpha=1.0, data=None, draw=True, **kwargs):
     if data is not None:
         from nodebox.graphics import Image
         arg = Image.fromData(data).awtImage
     else:
         arg = path
     img = CanvasContext.image(self, arg, x, y, width, height, alpha, Boolean(draw))
     # todo: handle data and kwargs
     return img
示例#8
0
    def findpath(self, points, curvature=1.0):
        # The list of points consists of Point objects,
        # but it shouldn't crash on something straightforward
        # as someone supplying a list of (x,y)-tuples.

        from types import TupleType
        for i, pt in enumerate(points):
            if type(pt) == TupleType:
                points[i] = Point(pt[0], pt[1])
        return CanvasContext.findpath(self, points, curvature)
示例#9
0
 def arrow(self,
           x,
           y,
           width=100,
           type=CanvasContext.NORMAL,
           draw=True,
           **kwargs):
     p = CanvasContext.arrow(self, x, y, width, type, Boolean(draw))
     self._setAttributesFromKwargs(p, **kwargs)
     return p
示例#10
0
 def star(self,
          startx,
          starty,
          points=20,
          outer=100,
          inner=50,
          draw=True,
          **kwargs):
     p = CanvasContext.star(self, startx, starty, points, outer, inner,
                            Boolean(draw))
     self._setAttributesFromKwargs(p, **kwargs)
     return p
示例#11
0
 def color(self, *args):
     if len(args) == 1 and isinstance(args[0], tuple):
         args = args[0]
     return CanvasContext.color(self, *args)
示例#12
0
 def ellipse(self, x, y, width, height, draw=True, **kwargs):
     p = CanvasContext.ellipse(self, x, y, width, height, Boolean(draw))
     self._setAttributesFromKwargs(p, **kwargs)
     return p
示例#13
0
 def stroke(self, *args):
     if len(args) == 1 and isinstance(args[0], tuple):
         args = args[0]
     return CanvasContext.stroke(self, *args)
示例#14
0
 def lineheight(self, lineheight=None):
     if lineheight is not None:
         return CanvasContext.lineheight(self, lineheight)
     return CanvasContext.lineheight(self)
示例#15
0
 def autoclosepath(self, close=None):
     if close is None:
         return CanvasContext.autoclosepath(self)
     else:
         return CanvasContext.autoclosepath(self, Boolean(close))
示例#16
0
 def endpath(self, draw=True):
     return CanvasContext.endpath(self, Boolean(draw))
示例#17
0
 def arrow(self, x, y, width=100, type=CanvasContext.NORMAL, draw=True, **kwargs):
     p = CanvasContext.arrow(self, x, y, width, type, Boolean(draw))
     self._setAttributesFromKwargs(p, **kwargs)
     return p
示例#18
0
 def textheight(self, txt, height=None, **kwargs):
     if height is None: height = 0
     h = CanvasContext.textheight(self, unicode(txt), height)
     # todo: handle kwargs?
     return h
示例#19
0
 def textwidth(self, txt, width=None, **kwargs):
     if width is None: width = 0
     w = CanvasContext.textwidth(self, unicode(txt), width)
     # todo: handle kwargs?
     return w
示例#20
0
 def textmetrics(self, txt, width=None, height=None, **kwargs):
     if width is None: width = 0
     if height is None: height = 0
     r = CanvasContext.textmetrics(self, unicode(txt), width, height)
     # todo: handle kwargs?
     return r
示例#21
0
 def textpath(self, txt, x, y, width=None, height=None, **kwargs):
     if width is None: width = 0
     if height is None: height = 0
     p = CanvasContext.textpath(self, unicode(txt), x, y, width, height)
     self._setAttributesFromKwargs(p, **kwargs)
     return p
示例#22
0
 def strokewidth(self, width=None):
     if width is not None:
         return CanvasContext.strokewidth(self, width)
     return CanvasContext.strokewidth(self)
示例#23
0
 def align(self, align=None):
     if align is not None:
         return CanvasContext.align(self, align)
     return CanvasContext.align(self)
示例#24
0
 def line(self, x1, y1, x2, y2, draw=True, **kwargs):
     p = CanvasContext.line(self, x1, y1, x2, y2, Boolean(draw))
     self._setAttributesFromKwargs(p, **kwargs)
     return p
示例#25
0
 def star(self, startx, starty, points=20, outer=100, inner=50, draw=True, **kwargs):
     p = CanvasContext.star(self, startx, starty, points, outer, inner, Boolean(draw))
     self._setAttributesFromKwargs(p, **kwargs)
     return p
示例#26
0
 def colorrange(self, range=None):
     if range is not None:
         return CanvasContext.colorrange(self, range)
     return CanvasContext.colorrange(self)
示例#27
0
 def beginpath(self, x=None, y=None):
     if x != None and y != None:
         CanvasContext.beginpath(self, x, y)
     else:
         CanvasContext.beginpath(self)
示例#28
0
 def colormode(self, mode=None, range=None):
     if mode is None:
         if range is not None:
             CanvasContext.colorrange(self, range)
         return CanvasContext.colormode(self)
     return CanvasContext.colormode(self, mode, range)
示例#29
0
 def drawpath(self, path, **kwargs):
     CanvasContext.drawpath(self, path)
     self._setAttributesFromKwargs(path, **kwargs)
示例#30
0
 def var(self, *args):
     CanvasContext.var(self, *args)
     v = self.findVar(args[0])
     if v is not None:
         self._ns[v.name] = v.value
示例#31
0
 def background(self, *args):
     if len(args) == 1 and isinstance(args[0], tuple):
         args = args[0]
     return CanvasContext.background(self, *args)
示例#32
0
 def fontsize(self, fontsize=None):
     if fontsize is not None:
         return CanvasContext.fontsize(self, fontsize)
     return CanvasContext.fontsize(self)