Ejemplo n.º 1
0
    def recompute(self):
        h1, h2, h3, theta, p1, p2 = self.h1, self.h2, self.h3, self.theta, \
                                    self.p1, self.p2
        xvect = (p2 - p1).normalized()
        angle = (p2 - p1).polar()[1] + theta * pi / 180
        yvect = Polar(1, angle)

        new = Sketch.CreatePath()
        newpaths = [new]

        new.AppendLine(p1)
        new.AppendLine(p1 + h1 * yvect)
        new = Sketch.CreatePath()
        newpaths.append(new)
        new.AppendLine(p1 + h3 * yvect)
        new.AppendLine(p2 + h3 * yvect)
        new = Sketch.CreatePath()
        newpaths.append(new)
        new.AppendLine(p2)
        new.AppendLine(p2 + h2 * yvect)

        for new in newpaths:
            new.Transform(self.trafo)
        if self.objects:
            self.objects[0].SetPaths(newpaths)
        else:
            lines = Sketch.PolyBezier(tuple(newpaths))
            self.set_objects([lines])
Ejemplo n.º 2
0
def main():
    Sketch.init_lib()
    if len(sys.argv) != 3:
        sys.stderr.write(__doc__)
        sys.exit(1)

    convert(sys.argv[1], sys.argv[2])
Ejemplo n.º 3
0
    def recompute(self):
        h1, h2, n, p1, p2 = self.h1, self.h2, self.n, self.p1, self.p2

        xvect = (p2 - p1).normalized()
        yvect = Point(xvect.y, -xvect.x)

        new = Sketch.CreatePath()
        newpaths = [new]

        new.AppendLine(p1)
        new.AppendLine(p2)
        new.Transform(self.trafo)

        for i in range(0, n + 1):
            new = Sketch.CreatePath()
            newpaths.append(new)

            p = p1 + (p2 - p1) / float(n) * i
            new.AppendLine(p - yvect * h1)
            new.AppendLine(p + yvect * h2)
            new.Transform(self.trafo)

        if self.objects:
            self.objects[0].SetPaths(newpaths)
        else:
            lines = Sketch.PolyBezier(tuple(newpaths))
            self.set_objects([lines])
Ejemplo n.º 4
0
def main():
    Sketch.init_lib()
    if len(sys.argv) != 3:
        sys.stderr.write(__doc__)
        sys.exit(1)

    convert(sys.argv[1], sys.argv[2])
Ejemplo n.º 5
0
    def recompute(self):
        new = Sketch.CreatePath()
        newpaths = [new]
        p1, p2, h, n = self.p1, self.p2, self.h, self.n

        y1 = f1 * h * uy
        y2 = f2 * h * uy
        y3 = h * uy
        x = (p2 - p1) / float(n)

        new.AppendLine(p1)
        new.AppendLine(p2)
        new.AppendLine(p2 + y3)

        p = p2
        new.AppendLine(p + y1)
        for i in range(n):
            p = p - x
            new.AppendLine(p + y1)
            new.AppendLine(p + y2)
            new.AppendLine(p + y1)

        new.AppendLine(p1 + y1)
        new.AppendLine(p1 + y3)
        new.AppendLine(p1)

        new.Transform(self.trafo)
        if self.objects:
            self.objects[0].SetPaths(newpaths)
        else:
            obj = Sketch.PolyBezier(tuple(newpaths))
            self.set_objects([obj])
Ejemplo n.º 6
0
def main():
    import Sketch
    Sketch.init_lib()

    draw_printable = 1
    draw_visible = 0
    embed_fonts = 0
    eps_for = util.get_real_username()
    eps_date = util.current_date()
    eps_title = None
    rotate = 0

    import getopt
    opts, args = getopt.getopt(sys.argv[1:], 'hprved:f:t:', [
        'help', 'noprintable', 'rotate', 'visible', 'embed-fonts', 'for=',
        'date=', 'title='
    ])

    for optchar, value in opts:
        if optchar == '-h' or optchar == '--help':
            print_usage()
            return -1
        elif optchar == '-p' or optchar == '--noprintable':
            draw_printable = 0
        elif optchar == '-v' or optchar == '--visible':
            draw_visible = 1
        elif optchar == '-d' or optchar == '--date':
            eps_date = value
        elif optchar == '-f' or optchar == '--for':
            eps_for = value
        elif optchar == '-r' or optchar == '--rotate':
            rotate = 1
        elif optchar == '-t' or optchar == '--title':
            eps_title = value
        elif optchar == '-e' or optchar == '--embed-fonts':
            embed_fonts = 1

    if len(args) not in (1, 2):
        print_usage()
        return -1

    filename = args[0]
    if len(args) > 1:
        psfile = args[1]
    else:
        psfile = sys.stdout

    if eps_title is None:
        eps_title = os.path.basename(filename)

    sk2ps(filename,
          psfile,
          printable=draw_printable,
          visible=draw_visible,
          For=eps_for,
          CreationDate=eps_date,
          Title=eps_title,
          rotate=rotate,
          embed_fonts=embed_fonts)
