My favorites | Sign in
Project Home Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2009 Scott Kirkwood. All Rights Reserved.

"""Create a seven segment display from a template.

The template needs to be in a certain format:
You should have the segments as paths named with the following IDs

tc
tl tr
cc
bl br
bc

The program will delete (remove) the appropriate segments in order to
make a number (0-9).
"""

__author__ = 'scott@forusers.com (Scott Kirkwood)'

# These two lines are only needed if you don't put the script directly into
# the installation directory
import sys
sys.path.append('/usr/share/inkscape/extensions')

import inkex
import logging

addNS = inkex.addNS

SEGMENTS_TO_DELETE = {
0: ['cc'],
1: ['tc', 'tl', 'cc', 'bl', 'bc'],
2: ['tl', 'br'],
3: ['tl', 'bl'],
4: ['tc', 'bl', 'bc'],
5: ['tr', 'bl'],
6: ['tr'],
7: ['tl', 'cc', 'bl', 'bc'],
8: [],
9: ['bl'],
}

class SevenSegment(inkex.Effect):
"""
Example Inkscape effect extension.
"""
def __init__(self):
"""
Constructor.
"""
# Call the base class constructor.
inkex.Effect.__init__(self)

self.OptionParser.add_option('-n', '--number', action='store',
type='int', dest='number', default=0,
help='Number to create.')

def effect(self):
"""
Effect behaviour.
Create multiple keys.
"""
# Get access to main SVG document element and get its dimensions.
svg = self.document.getroot()

width = inkex.unittouu(svg.get('width'))
height = inkex.unittouu(svg.get('height'))

num = self.options.number
if num not in SEGMENTS_TO_DELETE:
logging.error('Number must be between 0 and 9')
return

self.DeleteSegments(svg, SEGMENTS_TO_DELETE[num])

def DeleteSegments(self, root, segments):
lookup = dict((x, True) for x in segments)
lookup.update(dict((x + '1', True) for x in segments))
lookup.update(dict((x + '2', True) for x in segments))
lookup.update(dict((x + '3', True) for x in segments))
for g in root.iter(addNS('g', 'svg')):
for path in g.iterchildren(addNS('path', 'svg')):
if path.get('id') in lookup:
g.remove(path)



# Create effect instance and apply it.
effect = SevenSegment()
effect.affect()

Change log

564e7d49dd66 by Scott Kirkwood <scottakirkwood> on Dec 28, 2009   Diff
Untested changes.
Now the green has two paths for the glow.
Made the default black have a much less
apparent shadow.
Go to: 
Project members, sign in to write a code review

Older revisions

e8f1c25d703e by Scott Kirkwood <sc...@forusers.com> on Dec 27, 2009   Diff
Added seven segment inkscape plugin.
All revisions of this file

File info

Size: 2243 bytes, 93 lines
Powered by Google Project Hosting