File: inspect_beziers.py

package info (click to toggle)
skencil 0.6.17-7
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 6,136 kB
  • ctags: 8,589
  • sloc: python: 36,672; ansic: 16,571; sh: 151; makefile: 92
file content (79 lines) | stat: -rw-r--r-- 3,257 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#
#  inspect_beziers - examine bezier polygons
#                    Tamito KAJIYAMA <26 March 2000>
# Copyright (C) 2000 by Tamito KAJIYAMA
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

from Sketch import Bezier, Line, ContAngle, ContSmooth, ContSymmetrical

from Tkinter import *

class Viewer(Toplevel):
    type_names = {Line: "Line", Bezier: "Bezier"}
    cont_names = {ContAngle: "ContAngle",
                  ContSmooth: "ContSmooth",
                  ContSymmetrical: "ContSymmetrical"}
    def __init__(self, context):
        Toplevel.__init__(self, context.application.root)
        self.title("Inspect Beziers")
        self.document = context.document
        frame = Frame(self)
        frame.pack(side=BOTTOM, fill=X)
	button = Button(frame, text="Update", command=self.update)
	button.pack(side=LEFT)
	button = Button(frame, text="Dismiss", command=self.destroy)
	button.pack(side=RIGHT)
        sb = Scrollbar(self)
        sb.pack(side=RIGHT, fill=Y)
        self.text = Text(self, width=85, height=25, yscrollcommand=sb.set)
        self.text.pack(side=LEFT, fill=BOTH, expand=1)
        sb.config(command=self.text.yview)
        self.update()
    def update(self):
        self.text.delete("1.0", END)
        n = 0
        for obj in self.document.SelectedObjects():
            if not obj.is_Bezier:
                continue
            self.text.insert(END, "Bezier #%d\n" % (n + 1))
            paths = obj.Paths()
            for i in range(len(paths)):
                self.text.insert(END, "  path #%d\n" % (i + 1))
                for j in range(paths[i].len):
                    s = apply(self.format_segment, paths[i].Segment(j))
                    self.text.insert(END, "    #%d %s\n" % ((j + 1), s))
            self.text.insert(END, "\n")
            n = n + 1
        if n == 0:
            self.text.insert(END, "No bezier polygons selected.")
    def format_segment(self, type, controls, point, cont):
        if type == Line:
            controls = ""
        elif controls:
            controls = " ((%.2f, %.2f), (%.2f, %.2f))" % \
                       (controls[0].x, controls[0].y,
                        controls[1].x, controls[1].y)
        else:
            controls = " ()"
        point = " (%.2f, %.2f) " % (point.x, point.y)
        type = self.type_names[type]
        cont = self.cont_names[cont]
        return type + controls + point + cont

import Sketch.Scripting
Sketch.Scripting.AddFunction('inspect_beziers', 'Inspect Beziers', Viewer,
                             script_type=Sketch.Scripting.AdvancedScript)