Ejemplo n.º 7
0
 def init_tk(self, screen_name=None, geometry=None):
     TkApplication.init_tk(self, screen_name=screen_name, geometry=geometry)
     root = self.root
     Sketch.init_modules_from_widget(root)
     root.iconbitmap(pixmaps.Icon)
     root.iconmask(pixmaps.Icon_mask)
     root.iconname('Skencil')
     root.group(root)
     config.add_options(root)
Ejemplo n.º 8
0
    def init_tk(self, screen_name = None, geometry = None):
	TkApplication.init_tk(self, screen_name = screen_name,
			      geometry = geometry)
	root = self.root
	Sketch.init_modules_from_widget(root)
	root.iconbitmap(pixmaps.Icon)
	root.iconmask(pixmaps.Icon_mask)
	root.iconname('Skencil')
	root.group(root)
	config.add_options(root)
Ejemplo n.º 9
0
def main():
    import Sketch
    Sketch.init_lib()

    draw_printable = 1
    draw_visible = 0
    embed_fonts = 0
    eps_for = util.get_real_username()
    eps_date = util.current_date()
    eps_title = None
    rotate = 0

    import getopt
    opts, args = getopt.getopt(sys.argv[1:], 'hprved:f:t:',
                               ['help', 'noprintable', 'rotate', 'visible',
                                'embed-fonts', 'for=', 'date=', 'title='])

    for optchar, value in opts:
        if optchar == '-h' or optchar == '--help':
            print_usage()
            return -1
        elif optchar == '-p' or optchar == '--noprintable':
            draw_printable = 0
        elif optchar == '-v' or optchar == '--visible':
            draw_visible = 1
        elif optchar == '-d' or optchar == '--date':
            eps_date = value
        elif optchar == '-f' or optchar == '--for':
            eps_for = value
        elif optchar == '-r' or optchar == '--rotate':
            rotate = 1
        elif optchar == '-t' or optchar == '--title':
            eps_title = value
        elif optchar == '-e' or optchar == '--embed-fonts':
            embed_fonts = 1

    if len(args) not in (1, 2):
        print_usage()
        return -1

    filename = args[0]
    if len(args) > 1:
        psfile = args[1]
    else:
        psfile = sys.stdout

    if eps_title is None:
        eps_title = os.path.basename(filename)

    sk2ps(filename, psfile, printable= draw_printable, visible = draw_visible,
          For = eps_for, CreationDate = eps_date, Title = eps_title,
          rotate = rotate, embed_fonts = embed_fonts)
Ejemplo n.º 10
0
    def recompute(self):
        new = Sketch.CreatePath()
        newpaths = [new]
        p1, p2 = self.p1, self.p2

        new.AppendLine(p1)
        new.AppendLine(p2)

        new.Transform(self.trafo)
        if self.objects:
            self.objects[0].SetPaths(newpaths)
        else:
            obj = Sketch.PolyBezier(tuple(newpaths))
            self.set_objects([obj])
Ejemplo n.º 11
0
    def recompute(self):
        h1, h2, w1, w2 = self.GetData()
        new = Sketch.CreatePath()
        newpaths = [new]
        for p in ((-w1, 0), (0, -h2 - h1), (0, -h1), (w2, -h1), (w2, -h2 - h1),
                  (w2 + w1, 0), (w2, h2 + h1), (w2, h1), (0, h1), (0, h2 + h1),
                  (-w1, 0)):
            new.AppendLine(p)

        new.Transform(self.trafo)
        if self.objects:
            self.objects[0].SetPaths(newpaths)
        else:
            obj = Sketch.PolyBezier(tuple(newpaths))
            self.set_objects([obj])
