Changeset 1795

Show
Ignore:
Timestamp:
07/31/07 02:46:57 (1 year ago)
Author:
arj..@yirdis.nl
Message:

Fixed save/load for simple items.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/gaphor/diagram/simpleitem.py

    r1765 r1795  
    99from style import Style 
    1010 
    11 class Dummy(object): 
    12     def save(self, *args): 
    13         pass 
    14  
    15     def load(self, *args): 
    16         pass 
    17  
    18     def postload(self, *args): 
    19         pass 
    20          
    21  
    22 class Line(_Line, Dummy): 
     11class Line(_Line): 
    2312 
    2413    __style__ = { 
     
    3726    id = property(lambda self: self._id, doc='Id') 
    3827 
     28    def save (self, save_func): 
     29        save_func('matrix', tuple(self.matrix)) 
     30        for prop in ('orthogonal', 'horizontal'): 
     31            save_func(prop, getattr(self, prop)) 
     32        points = [ ] 
     33        for h in self.handles(): 
     34            points.append(tuple(map(float, h.pos))) 
     35        save_func('points', points) 
     36 
     37    def load (self, name, value): 
     38        if name == 'matrix': 
     39            self.matrix = eval(value) 
     40        elif name == 'points': 
     41            points = eval(value) 
     42            for x in xrange(len(points) - 2): 
     43                self.split_segment(0) 
     44            for i, p in enumerate(points): 
     45                self.handles()[i].pos = p 
     46        elif name == 'horizontal': 
     47            self.horizontal = eval(value) 
     48        elif name == 'orthogonal': 
     49            self._load_orthogonal = eval(value) 
     50 
     51    def postload(self): 
     52        if hasattr(self, '_load_orthogonal'): 
     53            self.orthogonal = self._load_orthogonal 
     54            del self._load_orthogonal 
     55 
    3956    def draw(self, context): 
    4057        cr = context.cairo 
     
    4562 
    4663 
    47 class Box(Element, Dummy): 
     64class Box(Element): 
    4865    """ 
    4966    A Box has 4 handles (for a start):: 
     
    6683    id = property(lambda self: self._id, doc='Id') 
    6784 
     85    def save(self, save_func): 
     86        save_func('matrix', tuple(self.matrix)) 
     87        save_func('width', self.width) 
     88        save_func('height', self.height) 
     89 
     90    def load(self, name, value): 
     91        if name == 'matrix': 
     92            self.matrix = eval(value) 
     93        elif name == 'width': 
     94            self.width = eval(value) 
     95        elif name == 'height': 
     96            self.height = eval(value) 
     97 
     98    def postload(self): 
     99        pass 
     100 
    68101    def draw(self, context): 
    69102        cr = context.cairo 
     
    78111 
    79112 
    80 class Ellipse(Element, Dummy): 
     113class Ellipse(Element): 
    81114    """ 
    82115    """ 
     
    94127 
    95128    id = property(lambda self: self._id, doc='Id') 
     129 
     130    def save(self, save_func): 
     131        save_func('matrix', tuple(self.matrix)) 
     132        save_func('width', self.width) 
     133        save_func('height', self.height) 
     134 
     135    def load(self, name, value): 
     136        if name == 'matrix': 
     137            self.matrix = eval(value) 
     138        elif name == 'width': 
     139            self.width = eval(value) 
     140        elif name == 'height': 
     141            self.height = eval(value) 
     142 
     143    def postload(self): 
     144        pass 
    96145 
    97146    def draw(self, context): 
     
    112161 
    113162 
    114 # vim:sw=4:et:ai, Dummy 
     163# vim:sw=4:et:ai