def OnDrag(self, event: MouseEvent): """ Callback to drag the selected shapes. Args: event: """ x, y = event.GetX(), event.GetY() if not self._moving: self.PrepareBackground() self._moving = True clicked = self._clickedShape if clicked and not clicked.IsSelected(): self._selectedShapes.append(clicked) clicked.SetSelected(True) clicked.SetMoving(True) self._clickedShape = cast(Shape, None) for shape in self._selectedShapes: parent = shape.GetParent() if parent is not None and parent.IsSelected() and not isinstance( shape, SizerShape): continue ox, oy = self._lastMousePosition dx, dy = x - ox, y - oy sx, sy = shape.GetPosition() shape.SetPosition(sx + dx, sy + dy) self.Refresh(False) self._lastMousePosition = (x, y)
def OnRightDown(self, event: MouseEvent): """ Handle right-clicks on our UML LineShape- Override base handler; It does nothing Args: event: """ menu: Menu = Menu() menu.Append(MENU_ADD_BEND, _('Add Bend'), _('Add Bend at right click point')) menu.Append(MENU_REMOVE_BEND, _('Remove Bend'), _('Remove Bend closest to click point')) menu.Append(MENU_TOGGLE_SPLINE, _('Toggle Spline'), _('Best with at least one bend')) if len(self._controls) == 0: bendItem: MenuItem = menu.FindItemById(MENU_REMOVE_BEND) bendItem.Enable(enable=False) x: int = event.GetX() y: int = event.GetY() clickPoint: Tuple[int, int] = (x, y) OglLink.clsLogger.debug(f'OglLink - {clickPoint=}') # I hate lambdas -- humberto menu.Bind(EVT_MENU, lambda evt, data=clickPoint: self._onMenuItemSelected(evt, data)) frame = self._diagram.GetPanel() frame.PopupMenu(menu, x, y)
def OnCanvasDClick(self, event: wx.MouseEvent): if self.gl_canvas.selection_mode: event.Skip() return size = self.gl_canvas.GetSize() mouse_x = event.GetX() / size.x * 2 - 1 mouse_y = -event.GetY() / size.y * 2 + 1 intersects = self.gl_canvas.camera.raycaster.intersect_objects( (mouse_x, mouse_y), self.camera) if intersects: intersection = intersects[0] plugin = intersection.object.plugin if plugin is not None: result = plugin.get_identify_detail(intersection.point) if self.inspect_window is None: self.inspect_window = InspectWindow(self, wx.ID_ANY) self.inspect_window.data = result self.inspect_window.Show() zonal_result = plugin.get_zonal_stats_from_point( intersection.point) if zonal_result: if self.zonalstats_window is None: self.zonalstats_window = ZonalStatisticsWindow( self, wx.ID_ANY) self.zonalstats_window.data = zonal_result self.zonalstats_window.plugin = plugin self.zonalstats_window.Show()
def OnRightDown(self, event: MouseEvent): """ Callback for right clicks """ pyutObject: PyutClass = cast(PyutClass, self.pyutObject) menu: Menu = Menu() menu.Append(MENU_TOGGLE_STEREOTYPE, _("Toggle stereotype display"), _("Set stereotype display on or off"), True) item = menu.FindItemById(MENU_TOGGLE_STEREOTYPE) item.Check(pyutObject.getShowStereotype()) menu.Append(MENU_TOGGLE_FIELDS, _("Toggle fields display"), _("Set fields display on or off"), True) item = menu.FindItemById(MENU_TOGGLE_FIELDS) item.Check(pyutObject.showFields) menu.Append(MENU_TOGGLE_METHODS, _("Toggle methods display"), _("Set methods display on or off "), True) item = menu.FindItemById(MENU_TOGGLE_METHODS) item.Check(pyutObject.showMethods) menu.Append(MENU_TOGGLE_METHOD_PARAMETERS, _("Toggle parameter display"), _("Set parameter display on or off"), True) itemToggleParameters: MenuItem = menu.FindItemById( MENU_TOGGLE_METHOD_PARAMETERS) displayParameters: PyutDisplayParameters = self.pyutObject.displayParameters self._initializeTriStateDisplayParametersMenuItem( displayParameters, itemToggleParameters) menu.Append(MENU_FIT_FIELDS, _("Fit Fields"), _("Fit to see all class fields")) menu.Append(MENU_CUT_SHAPE, _("Cut shape"), _("Cut this shape")) menu.Append(MENU_IMPLEMENT_INTERFACE, _('Implement Interface'), _('Use Existing interface or create new one')) frame = self._diagram.GetPanel() # Callback menu.Bind(EVT_MENU, self.OnMenuClick, id=MENU_TOGGLE_STEREOTYPE) menu.Bind(EVT_MENU, self.OnMenuClick, id=MENU_TOGGLE_FIELDS) menu.Bind(EVT_MENU, self.OnMenuClick, id=MENU_TOGGLE_METHODS) menu.Bind(EVT_MENU, self.OnMenuClick, id=MENU_FIT_FIELDS) menu.Bind(EVT_MENU, self.OnMenuClick, id=MENU_CUT_SHAPE) menu.Bind(EVT_MENU, self.OnMenuClick, id=MENU_IMPLEMENT_INTERFACE) menu.Bind(EVT_MENU, self.onDisplayParametersClick, id=MENU_TOGGLE_METHOD_PARAMETERS) x: int = event.GetX() y: int = event.GetY() self.logger.debug(f'OglClass - x,y: {x},{y}') frame.PopupMenu(menu, x, y)
def OnMouseMove(self, event: wx.MouseEvent): if self._dragging and event.LeftIsDown(): value = event.GetX() / self._px_per_value + self.min_value if self.active_handle == self.MIN_HANDLE: self.min_stop = max(self.min_value, min(value, self.max_stop)) else: self.max_stop = min(self.max_value, max(value, self.min_stop)) wx.PostEvent(self, HistogramCtrlValueChangedEvent(min_stop=self.min_stop, max_stop=self.max_stop)) self.Refresh()
def OnLeftDClick(self, event: MouseEvent): """ Manage a left double click mouse event. Args: event: """ x, y = self.CalcUnscrolledPosition(event.GetX(), event.GetY()) self._ctrl.editObject(x, y) DiagramFrame.OnLeftDClick(self, event)
def OnLeftDown(self, event: wx.MouseEvent): if self.selection_mode and self.selection_mode is GLSelectionControls.POLY: # Catch when the user clicked on the overlay while in POLY mode if self.overlay.target: event.Skip() return self.camera.poly_select.append_point(event.GetX(), event.GetY()) self.Refresh() event.Skip()
def OnLeftDClick(self, event: MouseEvent): """ Manage a left double click mouse event. @param event @since 1.22 @author L. Burgbacher <*****@*****.**> """ x, y = self.CalcUnscrolledPosition(event.GetX(), event.GetY()) self._ctrl.editObject(x, y) DiagramFrame.OnLeftDClick(self, event)
def OnLeftDown(self, event: wx.MouseEvent): dc = wx.MemoryDC() x = event.GetX() y = event.GetY() if y > self.GetSize().y - self.HANDLE_HEIGHT - self.LABEL_PADDING - dc.GetTextExtent("0").GetHeight(): min_pos = (self.min_stop - self.min_value) * self._px_per_value max_pos = (self.max_stop - self.min_value) * self._px_per_value if abs(x - min_pos) < abs(x - max_pos): self.active_handle = self.MIN_HANDLE else: self.active_handle = self.MAX_HANDLE self._dragging = True self.CaptureMouse()
def OnRightDown(self, event: MouseEvent): """ Callback for right clicks """ if self._menu is None: self._menu = self._createMenu() frame = self._diagram.GetPanel() x: int = event.GetX() y: int = event.GetY() self.logger.debug(f'OglClass - x,y: {x},{y}') frame.PopupMenu(self._menu, x, y)
def OnLeftDown(self, event: MouseEvent): """ Callback for left down events on the diagram. Args: event: """ self.clsLogger.debug("DiagramFrame.OnLeftDown") # First, call the generic handler for OnLeftDown shape: ShapeEventHandler = self.GenericHandler(event, "OnLeftDown") self._clickedShape = cast(Shape, shape) # store the last clicked shape if not event.GetSkipped(): return if shape is None: self._BeginSelect(event) return # manage click and drag x, y = event.GetX(), event.GetY() self._lastMousePosition = (x, y) realShape: Shape = cast(Shape, shape) if not event.ControlDown() and not realShape.IsSelected(): shapes = self._diagram.GetShapes() shapes.remove(shape) if isinstance(shape, SizerShape): # don't deselect the parent of a sizer # or its sizer's would be detached shapes.remove(shape.GetParent()) elif isinstance(shape, ControlPoint): # don't deselect the line of a control point self.clsLogger.debug(f'{shape=}') for line in shape.GetLines(): shapes.remove(line) # do not call DeselectAllShapes, because we must ensure that # the sizer won't be deselected (because they are detached when they are deselected) # deselect every other shape for s in shapes: s.SetSelected(False) s.SetMoving(False) self._selectedShapes = [cast(Shape, shape)] cast(Shape, shape).SetSelected(True) cast(Shape, shape).SetMoving(True) self._clickedShape = cast(Shape, None) self.Refresh() self.Bind(EVT_MOTION, self.OnMove)
def OnMouse(self, event: wx.MouseEvent): if self.HasCapture() and self.captured_item is not None: hit_item = self.captured_item else: hit_item = self.HitTest(event.GetPosition()) if hit_item is not None: event.SetX(event.GetX() - hit_item.position.x) event.SetY(event.GetY() - hit_item.position.y) event.SetEventObject(hit_item) wx.PostEvent(hit_item, event) event.Skip(False) else: self.SetCursor(wx.Cursor(wx.CURSOR_ARROW)) event.Skip(True)
def _BeginSelect(self, event: MouseEvent): """ Create a selector box and manage it. @param event """ if not event.ControlDown(): self.DeselectAllShapes() x, y = event.GetX(), event.GetY() # event position has been modified self._selector = rect = RectangleShape(x, y, 0, 0) rect.SetDrawFrame(True) rect.SetBrush(TRANSPARENT_BRUSH) rect.SetMoving(True) self._diagram.AddShape(rect) self.PrepareBackground() self.Bind(EVT_MOTION, self._OnMoveSelector)
def OnRightDown(self, event: MouseEvent): """ Handle right clicks on our UML LineShape- Override base handler; It does nothing Args: event: """ menu: Menu = Menu() menu.Append(ID_ANY, _('Add Bend'), _('Add Bend at right click point')) x: int = event.GetX() y: int = event.GetY() clickPoint: Tuple[int, int] = (x, y) self.clsLogger.debug(f'OglLink - x,y: {x},{y}') # Callback menu.Bind(EVT_MENU, lambda evt, data=clickPoint: self.onAddBend(evt, data)) frame = self._diagram.GetPanel() frame.PopupMenu(menu, x, y)
def OnMotion(self, event: wx.MouseEvent): x = event.GetX() y = event.GetY() if event.LeftIsDown(): # Normal scene movement without selection if not self.selection_mode and self._x > -1 and self._y > -1: self.camera_interactor.mouse_motion(x - self._x, y - self._y, event.ShiftDown(), event.AltDown(), event.ControlDown()) self._x = x self._y = y # Left-mouse drag selection, movement disabled if self.selection_mode and self.selection_mode is GLSelectionControls.BOX and \ not self.selection_mode_depressed: if self.start_x == -1 and self.start_y == -1: self.start_x = self._x self.start_y = self._y self.camera.box_select.from_screen_coords( (self.start_x, self.start_y), (self._x, self._y)) self.Sync() self.Refresh() # Scene movement with selection enabled elif event.RightIsDown() and self.selection_mode: if self._x > -1 and self._y > -1: self.camera_interactor.mouse_motion(x - self._x, y - self._y, event.ShiftDown(), event.AltDown(), event.ControlDown()) self._x = x self._y = y # Reset mouse coordinates else: self._x = self._y = self.start_x = self.start_y = -1 event.Skip()
def OnMotion(self, event: wx.MouseEvent): canvas_pos = self.canvas.GetScreenPosition() canvas_size = self.canvas.GetSize() if self.dragging and event.LeftIsDown(): if self.mouse_pos.x != -1 and self.mouse_pos.y != -1: pos = self.GetPosition() new_pos = wx.Point(pos.x + event.GetX() - self.mouse_pos.x, pos.y + event.GetY() - self.mouse_pos.y) size = self.GetSize() if new_pos.x < canvas_pos.x: new_pos.x = canvas_pos.x if new_pos.y < canvas_pos.y: new_pos.y = canvas_pos.y if new_pos.x + size.x > canvas_pos.x + canvas_size.x: new_pos.x = canvas_pos.x + canvas_size.x - size.x if new_pos.y + size.y > canvas_pos.y + canvas_size.y: new_pos.y = canvas_pos.y + canvas_size.y - size.y self.SetPosition(new_pos) self.translucent_background.SetPosition(new_pos) else: self.mouse_pos = event.GetPosition() else: self.mouse_pos = wx.DefaultPosition