Ejemplo n.º 12
0
    def recompute(self):
        w1, w2, p1, p2 = self.w1, self.w2, self.p1, self.p2

        xvect = (p2 - p1).normalized()

        new = Sketch.CreatePath()
        newpaths = [new]

        new.AppendLine(p1 - w1 * xvect)
        new.AppendLine(p2 + w2 * xvect)
        new.Transform(self.trafo)
        if self.objects:
            self.objects[0].SetPaths(newpaths)
        else:
            lines = Sketch.PolyBezier(tuple(newpaths))
            self.set_objects([lines])
Ejemplo n.º 13
0
def loadfromschooldata(string):
    # init an empty sketch
    sketch = Sketch.Sketch(sketch_id='shape', strokes=[])

    # find lines
    lines = string.splitlines()
    laststroke = -1
    pointid = 0
    strokelist = []

    # for each line
    for line in lines:
        # obtain point parameters
        numbers = line.split('\t')

        # if a new stroke is found
        if int(numbers[2]) > laststroke:
            # init a new empty stroke
            laststroke = laststroke + 1
            strokelist.append(Stroke.Stroke(str(laststroke)))

        # add the point to its corresponding stroke
        strokelist[laststroke].addPoint(
            Point.Point('p' + str(pointid), float(numbers[3]),
                        float(numbers[0]), float(numbers[1])))
        pointid = pointid + 1

    # finally add the strokes to the sketch
    for stroke in strokelist:
        sketch.addStrokes(stroke)

    return sketch
Ejemplo n.º 14
0
def loadURL(url):
    global rgba
    if Skribbler.width == 0 or Skribbler.height == 0:
        print("Canvas is not initialized! Try running 'init'")
        return
    rgba = Sketch.getRGBAFrom(cmd.replace("url ", ""), Skribbler.width,
                              Skribbler.height)
    print("Loaded image successfully!")
Ejemplo n.º 15
0
 def recompute(self):
     path = Sketch.CreatePath()
     newpaths = [path]
     h = self.h
     path.AppendLine((5, 5))
     path.AppendBezier((7, 5 + h / 2.), (12, 5 + h), (15, 5 + h))
     path.AppendBezier((18, 5 + h), (22, 5 + h / 2), (25, 5))
     path.Transform(self.trafo)
     if self.objects:
         self.objects[1].SetPaths(tuple(newpaths))
     else:
         skull = Sketch.Ellipse(Scale(22))
         skull.Transform(Translation(15, 16))
         mouth = Sketch.PolyBezier(tuple(newpaths))
         r_eye = Sketch.Ellipse(Scale(3))
         l_eye = Sketch.Ellipse(Scale(3))
         l_eye.Transform(Translation(7, 21))
         r_eye.Transform(Translation(22, 21))
         self.set_objects([skull, mouth, r_eye, l_eye])
Ejemplo n.º 16
0
def main():
    import Sketch, Sketch.config
    Sketch.Issue(None, Sketch.const.INITIALIZE)
    #plugins.load_plugin_configuration(config.plugin_path)

    use_bbox = 0
    resolution = 72.0
    steps = alpha = None

    import getopt
    opts, args = getopt.getopt(
        sys.argv[1:], 'bhr:s:A:',
        ['help', 'bbox', 'resolution=', 'gradient-steps=', 'alpha-bits='])

    for optchar, value in opts:
        if optchar == '-h' or optchar == '--help':
            print_usage()
            return -1
        elif optchar == '-b' or optchar == '--bbox':
            use_bbox = 1
        elif optchar == '-r' or optchar == '--resolution':
            resolution = float(value)
        elif optchar == '-s' or optchar == '--gradient-steps':
            steps = float(value)
        elif optchar == '-A' or optchar == '--alpha-bits':
            alpha = int(value)
            if alpha not in (1, 2, 4):
                sys.stderr.write("sk2ppm: alpha-bits value must be one of"
                                 " 1, 2 or 4\n")
                return -1

    if len(args) not in (1, 2):
        print_usage()
        return -1

    if steps is not None:
        Sketch.config.preferences.gradient_steps_print = steps

    filename = args[0]
    if len(args) > 1:
        ppmfile = args[1]
    else:
        ppmfile = sys.stdout

    doc = load.load_drawing(filename)

    context = Context()
    context.document = doc

    export_raster(context,
                  ppmfile,
                  resolution,
                  use_bbox,
                  format="ppm",
                  antialias=alpha)
