def create_as(self, type, id, parent=None, subject=None): item = type(id, self.model) if subject: item.subject = subject self.canvas.add(item, parent) self.model.handle(DiagramItemCreated(self.model, item)) return item
def create_as(self, type, id, parent=None, subject=None): if not type or not issubclass(type, gaphas.Item): raise TypeError( f"Type {type} can not be added to a diagram as it is not a diagram item" ) item = type(id, self.model) if subject: item.subject = subject self.canvas.add(item, parent) self.model.handle(DiagramItemCreated(self.model, item)) return item
def create_as(self, type, id, parent=None, subject=None): if not (type and issubclass(type, Presentation)): raise TypeError( f"Type {type} can not be added to a diagram as it is not a diagram item" ) item = type(connections=self._connections, id=id, model=self.model) assert isinstance( item, gaphas.Item), f"Type {type} does not comply with Item protocol" item.diagram = self if subject: item.subject = subject if parent: item.parent = parent self.model.handle(DiagramItemCreated(self, item)) self.request_update(item) return item
def create_as(self, type, id, parent=None, subject=None): if not (type and issubclass(type, Presentation)): raise TypeError( f"Type {type} can not be added to a diagram as it is not a diagram item" ) # Avoid events that reference this element before its created-event is emitted. with self.model.block_events(): item = type(diagram=self, id=id) assert isinstance( item, gaphas.Item ), f"Type {type} does not comply with Item protocol" self.model.handle(DiagramItemCreated(self, item)) if subject: item.subject = subject if parent: item.parent = parent self.request_update(item) return item