Ejemplo n.º 1
0
    def onContextMenu(self, event):
        """
        Default context menu for a plot panel
        """
        # Define a location event for the position of the popup

        # TODO: convert from screen coords to window coords
        x, y = event.GetPosition()
        self.menuevent = LocationEvent("context",
                                       self.canvas,
                                       x,
                                       y,
                                       guiEvent=event)

        popup = wx.Menu()
        item = popup.Append(wx.ID_ANY, '&Save image', 'Save image as PNG')
        wx.EVT_MENU(self, item.GetId(), self.onSaveImage)
        item = popup.Append(wx.ID_ANY, '&Grid on/off', 'Toggle grid lines')
        wx.EVT_MENU(self, item.GetId(), self.onGridToggle)
        cmaps = CMapMenu(self, mapper=self.colormapper, canvas=self.canvas)
        item = popup.AppendMenu(wx.ID_ANY, "Colourmaps", cmaps)
        #popup.Append(315,'&Properties...','Properties editor for the graph')
        #wx.EVT_MENU(self, 315, self.onProp)

        pos = event.GetPosition()
        pos = self.ScreenToClient(pos)
        self.PopupMenu(popup, pos)
Ejemplo n.º 2
0
    def dropEvent(self, event):
        """
        If the event data contains a workspace reference then
        request a plot of the workspace.

        :param event: A QDropEvent containing the MIME
                      data of the action
        """
        from matplotlib.backend_bases import LocationEvent
        workspace_names = event.mimeData().text().split('\n')

        # This creates a matplotlib LocationEvent so that the axis in which the
        # drop event occurred can be calculated
        try:
            x, y = self._canvas.mouseEventCoords(event.pos())
        except AttributeError:  # matplotlib v1.5 does not have mouseEventCoords
            try:
                dpi_ratio = self._canvas.devicePixelRatio() or 1
            except AttributeError:
                dpi_ratio = 1
            x = dpi_ratio * event.pos().x()
            y = dpi_ratio * self._canvas.figure.bbox.height / dpi_ratio - event.pos(
            ).y()

        location_event = LocationEvent('AxesGetterEvent', self._canvas, x, y)
        ax = location_event.inaxes if location_event.inaxes else self._canvas.figure.axes[
            0]

        self._plot_on_here(workspace_names, ax)
        QMainWindow.dropEvent(self, event)
Ejemplo n.º 3
0
    def dropEvent(self, event):
        """
        If the event data contains a workspace reference then
        request a plot of the workspace.

        :param event: A QDropEvent containing the MIME
                      data of the action
        """
        from matplotlib.backend_bases import LocationEvent
        workspace_names = event.mimeData().text().split('\n')

        # This creates a matplotlib LocationEvent so that the axis in which the drop event occurred can be calculated
        x, y = self._canvas.mouseEventCoords(event.pos())
        location_event = LocationEvent('AxesGetterEvent', self._canvas, x, y)
        ax = location_event.inaxes if location_event.inaxes else self._canvas.figure.axes[0]

        self._plot_on_here(workspace_names, ax)
        QMainWindow.dropEvent(self, event)
def test_location_event_position():
    # LocationEvent should cast its x and y arguments
    # to int unless it is None
    fig = plt.figure()
    canvas = FigureCanvasBase(fig)
    test_positions = [(42, 24), (None, 42), (None, None),
                      (200, 100.01), (205.75, 2.0)]
    for x, y in test_positions:
        event = LocationEvent("test_event", canvas, x, y)
        if x is None:
            assert event.x is None
        else:
            assert event.x == int(x)
            assert isinstance(event.x, int)
        if y is None:
            assert event.y is None
        else:
            assert event.y == int(y)
            assert isinstance(event.y, int)
Ejemplo n.º 5
0
def test_location_event_position(x, y):
    # LocationEvent should cast its x and y arguments to int unless it is None.
    fig, ax = plt.subplots()
    canvas = FigureCanvasBase(fig)
    event = LocationEvent("test_event", canvas, x, y)
    if x is None:
        assert event.x is None
    else:
        assert event.x == int(x)
        assert isinstance(event.x, int)
    if y is None:
        assert event.y is None
    else:
        assert event.y == int(y)
        assert isinstance(event.y, int)
    if x is not None and y is not None:
        assert re.match(
            "x={} +y={}".format(ax.format_xdata(x), ax.format_ydata(y)),
            ax.format_coord(x, y))
        ax.fmt_xdata = ax.fmt_ydata = lambda x: "foo"
        assert re.match("x=foo +y=foo", ax.format_coord(x, y))
Ejemplo n.º 6
0
 def set_active_tab(self, tab_name: str) -> None:
     event = LocationEvent("click", self.figure.canvas, 0, 0)
     event.inaxes = self.tabs_data[tab_name]["button"].ax
     self.__click(event, force_update=True)
Ejemplo n.º 7
0
 def __init__(self, name, cursor, x, y, id_, **kwargs):
     LocationEvent.__init__(self, name, cursor.ax.figure.canvas, x, y,
                            **kwargs)
     self.id = id_
     self.cursor = cursor