Ejemplo n.º 17
0
def main():
    global application

    try:
	options = process_args(sys.argv[1:])
    except getopt.error:
	sys.stderr.write(Sketch._(usage))
	sys.exit(1)

    if options.args:
	filename = options.args[0]
    else:
	filename = ''

    Sketch.init_ui()

    from Sketch.UI.skapp import SketchApplication
    application = SketchApplication(filename, options.display, options.geometry, options.participant, options.f1, options.f2, options.f3,options.f4,run_script = options.run_script)
    Sketch.Issue(None, Sketch.const.APP_INITIALIZED, application)
    application.Run()
    application.SavePreferences()
Ejemplo n.º 18
0
    def recompute(self):
        p1, p2, p3, p4 = self.p1, self.p2, self.p3, self.p4
        
        new = Sketch.CreatePath()
        newpaths = [new]

        new.AppendLine(p1)
        new.AppendLine(p2)        
        new.Transform(self.trafo)

        new = Sketch.CreatePath()
        newpaths.append(new)
        new.AppendLine(p3)
        new.AppendLine(p4)        
        new.Transform(self.trafo)

        if self.objects:
            self.objects[0].SetPaths(newpaths)
        else:
            lines = Sketch.PolyBezier(tuple(newpaths))
            self.set_objects([lines])
Ejemplo n.º 19
0
    def recompute(self):
        r1 = self.r1
        r2 = self.r2
        theta1 = self.theta1
        theta2 = self.theta2
        if theta2 < theta1:
            theta2 = theta2+360

        ring2 = Sketch.Ellipse(start_angle=theta1*pi/180,
                               end_angle=theta2*pi/180,
                               arc_type=0).Paths()[0]
        ring1 = ring2.Duplicate()
        ring2.Transform(Scale(r2))
        ring1.Transform(Scale(r1))
        new = Sketch.CreatePath()
        newpaths = [new]

        new.AppendLine(Polar(r1, theta1*pi/180.))
        for i in range(ring2.len):
            segment = ring2.Segment(i)
            new.AppendSegment(*segment)

        new.AppendLine(Polar(r2, theta2*pi/180.))
        new.AppendLine(Polar(r1, theta2*pi/180.))

        ring1.Transform(Scale(-1,1))
        ring1.Transform(Rotation((180+theta1+theta2)*pi/180.))
        
        for i in range(ring1.len):
            s = ring1.Segment(i)
            new.AppendSegment(*s)

        for path in newpaths:
            path.Transform(self.trafo)
        if self.objects:
            self.objects[0].SetPaths(newpaths)
        else:
            obj = Sketch.PolyBezier(tuple(newpaths))
            self.set_objects([obj])
Ejemplo n.º 20
0
    def recompute(self):
        path = Sketch.CreatePath()
        top = [path]

        h = self.h
        dh = 0.55197 * h
        d = l = width
        dd = 0.55197 * d / 2.
        c = d / 2.

        path.AppendLine((0, l))
        path.AppendBezier((0, l + dh), (c - dd, l + h), (c, l + h))
        path.AppendBezier((c + dd, h + l), (d, l + dh), (d, l))

        path.AppendBezier((d, l - dh), (c + dd, l - h), (c, l - h))
        path.AppendBezier((c - dd, l - h), (0, l - dh), (0, l))
        path.Transform(self.trafo)

        path = Sketch.CreatePath()
        hull = [path]

        path.AppendLine((d, l))
        path.AppendLine((d, 0))
        path.AppendBezier((d, -dh), (c + dd, -h), (c, -h))
        path.AppendBezier((c - dd, -h), (0, -dh), (0, 0))
        path.AppendLine((0, l))
        path.AppendBezier((0, l - dh), (c - dd, l - h), (c, l - h))
        path.AppendBezier((c + dd, l - h), (d, l - dh), (d, l))
        path.Transform(self.trafo)

        if self.objects:
            self.objects[0].SetPaths(hull)
            self.objects[1].SetPaths(top)
        else:
            obj_hull = Sketch.PolyBezier(tuple(hull))
            obj_hull.SetProperties(line_join=Sketch.const.JoinRound)
            obj_top = Sketch.PolyBezier(tuple(top))
            self.set_objects([obj_hull, obj_top])
