示例#1
0
 def add_figure(self):
     """Add the current figure to the stack of views and positions"""
     if self.figure not in self.views:
         self.views[self.figure] = cbook.Stack()
         self.positions[self.figure] = cbook.Stack()
         # Define Home
         self.push_current()
         # Adding the clear method as axobserver, removes this burden from
         # the backend
         self.figure.add_axobserver(self.clear)
示例#2
0
 def add_figure(self):
     """Add the current figure to the stack of views and positions"""
     if self.figure not in self.views:
         self.views[self.figure] = cbook.Stack()
         self.positions[self.figure] = cbook.Stack()
         self.home_views[self.figure] = WeakKeyDictionary()
         # Define Home
         self.push_current()
         # Make sure we add a home view for new axes as they're added
         self.figure.add_axobserver(lambda fig: self.update_home_views())
示例#3
0
    def __init__(self, canvas):
        self.canvas = canvas
        canvas.toolbar = self
        # a dict from axes index to a list of view limits
        self._views = cbook.Stack()
        self._positions = cbook.Stack()  # stack of subplot positions
        self._xypress = None  # the location and axis info at the time
                              # of the press
        self._idPress = None
        self._idRelease = None
        self._active = None
        self._lastCursor = None
        self._init_toolbar()
        self._idDrag = self.canvas.mpl_connect(
            'motion_notify_event', self.mouse_move)

        self._ids_zoom = []
        self._zoom_mode = None

        self._button_pressed = None  # determined by the button pressed
                                     # at start

        self.mode = ''  # a mode string for the status bar
        self.set_history_buttons()
示例#4
0
    def __init__(self, canvas, parent, coordinates=True):
        """ coordinates: should we show the coordinates on the right? """
        self.canvas = canvas
        self.parent = parent
        self._nav_stack = cbook.Stack()
        self.coordinates = coordinates
        self._actions = {}
        """A mapping of toolitem method names to their QActions"""
        self.toolitems = (
            ('Home', 'Reset original view', 'home', 'home'),
            ('Back', 'Back to previous view', 'back', 'back'),
            ('Forward', 'Forward to next view', 'forward', 'forward'),
            (None, None, None, None),
            #('Pan', 'Pan axes with left mouse, zoom with right', 'move', 'pan'),
            ('Zoom', 'Zoom to rectangle', 'zoom_to_rect', 'zoom'),
            # ('Subplots', 'Configure subplots', 'subplots', 'configure_subplots'),
            (None, None, None, None),
            # ('Save', 'Save the figure', 'filesave', 'save_figure'),
        )

        QtWidgets.QToolBar.__init__(self, parent)
        NavigationToolbar2.__init__(self, canvas)
示例#5
0
    def __init__(self, panel, canvas, auiTarget=None):
        self.panel = panel

        if not auiTarget:
            auiTarget = panel


