~ubuntu-branches/ubuntu/oneiric/yapgvb/oneiric

« back to all changes in this revision

Viewing changes to graph_attribute_types.py

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-05-20 23:32:19 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090520233219-1yfc1s3r86grd388
Tags: 1.1.3-0ubuntu1
* New upstream release.
* debian/rules:
  - Include /usr/share/python/python.mk in order to be able to use
    py_sitename and py_setup_install_args macros to install all python
    modules into the correct installation path.
* debian/control:
  - Set XS-Python-Version to all.
  - Bump Standards-Version.
* debian/copyright: Replace deprecated (C) with © symbol.
* Fix LP: #337317.

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
    while True: 
142
142
        yield [itz.next() for j in xrange(groupsize)]
143
143
 
 
144
class EdgePosition(list):
 
145
    """ Just like a normal list, except with "end" and "start" attributes which may be set to end and start points of the splin.
 
146
        end and start may also be None"""
 
147
    end = None
 
148
    start = None
 
149
    def __init__(self, *args, **keywords):
 
150
        list.__init__(self, *args, **keywords)
 
151
        
144
152
class splineType(AttributeType):
145
153
    # currently handles only splines of form:
146
154
    #   e,x1,y1 x2,y2 x3,y3 ... xN,yN
148
156
        AttributeType.__init__(self, self.to_python, self.from_python, 'object')
149
157
 
150
158
    def to_python(self, s):
151
 
        if not s.startswith('e,'):
152
 
            raise Exception("Help! Don't understand splineType \"%s\"!")
153
 
        points = s[2:].split(' ')
154
 
        points = [x.split(',') for x in points]
155
 
        points = [(int(a),int(b)) for a,b in points]
 
159
        words = s.split(' ')
 
160
        if words[0].startswith('e'):
 
161
            a,b = words[0].split(',')[1:]
 
162
            endpoint = (int(a),int(b)) 
 
163
            words.pop(0)
 
164
        else:
 
165
            endpoint = None
 
166
        if words[0].startswith('s'):
 
167
            a,b = words[0].split(',')[1:]
 
168
            startpoint = (int(a),int(b)) 
 
169
            words.pop(0)
 
170
        else:
 
171
            startpoint = None
 
172
        points = EdgePosition([ map(int,x.split(',')) for x in words ])
 
173
        points.start = startpoint
 
174
        points.end = endpoint
156
175
        return points
 
176
 
157
177
    def from_python(self, pointslist):
158
178
        return 'e,' + ' '.join(['%s,%s'%(x,y) for x,y in pointslist])
159
179