Ejemplo n.º 21
0
    def recompute(self):
        l1, l2, d1, d2, d3 = self.l1, self.l2, self.d1, self.d2, self.d3
        
        new = Sketch.CreatePath()
        newpaths = [new]

        #draw the arrow head
        for p in ((0,-d1), (0, -d1-d2), (-l1,0), (0, d1+d2), (0, d1)):
            new.AppendLine(Point(p))

        # the rounded part
        k = 1.2
        new.AppendBezier(Point(l2,d1), Point(l2, d1-d3/k), Point(l2,d1-d3))
        new.AppendLine(Point(l2, -d1-d3))
        new.AppendBezier(Point(l2,-d1-d3/k), Point(l2,-d1), Point(0,-d1))
        

        for path in newpaths:
            path.Transform(self.trafo)
        if self.objects:
            self.objects[0].SetPaths(newpaths)
        else:
            obj = Sketch.PolyBezier(tuple(newpaths))
            self.set_objects([obj])         
Ejemplo n.º 22
0
    def recompute(self):
        p1 = Polar(self.l1, self.theta1 * pi / 180)
        p2 = Polar(self.l2, self.theta2 * pi / 180)

        new = Sketch.CreatePath()
        newpaths = [new]

        new.AppendLine(p1)
        new.AppendLine((0, 0))
        new.AppendLine(p2)

        new.Transform(self.trafo)
        alpha = p1.polar()[1]
        beta = p2.polar()[1]
        if self.objects:
            self.objects[0].SetPaths(newpaths)
            self.objects[1].SetAngles(alpha, beta)
            trafo = self.trafo(Scale(self.r, self.r))
            self.objects[1].set_transformation(trafo)
        else:
            lines = Sketch.PolyBezier(tuple(newpaths))
            circle = Sketch.Ellipse(start_angle=alpha, end_angle=beta)
            circle.Transform(Scale(self.r, self.r))
            self.set_objects([lines, circle])
Ejemplo n.º 23
0
def reload_image(context):
    image = context.document.CurrentObject()
    if image is not None and isinstance(image, external.ExternalGraphics):
        # Don't try this at home :) It pokes around in the internals of
        # Sketch!

        olddata = image.data
        filename = olddata.Filename()
        oldrect = image.bounding_rect

        # first, remove the old object from the cache.
        if olddata.stored_in_cache \
           and external.instance_cache.has_key(filename):
            del external.instance_cache[filename]
            olddata.stored_in_cache = 0

        # now we can load the data again the normal way because it's not
        # in the cache anymore.
        if image.is_Eps:
            data = eps.load_eps(filename)
        else:
            data = Sketch.load_image(filename)

        # replace the old data object with the new one. Normally we
        # would have to handle the undo info returned. Here we just
        # discard it so that the reload won't be in the history.
        image.SetData(data)

        # some house keeping tasks that are necessary because the sort
        # of thing we're doing here, i.e. modifying an object without
        # undo information etc., wasn't anticipated:
        
        # to make sure that the bboxes get recomputed etc, call the
        # _changed method. SetData should probably do that
        # automatically, but currently it doesn't
        image._changed()

        # make sure the object itself is properly redrawn
        context.document.AddClearRect(oldrect)
        context.document.AddClearRect(image.bounding_rect)
        
        # make sure the selection's idea of the bounding rect is updated
        # too and have the canvas update the handles
        context.document.selection.ResetRectangle()
        context.main_window.canvas.update_handles()
Ejemplo n.º 24
0
def PythonPrompt(prompt='>>>', prompt2='...'):
    # try to import readline in Python 1.5
    have_readline = 0
    try:
        import readline
        have_readline = 1
        Sketch.Issue(None, Sketch.const.INIT_READLINE)
    except ImportError:
        pass
    globals = {}
    # put all of Sketch.main and Sketch into the globals
    exec 'from Sketch.main import *' in globals
    exec 'from Sketch import *' in globals
    # put all sketch specific modules into the globals
    for module in get_sketch_modules():
        globals[module.__name__] = module
    add_sketch_objects(globals)
    if have_readline:
        from Sketch.Lib import skcompleter
        skcompleter.install(globals, locals)
    while 1:
        try:
            cmd = raw_input(prompt)
            #cmd = string.strip(cmd)
            if cmd:
                if cmd[-1] == ':':
                    # a compound statement
                    lines = []
                    while string.strip(cmd):
                        lines.append(cmd)
                        cmd = raw_input(prompt2)
                    cmd = string.join(lines + [''], '\n')
                    kind = 'exec'
                else:
                    kind = 'single'

                c = compile(cmd, '<string>', kind)
                exec c in globals, locals
        except EOFError:
            print '----- returning to Sketch'
            return
        except:
            import traceback
            traceback.print_tb(sys.exc_traceback)
            print 'Exception %s: %s' % (sys.exc_type, sys.exc_value)
