Example #1
0
    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)
Example #2
0
 def OnMouseDown(self, evt: wx.MouseEvent):
     if not self.dictating:
         evt.Skip(True)
         return
     if evt.ButtonDown(1):
         self.rtext.SetInsertionPointEnd()
         evt.Skip(False)
Example #3
0
    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)
Example #4
0
    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 OnMouse(self, event: wx.MouseEvent) -> None:
        pos = event.GetPosition()
        x, y, r = self.ROI
        if event.LeftDClick():
            # Set circle centre
            self.MoveCircle(pos, r)
        elif event.Dragging():
            # Drag circle centre or radius
            drag_r = np.sqrt((x - pos[0])**2 + (y - pos[1])**2)
            if self._dragging is None:
                # determine what to drag
                if drag_r < 0.5 * r:
                    # closer to center
                    self._dragging = "xy"
                else:
                    # closer to edge
                    self._dragging = "r"
            elif self._dragging == "r":
                # Drag circle radius
                self.MoveCircle((x, y), drag_r)
            elif self._dragging == "xy":
                # Drag circle centre
                self.MoveCircle(pos, r)

        if not event.Dragging():
            # Stop dragging
            self._dragging = None
            self.circle.SetColor("cyan")

        self.canvas.Draw(Force=True)
Example #6
0
    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)
Example #7
0
 def on_mouse_move(self, event: wx.MouseEvent):
     """
     Scene Panel move event. Calls hover if the mouse has no pressed buttons.
     Calls move if the mouse is currently dragging.
     """
     if event.Moving():
         self.scene.event(event.GetPosition(), "hover", None)
     else:
         self.scene.event(event.GetPosition(), "move", None)
 def on_mouse(self, event: wx.MouseEvent):
     if event.LeftDClick() or event.LeftDown():
         clicked_time = time.time()
         if clicked_time - self._last_click < 0.5:
             self._nearest = not self._nearest
             self.Refresh()
             self._last_click = 0
         else:
             self._last_click = clicked_time
Example #9
0
 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()
Example #10
0
 def _on_wheel(self, evt: wx.MouseEvent):
     """Add scroll wheel behaviour to the input."""
     rotation = evt.GetWheelRotation()
     ctrl = evt.GetEventObject()
     if rotation > 0:
         ctrl.SetValue(ctrl.GetValue() + ctrl.GetIncrement())
         self._changed(ctrl)
     elif rotation < 0:
         ctrl.SetValue(ctrl.GetValue() - ctrl.GetIncrement())
         self._changed(ctrl)
Example #11
0
    def on_mouse_wheel(self, event: wx.MouseEvent) -> None:
        """On mouse wheel change, adjust zoom accordingly."""
        if not self._gl_initialized or event.MiddleIsDown():
            return

        scale = self.get_scale_factor()
        event.x = int(event.x * scale)
        event.y = int(event.y * scale)

        self._update_camera_zoom(event.WheelRotation / event.WheelDelta)
Example #12
0
 def OnMouseDown(self: wx.Window, e: wx.MouseEvent):
     self.dragging = True
     self.startOfDrag = self.lastMousePosition = e.GetPosition()
     if self.FindWindow("Action").Value == "Draw":
         self.AddShape(e)
     elif self.FindWindow("Action").Value == "Select":
         p = wx.Pen(wx.BLACK, 1)
         self.selectionBox = Rectangle(p, self.startOfDrag.x,
                                          self.startOfDrag.y)
     e.Skip()
Example #13
0
    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)
Example #14
0
    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)
Example #15
0
    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()
Example #16
0
    def OnMouseWheel(self, event: wx.MouseEvent):
        if self.selection_mode:
            return

        self.camera_interactor.mouse_wheel(event.GetWheelRotation(),
                                           event.GetWheelDelta(),
                                           event.ShiftDown(), event.AltDown(),
                                           event.ControlDown())
        self._x = self._y = -1
        self.Sync()
        self.Refresh()
Example #17
0
    def on_mouse_motion(self, evt: wx.MouseEvent):
        # Dragging
        if evt.Dragging() and evt.LeftIsDown():
            if self.selected < 0:
                return
            drag_end_x, drag_end_y = evt.GetPosition()
            control_points = self.tfunc.control_points
            w, h = self.GetSize()
            h = h - 30

            if self.selected == 0 or self.selected == len(control_points) - 1:
                cp = self.get_control_point_area(control_points[self.selected])
                drag_end_x = cp.get_center_x()
                if drag_end_y < 0:
                    drag_end_y = 0
                if drag_end_y > h:
                    drag_end_y = h
            else:
                left_point = self.get_control_point_area(
                    control_points[self.selected - 1])
                right_point = self.get_control_point_area(
                    control_points[self.selected + 1])

                if drag_end_x <= left_point.get_center_x() + 1:
                    drag_end_x = left_point.get_center_x() + 2
                if drag_end_x >= right_point.get_center_x() - 1:
                    drag_end_x = right_point.get_center_x() - 2
                if drag_end_y < 0:
                    drag_end_y = 0
                if drag_end_y > h:
                    drag_end_y = h

            value_range = self.tfunc.sMax - self.tfunc.sMin
            minimum = self.tfunc.sMin
            t = drag_end_x / w
            s = int((t * value_range) + minimum)
            a = (h - drag_end_y) / h

            self.tfunc.update_control_point_scalar(self.selected, s)
            self.tfunc.update_control_point_alpha(self.selected, a)
            self.editor.set_selected_info(self.selected, s, a,
                                          control_points[self.selected].color)
            self.Refresh()
        # Moving around
        else:
            x, y = evt.GetPosition()
            control_points = self.tfunc.control_points
            if any(
                    self.get_control_point_area(cp).contains(x, y)
                    for cp in control_points):
                self.SetCursor(wx.Cursor(wx.CURSOR_HAND))
            else:
                self.SetCursor(wx.Cursor(wx.CURSOR_DEFAULT))
