def __init__(self, id=None): gaphas.Element.__init__(self) DiagramItem.__init__(self, id) self.min_width = self.style.min_size[0] self.min_height = self.style.min_size[1] self.auto_resize = 0
def save(self, save_func): DiagramItem.save(self, save_func) save_func('matrix', tuple(self.matrix)) for prop in ('orthogonal', 'horizontal'): save_func(prop, getattr(self, prop)) points = [] for h in self.handles(): points.append(tuple(map(float, h.pos))) save_func('points', points) canvas = self.canvas c = canvas.get_connection(self.head) if c: save_func('head-connection', c.connected, reference=True) c = canvas.get_connection(self.tail) if c: save_func('tail-connection', c.connected, reference=True)
def load(self, name, value): if name == 'matrix': self.matrix = eval(value) elif name == 'points': points = eval(value) for x in xrange(len(points) - 2): h = self._create_handle((0, 0)) self._handles.insert(1, h) for i, p in enumerate(points): self.handles()[i].pos = p # Update connection ports of the line. Only handles are saved # in Gaphor file therefore ports need to be recreated after # handles information is loaded. self._update_ports() elif name == 'orthogonal': self._load_orthogonal = eval(value) elif name in ('head_connection', 'head-connection'): self._load_head_connection = value elif name in ('tail_connection', 'tail-connection'): self._load_tail_connection = value else: DiagramItem.load(self, name, value)
def postload(self): if hasattr(self, '_load_orthogonal'): # Ensure there are enough handles if self._load_orthogonal and len(self._handles) < 3: p0 = self._handles[-1].pos self._handles.insert(1, self._create_handle(p0)) self.orthogonal = self._load_orthogonal del self._load_orthogonal # First update matrix and solve constraints (NE and SW handle are # lazy and are resolved by the constraint solver rather than set # directly. self.canvas.update_matrix(self) self.canvas.solver.solve() if hasattr(self, '_load_head_connection'): self._postload_connect(self.head, self._load_head_connection) del self._load_head_connection if hasattr(self, '_load_tail_connection'): self._postload_connect(self.tail, self._load_tail_connection) del self._load_tail_connection DiagramItem.postload(self)
def post_update(self, context): gaphas.Element.post_update(self, context) DiagramItem.post_update(self, context)
def point(self, pos): d1 = gaphas.Element.point(self, pos) d2 = DiagramItem.point(self, pos) return min(d1, d2)
def pre_update(self, context): #super(ElementItem, self).pre_update(context) self.update_stereotype() DiagramItem.pre_update(self, context) gaphas.Element.pre_update(self, context)
def load(self, name, value): if name == 'matrix': self.matrix = eval(value) else: DiagramItem.load(self, name, value)
def save(self, save_func): save_func('matrix', tuple(self.matrix)) for prop in ('width', 'height'): self.save_property(save_func, prop) DiagramItem.save(self, save_func)
def draw(self, context): self.fill_background(context) self.highlight(context) gaphas.Element.draw(self, context) DiagramItem.draw(self, context)
def draw(self, context): gaphas.Line.draw(self, context) DiagramItem.draw(self, context)
def post_update(self, context): gaphas.Line.post_update(self, context) DiagramItem.post_update(self, context)
def pre_update(self, context): # first, update stereotype to know its text self.update_stereotype() gaphas.Line.pre_update(self, context) DiagramItem.pre_update(self, context)
def __init__(self, id = None): gaphas.Line.__init__(self) DiagramItem.__init__(self, id) self.fuzziness = 2