#        PatchedAuiToolBar.__init__( self, auiTarget, -1, wx.DefaultPosition, wx.DefaultSize,
#                                    aui.AUI_TB_DEFAULT_STYLE | aui.AUI_TB_PLAIN_BACKGROUND
#                                        #| aui.AUI_TB_TEXT
#                                    )
        aui.AuiToolBar.__init__(self, auiTarget, -1, wx.DefaultPosition,
                                wx.DefaultSize, aui.AUI_TB_DEFAULT_STYLE
                                | aui.AUI_TB_PLAIN_BACKGROUND
                                #| aui.AUI_TB_TEXT
                                )
        self.SetName("Renderer toolbar")

        #NavigationToolbar2.__init__(self, canvas)
        self.canvas = canvas
        self._idle = True
        self.statbar = None

        self.SetToolBitmapSize(wx.Size(22, 22))

        # self.AddSimpleTool( 'Reset view', self.CUSTOM_HOME_ID, loadIcon( "go-home.png" )
        #, 'Reset original view' )

        # self.AddCheckTool( self._NTB2_PAN, loadIcon( "my-trans.png" )
        #, shortHelp='Pan'
        #, longHelp='Pan with left, zoom with right mouse button')

        # self.AddSimpleTool( self.CUSTOM_PAN_LEFT_ID, loadIcon( "go-previous.png" )
        #, 'Pan to the left'
        #, 'Pan view within axes to the left')

        # self.AddSimpleTool( self.CUSTOM_PAN_RIGHT_ID, loadIcon( "go-next.png" )
        #, 'Pan to the right'
        #, 'Pan view within axes to the right')

        # self.AddSeparator()

        dec = self.AddSimpleTool(self.CUSTOM_DEC_CANVAS_WIDTH_ID,
                                 'Decrease canvas',
                                 loadIcon("zoom-dec-width.png"),
                                 'Decrease canvas width')
        dec.SetDisabledBitmap(
            MakeDisabledBitmap(loadIcon("zoom-dec-width.png")))

        self.canvasComboBox = ListCtrlComboPopupControl(
            self,
            style=wx.CB_READONLY | wx.CB_DROPDOWN  # |wx.NO_BORDER
            ,
            size=(87, -1))
        self.canvasComboBox.popup.dismissCallback = self.onCanvasWidthCombo
        self.canvasComboBox.addItems(self.canvasWidthScalesNames)
        self.canvasComboBox.select(0)
        self.canvasComboBox.SetInitialSize((87, 22))
        self.canvasComboBox.SetToolTip(wx.ToolTip('Select canvas width zoom'))
        self.AddControl(self.canvasComboBox, 'canvas width')

        inc = self.AddSimpleTool(self.CUSTOM_INC_CANVAS_WIDTH_ID,
                                 'Increase canvas',
                                 loadIcon("zoom-inc-width.png"),
                                 'Increase canvas width')
        inc.SetDisabledBitmap(
            MakeDisabledBitmap(loadIcon("zoom-inc-width.png")))
        self.EnableTool(self.CUSTOM_DEC_CANVAS_WIDTH_ID, False)

        self.AddSimpleTool(self.CUSTOM_FIT_CANVAS_ID, 'Fit canvas',
                           loadIcon("zoom-fit-best.png"),
                           'Fit canvas to image size')

        self.aspectTool = self.AddSimpleTool(self.CUSTOM_ASPECT_AUTO_ID,
                                             'Auto aspect',
                                             loadIcon("transform-scale.png"),
                                             'Auto aspect', wx.ITEM_CHECK)

        # if ( self.panel.figure.get_axes()[ 0 ].get_aspect() == 'auto' ):
        #self.ToggleTool( self.CUSTOM_ASPECT_AUTO_ID, True )

        self.AddSimpleTool(
            self.CUSTOM_PAGE_ZOOM_ID, 'Zoom axes', loadIcon("zoom-select.png"),
            ' Left mouse button to select rectangle zoom area\n Middle mouse button to pan axes\n Right click to zoom out.',
            wx.ITEM_CHECK)
        self.AddSimpleTool(
            self.CUSTOM_HOME_ID, 'Home', loadIcon("zoom-original.png"),
            'Restore the original view, i.e., reset zoom to fit image')

        self.AddSeparator()
        self.AddSimpleTool(self.CUSTOM_SAVE_IMAGE_ID, 'Save image',
                           loadIcon("my-image-save.png"),
                           'Save plot contents to file')
        # self.AddTool( self.CUSTOM_SAVE_IMAGE_ID, "Save image", loadIcon( "my-image-save.png" ), wx.NullBitmap
        #, wx.ITEM_NORMAL, "Save image", "Save plot contents to file", None)

        #wx.EVT_TOOL( self, self.CUSTOM_PAN_LEFT_ID, self.onCustomPanLeft )
        #wx.EVT_TOOL( self, self.CUSTOM_PAN_RIGHT_ID, self.onCustomPanRight )
        wx.EVT_TOOL(self, self.CUSTOM_INC_CANVAS_WIDTH_ID,
                    self.onIncCanvasWidth)
        wx.EVT_TOOL(self, self.CUSTOM_DEC_CANVAS_WIDTH_ID,
                    self.onDecCanvasWidth)
        wx.EVT_TOOL(self, self.CUSTOM_FIT_CANVAS_ID, self.onFitCanvas)
        wx.EVT_TOOL(self, self.CUSTOM_ASPECT_AUTO_ID, self.onAspectAuto)
        wx.EVT_TOOL(self, self.CUSTOM_SAVE_IMAGE_ID, self.save)
        wx.EVT_TOOL(self, self.CUSTOM_PAGE_ZOOM_ID, self.onZoomButton)
        wx.EVT_TOOL(self, self.CUSTOM_HOME_ID, self.onHome)
        #self.Bind( wx.EVT_TEXT, self.onCanvasWidthCombo, id=self.CUSTOM_CANVAS_WIDTH_COMBO_ID )
        #self.canvasComboBox.Bind( wx.EVT_TEXT, self.onCanvasWidthCombo )

        self.mouseMoveID_ = None
        self.mousePressID_ = None
        self.mouseReleaseID_ = None
        self.buttonPressed_ = None
        self.rubberBander_ = MPLRubberBander(self.canvas)

        self.views_ = cbook.Stack()
        self.positions_ = cbook.Stack()