Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def movable_items(self):
"""Filter selection
Filter items of selection that cannot be moved (i.e. are not instances of `Item`) and return the rest.
"""
view = self.view
if self._move_name_v:
yield InMotion(self._item, view)
else:
selected_items = set(view.selected_items)
for item in selected_items:
if not isinstance(item, Item):
continue
yield InMotion(item, view)
item = super()._create_item(pos, **kw)
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
@InMotion.register(ElementPresentation)
class DropZoneInMotion(GuidedItemInMotion):
def move(self, pos):
"""
Move the item. x and y are in view coordinates.
"""
super().move(pos)
item = self.item
view = self.view
x, y = pos
current_parent = view.canvas.get_parent(item)
over_item = view.get_item_at_point((x, y), selected=False)
if not over_item:
view.dropzone_item = None
view.get_window().set_cursor(None)
def move(self, pos):
if not self.item.moving:
return
super(GuidedStateInMotion, self).move(pos)
parent_item = self.item.parent
if parent_item:
constraint = parent_item.keep_rect_constraints[self.item]
self.view.canvas.solver.request_resolve_constraint(constraint)
def stop_move(self):
super(GuidedStateInMotion, self).stop_move()
self.item.moving = False
@InMotion.when_type(NameView)
class GuidedNameInMotion(GuidedItemInMotion):
def move(self, pos):
super(GuidedNameInMotion, self).move(pos)
parent_item = self.item.parent
if parent_item:
constraint = parent_item.keep_rect_constraints[self.item]
self.view.canvas.solver.request_resolve_constraint(constraint)
@HandleInMotion.when_type(StateView)
class GuidedStateHandleInMotion(GuidedStateMixin, GuidedItemHandleInMotion):
def glue(self, pos, distance=None):
distance = distance if distance else self.GLUE_DISTANCE
super(GuidedStateHandleInMotion, self).glue(pos, distance)
def movable_items(self):
"""Filter selection
Filter items of selection that cannot be moved (i.e. are not instances of `Item`) and return the rest.
"""
view = self.view
if self._move_name_v:
yield InMotion(self._item, view)
else:
selected_items = set(view.selected_items)
for item in selected_items:
if not isinstance(item, Item):
continue
yield InMotion(item, view)
def movable_items(self):
"""Filter selection
Filter items of selection that cannot be moved (i.e. are not instances of `Item`) and return the rest.
"""
view = self.view
if self._move_name_v:
yield InMotion(self._item, view)
else:
selected_items = set(view.selected_items)
for item in selected_items:
if not isinstance(item, Item):
continue
yield InMotion(item, view)
item = super(GroupPlacementTool, self)._create_item(pos, **kw)
adapter = component.queryMultiAdapter((parent, item), IGroup)
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
@InMotion.when_type(ElementItem)
class DropZoneInMotion(GuidedItemInMotion):
def move(self, pos):
"""
Move the item. x and y are in view coordinates.
"""
super(DropZoneInMotion, self).move(pos)
item = self.item
view = self.view
x, y = pos
current_parent = view.canvas.get_parent(item)
over_item = view.get_item_at_point((x, y), selected=False)
if not over_item:
item = super(GroupPlacementTool, self)._create_item(pos, **kw)
adapter = component.queryMultiAdapter((parent, item), IGroup)
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
@InMotion.when_type(ElementItem)
class DropZoneInMotion(GuidedItemInMotion):
def move(self, pos):
"""
Move the item. x and y are in view coordinates.
"""
super(DropZoneInMotion, self).move(pos)
item = self.item
view = self.view
x, y = pos
current_parent = view.canvas.get_parent(item)
over_item = view.get_item_at_point((x, y), selected=False)
if not over_item:
def on_drag_data_received(self, widget, context, x, y, data, info, time):
"""Receives state_id from LibraryTree and moves the state to the position of the mouse
:param widget:
:param context:
:param x: Integer: x-position of mouse
:param y: Integer: y-position of mouse
:param data: SelectionData: contains state_id
:param info:
:param time:
"""
item = self.canvas.get_view_for_model(self.model.selection.get_selected_state().states[data.get_text()])
pos_start = item.model.meta['gui']['editor_gaphas']['rel_pos']
motion = InMotion(item, self.view.editor)
motion.start_move(self.view.editor.get_matrix_i2v(item).transform_point(pos_start[0], pos_start[1]))
motion.move((x,y))
:param widget:
:param context:
:param x: Integer: x-position of mouse
:param y: Integer: y-position of mouse
:param data: SelectionData: contains state_id
:param info:
:param time:
"""
state_id_insert = data.get_text()
parent_m = self.model.selection.get_selected_state()
if not isinstance(parent_m, ContainerStateModel):
return
state_v = self.canvas.get_view_for_model(parent_m.states[state_id_insert])
pos_start = state_v.model.get_meta_data_editor()['rel_pos']
motion = InMotion(state_v, self.view.editor)
motion.start_move(self.view.editor.get_matrix_i2v(state_v).transform_point(pos_start[0], pos_start[1]))
motion.move((x, y))
motion.stop_move()
state_v.model.set_meta_data_editor('rel_pos', motion.item.position)
self.canvas.wait_for_update(trigger_update=True)
self._meta_data_changed(None, state_v.model, 'append_to_last_change', True)
def movable_items(self):
"""Filter selection
Filter items of selection that cannot be moved (i.e. are not instances of `Item`) and return the rest.
"""
view = self.view
if self._move_name_v:
yield InMotion(self._item, view)
else:
selected_items = set(view.selected_items)
for item in selected_items:
if not isinstance(item, Item):
continue
yield InMotion(item, view)