Ejemplo n.º 25
0
def reload_image(context):
    image = context.document.CurrentObject()
    if image is not None and isinstance(image, external.ExternalGraphics):
        # Don't try this at home :) It pokes around in the internals of
        # Sketch!

        olddata = image.data
        filename = olddata.Filename()
        oldrect = image.bounding_rect

        # first, remove the old object from the cache.
        if olddata.stored_in_cache \
           and external.instance_cache.has_key(filename):
            del external.instance_cache[filename]
            olddata.stored_in_cache = 0

        # now we can load the data again the normal way because it's not
        # in the cache anymore.
        if image.is_Eps:
            data = eps.load_eps(filename)
        else:
            data = Sketch.load_image(filename)

        # replace the old data object with the new one. Normally we
        # would have to handle the undo info returned. Here we just
        # discard it so that the reload won't be in the history.
        image.SetData(data)

        # some house keeping tasks that are necessary because the sort
        # of thing we're doing here, i.e. modifying an object without
        # undo information etc., wasn't anticipated:

        # to make sure that the bboxes get recomputed etc, call the
        # _changed method. SetData should probably do that
        # automatically, but currently it doesn't
        image._changed()

        # make sure the object itself is properly redrawn
        context.document.AddClearRect(oldrect)
        context.document.AddClearRect(image.bounding_rect)

        # make sure the selection's idea of the bounding rect is updated
        # too and have the canvas update the handles
        context.document.selection.ResetRectangle()
        context.main_window.canvas.update_handles()
Ejemplo n.º 26
0
def jsonshape(string):
    # parse json string
    shapejson = json.loads(string)

    # init an empty sketch
    sketch = Sketch.Sketch(sketch_id=shapejson['id'], strokes=[])

    # for each stroke
    for stroke in shapejson['strokes']:
        # init an empty stroke
        st = Stroke.Stroke(stroke['id'])

        # for each point in a stroke
        for point in stroke['points']:
            # add the point to the stroke
            st.addPoint(
                Point.Point(point['pid'], float(point['time']),
                            float(point['x']), float(point['y'])))

        # add the stroke to the sketch
        sketch.addStrokes(st)

    return sketch
