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 __init__(self, id=None): Item.__init__(self) DiagramItem.__init__(self, id) h1, h2 = Handle(), Handle() self._handles.append(h1) self._handles.append(h2) self._ports.append(LinePort(h1.pos, h2.pos)) self._combined = None self._join_spec = self.add_text('joinSpec', pattern='{ joinSpec = %s }', style=self.STYLE_TOP, visible=self.is_join_spec_visible) self._name = self.add_text('name', style={ 'text-align': self.style.name_align, 'text-padding': self.style.name_padding, 'text-outside': self.style.name_outside, 'text-align-str': self.style.name_align_str, 'text-align-group': 'stereotype', }, editable=True) self.watch('subject<NamedElement>.name', self.on_named_element_name)\ .watch('subject<JoinNode>.joinSpec', self.on_join_node_join_spec)
def __init__(self, id=None, model=None): Item.__init__(self) DiagramItem.__init__(self, id, model) h1, h2 = Handle(), Handle() self._handles.append(h1) self._handles.append(h2) self._ports.append(LinePort(h1.pos, h2.pos)) self._combined = None self._join_spec = self.add_text( "joinSpec", pattern="{ joinSpec = %s }", style=self.STYLE_TOP, visible=self.is_join_spec_visible, ) self._name = self.add_text( "name", style={ "text-align": self.style.name_align, "text-padding": self.style.name_padding, "text-outside": self.style.name_outside, "text-align-str": self.style.name_align_str, "text-align-group": "stereotype", }, editable=True, ) self.watch("subject<NamedElement>.name", self.on_named_element_name).watch( "subject<JoinNode>.joinSpec", self.on_join_node_join_spec)
def __init__(self, id=None): Item.__init__(self) DiagramItem.__init__(self, id) h1, h2 = Handle(), Handle() self._handles.append(h1) self._handles.append(h2) self._ports.append(LinePort(h1.pos, h2.pos)) self._combined = None self._join_spec = self.add_text( "joinSpec.value", pattern="{ joinSpec = %s }", style=self.STYLE_TOP, visible=self.is_join_spec_visible ) self._name = self.add_text( "name", style={ "text-align": self.style.name_align, "text-padding": self.style.name_padding, "text-outside": self.style.name_outside, "text-align-str": self.style.name_align_str, "text-align-group": "stereotype", }, editable=True, ) self.watch("subject<NamedElement>.name", self.on_named_element_name).watch( "subject<JoinNode>.joinSpec<LiteralSpecification>.value", self.on_join_node_join_spec )
def draw(self, context): """ Draw vertical line - symbol of fork and join nodes. Join specification is also drawn above the item. """ Item.draw(self, context) DiagramItem.draw(self, context) cr = context.cairo cr.set_line_width(6) h1, h2 = self._handles cr.move_to(h1.pos.x, h1.pos.y) cr.line_to(h2.pos.x, h2.pos.y) cr.stroke()
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 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 load(self, name, value): if name == "matrix": self.matrix = eval(value) elif name == "points": points = eval(value) for x in range(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 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 draw(self, context): self.fill_background(context) self.highlight(context) gaphas.Element.draw(self, context) DiagramItem.draw(self, context)
def point(self, pos): d1 = gaphas.Element.point(self, pos) d2 = DiagramItem.point(self, pos) return min(d1, d2)
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)) save_func("height", float(self._handles[1].pos.y)) if self._combined: save_func("combined", self._combined, reference=True) DiagramItem.save(self, save_func)
def save(self, save_func): save_func('matrix', tuple(self.matrix)) save_func('height', float(self._handles[1].pos.y)) if self._combined: save_func('combined', self._combined, reference=True) DiagramItem.save(self, save_func)
def pre_update(self, context): self.update_stereotype() Item.pre_update(self, context) DiagramItem.pre_update(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
def post_update(self, context): Item.post_update(self, context) DiagramItem.post_update(self, context)
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 post_update(self, context): gaphas.Element.post_update(self, context) DiagramItem.post_update(self, context)
def save(self, save_func): DiagramItem.save(self, save_func)
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 point(self, pos): d1 = gaphas.Line.point(self, pos) d2 = DiagramItem.point(self, pos) return min(d1, d2)
def load(self, name, value): if name == "matrix": self.matrix = eval(value) else: DiagramItem.load(self, name, value)