def group(self, parent, item): """ Group item within a parent. """ self.diagram.canvas.reparent(item, parent) adapter = Group(parent, item) adapter.group()
def stop_move(self): """Motion stops: drop!""" super().stop_move() item = self.item view = self.view canvas = view.canvas old_parent = view.canvas.get_parent(item) new_parent = view.dropzone_item try: if new_parent is old_parent: if old_parent is not None: old_parent.request_update(matrix=False) return if old_parent: canvas.reparent(item, None) adapter = Group(old_parent, item) if adapter: adapter.ungroup() old_parent.request_update() if new_parent: canvas.reparent(item, new_parent) adapter = Group(new_parent, item) if adapter and adapter.can_contain(): adapter.group() new_parent.request_update() finally: view.dropzone_item = None
def stop_move(self, pos): """Motion stops: drop!""" super().stop_move(pos) item = self.item view = self.view old_parent = item.parent new_parent = view.selection.dropzone_item try: if new_parent is old_parent: if old_parent is not None: old_parent.request_update(matrix=False) return if old_parent: item.parent = None adapter = Group(old_parent, item) if adapter: adapter.ungroup() old_parent.request_update() if new_parent: item.parent = new_parent adapter = Group(new_parent, item) if adapter and adapter.can_contain(): adapter.group() new_parent.request_update() finally: view.selection.dropzone_item = None
def item_factory(diagram, parent=None): if subject_class: element_factory = diagram.model subject = element_factory.create(subject_class) else: subject = None item = diagram.create(item_class, subject=subject) if config_func: config_func(item) adapter = Group(parent, item) if parent and adapter.can_contain(): adapter.group() diagram.canvas.reparent(item, parent=parent) return item
def stop_move(self): """ Motion stops: drop! """ super(DropZoneInMotion, self).stop_move() item = self.item view = self.view canvas = view.canvas old_parent = view.canvas.get_parent(item) new_parent = view.dropzone_item try: if new_parent is old_parent: if old_parent is not None: old_parent.request_update(matrix=False) return if old_parent: adapter = Group(old_parent, item) if adapter: adapter.ungroup() canvas.reparent(item, None) m = canvas.get_matrix_i2c(old_parent) item.matrix *= m old_parent.request_update() if new_parent: adapter = Group(new_parent, item) if adapter and adapter.can_contain(): adapter.group() canvas.reparent(item, new_parent) m = canvas.get_matrix_c2i(new_parent) item.matrix *= m new_parent.request_update() finally: view.dropzone_item = None view.get_window().set_cursor(None)
def _create_item(self, pos): """ Create diagram item and place it within parent's boundaries. """ parent = self._parent view = self.view try: adapter = Group(parent, self._factory.item_class()) if parent and adapter and adapter.can_contain(): item = super()._create_item(pos, parent=parent) else: item = super()._create_item(pos) adapter = Group(parent, item) if parent and item and adapter: adapter.group() parent.request_update(matrix=False) finally: self._parent = None view.dropzone_item = None view.get_window().set_cursor(None) return item
def _create_item(self, pos, **kw): """ Create diagram item and place it within parent's boundaries. """ parent = self._parent view = self.view try: adapter = Group(parent, self._factory.item_class()) if parent and adapter and adapter.can_contain(): kw["parent"] = parent item = super(GroupPlacementTool, self)._create_item(pos, **kw) adapter = Group(parent, item) if parent and item and adapter: adapter.group() canvas = view.canvas parent.request_update(matrix=False) finally: self._parent = None view.dropzone_item = None view.window.set_cursor(None) return item
def group(self, parent, item): """Group item within a parent.""" item.parent = parent adapter = Group(parent, item) adapter.group()