Ejemplo n.º 27
0
def main():
	import Sketch
	global doc
	global tbase_style

	Sketch.init_lib()

	draw_printable = 1
	draw_visible = 0
	embed_fonts = 0
	eps_for = util.get_real_username()
	eps_date = util.current_date()
	eps_title = None
	rotate = 0


	#doc = load.load_drawing('')
	# from mainwindow.py: self.SetDocument(Document(create_layer = 1))
	doc = Document(create_layer = 1)

	# get font info first
	Graphics.font.read_font_dirs()

	# indicate start of coord system first
	# coord system:: + goes upward / rightward
	# from RectangleCreator: trafo = Trafo(off.x, 0, 0, off.y, end.x, end.y)
	# actually, there 'end' seems to correspond to start (llc: lower left corner of rectangle) - and 'off' to the length extended in each direction (i.e. width, height - but can be negative) ; so instead of 'end' - calling it 'start'
	start_x = 5
	start_y = 5
	off_x = -10
	off_y = -10
	trec = Rectangle(trafo = Trafo(off_x, 0, 0, off_y, start_x, start_y))
	trec.update_rects()
	doc.Insert(trec)


	# from create_text.py
	textfld = SimpleText(Translation(50, 50), "xyzzy")
	textfld.SetProperties(fill_pattern = SolidPattern(StandardColors.green),
					   font = GetFont('Courier-Bold'),#('Times-Bold'),
					   font_size = 36)

	#copy textfld
	textfld2 = textfld.Duplicate()
	textfld2.SetProperties(fill_pattern = SolidPattern(StandardColors.blue)) # change color only

	# rotate textfld
	angleDeg = 45
	angleRad = pi*(angleDeg/180.0) # ensure float op - could use math.radians instead
	textfld.Transform(Rotation(angleRad)) # Rotation(angle, center)
	textfld.update_rects() # probably a good idea

	# change textfld's text with the current width (that we see)
	# get bounding box of text
	a = textfld.properties
	llx, lly, urx, ury = a.font.TextBoundingBox(textfld.text, a.font_size)
	# calculate width - its of UNTRANSFORMED text
	twidth = urx - llx
	# insert this width as text in textbox now:
	#~ textfld.text = str(twidth)
	#~ textfld.update_rects() # probably a good idea - again

	# get textfield as bezier
	textbez = textfld.AsBezier()
	#~ print textbez # returns Sketch.Graphics.group.Group; subclass of EditableCompound
	# the bounding rectangle - from Compound (type is Rect):
	textbez_bRect = textbez.bounding_rect
	# calc width now
	t2width = textbez_bRect.right - textbez_bRect.left
	# insert this width as text in textbox now:
	textfld.text = str(t2width)
	textfld.update_rects() # probably a good idea - again

	#~ doc.Insert(textfld)

	# create a line
	# using create_spiral.py technique below (see syntax note #(A1))
	tpath = CreatePath()

	# Note - apparently, the first appended point is "moveTo";
	# .. the ubsequent ones being "LineTo"
	tp = Point(textbez_bRect.left,textbez_bRect.bottom)
	tpath.AppendLine(tp) # moveto

	tp = Point(textbez_bRect.left,textbez_bRect.top)
	tpath.AppendLine(tp) # lineto
	tp = Point(textbez_bRect.right,textbez_bRect.top)
	tpath.AppendLine(tp) # lineto
	tp = Point(textbez_bRect.right,textbez_bRect.bottom)
	tpath.AppendLine(tp) # lineto

	tline = PolyBezier((tpath,))
	tline.AddStyle(tbase_style) # of Graphics.properties (also in compound, document) - seems to add a 'layer' if dynamic; else seems to 'replace' ?!

	#~ doc.Insert(tline)

	# group tline and textfld ...
	# footprints.py has Group(foot_prints = [])
	tgrp = Group([textfld, textfld2, tline])
	tgrp.update_rects()
	doc.Insert(tgrp)

	# add a box.. around textfld2
	# use radius1, radius2 !=  0 AND 1 (logarithmic) to get RoundedRectangle (best between 0.0 and 1.0)
	tfbr = textfld2.bounding_rect
	start_x = tfbr.left
	start_y = tfbr.bottom
	off_x = tfbr.right - tfbr.left
	off_y = tfbr.top - tfbr.bottom
	twid = abs(off_x - start_x)
	thei = abs(off_y - start_y)
	radfact = 1.2*twid/thei
	tradius = 0.05 # if we want to specify a single one, then the actual look will depend on the dimesions of the rectangle - so must 'smooth' it with radfact...
	trec = Rectangle(trafo = Trafo(off_x, 0, 0, off_y, start_x, start_y), radius1 = tradius, radius2 = tradius*radfact)
	trec.update_rects()
	doc.Insert(trec)

	# add another box - any where
	start_x = 100.0
	start_y = 100.0
	off_x = 50.0
	off_y = 50.0
	trec2 = Rectangle(trafo = Trafo(off_x, 0, 0, off_y, start_x, start_y))
	trec2.update_rects()
	doc.Insert(trec2)

	# try change props post insert - OK
	trec2.SetProperties(fill_pattern = SolidPattern(StandardColors.yellow), line_width = 2.0, line_pattern = SolidPattern(CreateRGBColor(0.5, 0.5, 0.7)))

	# try move the group as a whole (Translate - syntax: spread.py)
	# say, align the right edge of tline to left edge of trec2 (x direction)
	# NOTE: group does not define own .AsBezier(self);
	# but it has tgrp.bounding_rect (although python doesn't show it in dir(tgrp))
	# also there is Rectangle.bounding_rect
	# NOTE though - it seems bounding_rect is somehow padded, with (at least) 10 units in each direction! (also, bounding rect of line will include the arrow)
	xmove = (trec2.bounding_rect.left+10)-(tline.bounding_rect.right-10)
	#~ print xmove, trec2.bounding_rect.left, tline.bounding_rect.right
	tgrp.Translate(Point(xmove, 0))
	tgrp.update_rects()

	# add temporary line to indicate bounding boxes
	# and effect of padding (may cover the very first trec)
	tmpbr = trec2.bounding_rect
	doc.Insert(
		getQuickLine(
			(0,0),
			(trec2.bounding_rect.left+10, tline.bounding_rect.top-10)
		)
	)

	# end of draw  - generate output file
	filename = ''
	psfile = 'vectorout.ps'
	sk2ps(filename, psfile, printable= draw_printable, visible = draw_visible,
		  For = eps_for, CreationDate = eps_date, Title = eps_title,
		  rotate = rotate, embed_fonts = embed_fonts)