Example #18
0
 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()
Example #19
0
    def on_mouse_down(self, evt: wx.MouseEvent):
        self.drag_start = None
        control_points = self.tfunc.control_points
        inside = False
        idx = 0
        x, y = evt.GetPosition()
        while not inside and idx < len(control_points):
            inside = inside | self.get_control_point_area(
                control_points[idx]).contains(x, y)
            if inside:
                break
            else:
                idx = idx + 1

        if inside:
            if evt.GetButton() == wx.MOUSE_BTN_LEFT:
                self.selected = idx
                control_point = control_points[self.selected]
                self.editor.set_selected_info(self.selected,
                                              control_point.value,
                                              control_point.color.a,
                                              control_point.color)
                self.drag_start = (x, y)
            elif evt.GetButton() == wx.MOUSE_BTN_RIGHT:
                if 0 < idx < len(control_points) - 1:
                    self.tfunc.remove_control_point(idx)
                    self.selected = idx - 1
                    control_point = control_points[self.selected]
                    self.editor.set_selected_info(self.selected,
                                                  control_point.value,
                                                  control_point.color.a,
                                                  control_point.color)
                    self.drag_start = (x, y)
        else:
            w, h = self.GetSize()
            if 0 <= x < w and 0 <= y < h - 30:
                h = h - 30
                value_range = self.tfunc.sMax - self.tfunc.sMin
                minimum = self.tfunc.sMin
                t = x / w
                s = int((t * value_range) + minimum)
                a = (h - y) / h
                self.selected = self.tfunc.add_control_point(s, .0, .0, .0, a)
                control_point = control_points[self.selected]
                self.editor.set_selected_info(self.selected,
                                              control_point.value,
                                              control_point.color.a,
                                              control_point.color)
                self.drag_start = (x, y)
                self.Refresh()
Example #20
0
    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)
Example #21
0
    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)
Example #22
0
    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)
Example #23
0
    def OnMotion(self, evt: wx.MouseEvent):
        """
        Handler for mouse motion events.

        Args: 
            self: the Designer Window to initialize.
            evt: the event being executed.

        """
        pos = Vec2(evt.GetPosition())
        if self.dragging:
            self.dragged_point = pos
        else:
            self.update_hover_idx(pos)
            evt.Skip()
        self.Refresh()
Example #24
0
    def OnMouseMove(self: wx.Window, e: wx.MouseEvent):
        if self.dragging:
            shape = self.shapes[-1]
            if self.FindWindow("Action").Value == "Move":
                if not self.lastMousePosition:
                    self.lastMousePosition = e.GetPosition()
                shape.MoveBy(e.x - self.lastMousePosition.x, 
                             e.y - self.lastMousePosition.y)
            elif self.FindWindow("Action").Value == "Draw":
                shape.GrowTo(e.x, e.y)
            elif self.FindWindow("Action").Value == "Select":
                self.selectionBox.GrowTo(e.x, e.y)
                self.SelectShapes()

            self.lastMousePosition = e.GetPosition()
            self.Refresh()
Example #25
0
    def OnMove(self, event: MouseEvent):
        """
        Callback for mouse movements.

        @param  event
        """
        event.m_x, event.m_y = self.getEventPosition(event)
        self.OnDrag(event)
Example #26
0
 def OnRightDClick(self, event: MouseEvent):
     """
     Callback for right double clicks.
     Args:
         event:
     """
     self.clsLogger.debug("Unhandled right double click")
     event.Skip()
Example #27
0
 def OnRightUp(self, event: MouseEvent):
     """
     Callback for right clicks.
     Args:
         event:
     """
     self.clsLogger.debug("Unhandled right up")
     event.Skip()
Example #28
0
    def OnMiddleDClick(self, event: MouseEvent):
        """
        Callback for middle double clicks.

        @param  event
        """
        self.clsLogger.debug("Unhandled middle double click")
        event.Skip()
Example #29
0
 def OnLeftDown(self, event: MouseEvent):
     """
     Callback for left clicks.
     Args:
         event:
     """
     self.clsLogger.info("Unhandled left down")
     event.Skip()
Example #30
0
    def OnMouseMove(self, event: wx.MouseEvent):
        if self.timeline.start == self.timeline.end:
            return

        if self._dragging and event.LeftIsDown():
            x = event.GetPosition().x
            if self._uniform_time_intervals:
                t = self.timeline.time_at_index(round(x / self.px_per_step))
            else:
                t = self.time_at_position(x)

            if t != self._scrub_time:
                self._scrub_time = t

                if self.live_update:
                    self.timeline.current = self._scrub_time
                self.Refresh()