Ejemplo n.º 28
0
        elif opt == "--keep":
            Options.keep = 1
        elif opt == "--preload":
            Options.preload = 1
        elif opt == "--fit":
            Options.fit = 1
        elif opt in ("-h", "--help"):
            sys.stderr.write(__doc__)
            sys.exit(0)

    Options.files = args

parse_options()

import Sketch
Sketch.init_ui()

import Sketch.UI.skapp, Sketch.UI.view, Sketch.load

from Tkinter import BOTH


class ShowView(Sketch.UI.view.SketchView):

    def __init__(self, master=None, toplevel = None, double_buffer = 1,
                 show_page_outline = 0, **kw):
	apply(Sketch.UI.view.SketchView.__init__, (self, master), kw)
        self.double_buffer = double_buffer
        self.show_page_outline = show_page_outline

    def do_clear(self, region):
Ejemplo n.º 29
0
def extractFromXML(string):
    root = ET.fromstring(string)
    points = getPoints(root)
    strokes = getStrokes(points, root)
    sketch = Sketch.Sketch(root.get('id'), strokes)
    return sketch
Ejemplo n.º 30
0
    def init_tk(self, screen_name = None, geometry = None):
	Sketch.UI.skapp.TkApplication.init_tk(self, screen_name = screen_name,
                                              geometry = geometry)
        Sketch.init_modules_from_widget(self.root)
Ejemplo n.º 31
0
def process_args(args):
    # Read options from the command line. Return an instance object with the
    # instance variables:
    #	display		name of the X-display or None
    #	geometry	geometry of the main window or None
    #	args		rest of the arguments after the last option
    #
    # To behave more like other X-programs, sketch should accept the options
    # -display and -geometry with a single hyphen and no `='...

    # recognize a standard X geometry specification... (hack)
    if '-geometry' in args:
	try:
	    idx = args.index('-geometry')
	    geo = args[idx:idx + 2]
	    if len(geo) == 2:
		del args[idx:idx + 2]
		geo[0] = '-g'
		args[0:0] = geo
	except:
	    pass

    opts, args = getopt.getopt(args, 'd:g:hi',
			       ['display=', 'geometry=', 'help', 'run-script=',
                                'version', 'participant=','f1=','f2=','f3=','f4='])
    # the option -i is a hack to allow sketch to be used as a `python
    # interpreter' in the python shell in python-mode.el

    options = util.Empty(args = args,
			 display = None,
			 geometry = None, participant = None, f1 = None, f2 = None, f3 = None, f4 = None,#changed by shumon June , 2009
                         run_script = None)


    for optchar, value in opts:
        #print "opts=", opts, "optchar=", optchar,"value=",value
    	if optchar == '-d' or optchar == '--display':
    	    options.display = value
    	elif optchar == '-g' or optchar == '--geometry':
    	    options.geometry = value
        elif optchar == '--run-script':
                options.run_script = value
    	elif optchar == '-h' or optchar == '--help':
    	    print Sketch._(usage)
    	    sys.exit(0)
    	elif optchar == '--version':
    	    print Sketch._(version) % Sketch.SketchVersion
    	    sys.exit(0)
        elif optchar == '--participant':
            print "participant=", value
            options.participant = value
        elif optchar == '--f1':
            print "f1=",value
            options.f1 = value
        elif optchar == '--f2':
            print "f2=",value
            options.f2 = value
        elif optchar == '--f3':
            print "f3=",value
            options.f3 = value
        elif optchar == '--f4':
            print "f4=",value
            options.f4 = value

    return options