Beispiel #1
0
 def __init__( self, canvas, num ):
     if DEBUG: print 'FigureManagerQT.%s' % fn_name()
     FigureManagerBase.__init__( self, canvas, num )
     self.canvas = canvas
     self.window = qt.QMainWindow( None, None, qt.Qt.WDestructiveClose )
     self.window.closeEvent = self._widgetCloseEvent
     centralWidget = qt.QWidget( self.window )
     self.canvas.reparent( centralWidget, qt.QPoint( 0, 0 ) )
     self.canvas.setFocusPolicy( qt.QWidget.ClickFocus )
     self.canvas.setFocus()
     self.window.setCaption( "Figure %d" % num )
     self.window._destroying = False
     self.toolbar = self._get_toolbar(self.canvas, centralWidget)
     self.layout = qt.QVBoxLayout( centralWidget )
     self.layout.addWidget( self.canvas, 1 )
     if self.toolbar:
        self.layout.addWidget( self.toolbar, 0 )
     self.window.setCentralWidget( centralWidget )
     w = self.canvas.width()
     h = self.canvas.height()
     if self.toolbar:
        h += self.toolbar.height() + 4
     self.window.resize( w, h )
     if matplotlib.is_interactive():
         self.window.show()
     self.canvas.figure.show = lambda *args: self.window.show()
     def notify_axes_change( fig ):
        if self.toolbar != None: self.toolbar.update()
     self.canvas.figure.add_axobserver( notify_axes_change )
Beispiel #2
0
    def __init__(self, *args, **kwargs):
        # pull non-standard keyword arguments
        refresh = kwargs.pop('auto_refresh', False)

        # dynamically set the subplot positions based on the figure size
        # -- only if the user hasn't customised the subplot params
        figsize = kwargs.get('figsize', rcParams['figure.figsize'])
        subplotpars = get_subplot_params(figsize)
        use_subplotpars = 'subplotpars' not in kwargs and all([
            rcParams['figure.subplot.%s' % pos] ==
            MPL_RCPARAMS['figure.subplot.%s' % pos] for
            pos in ('left', 'bottom', 'right', 'top')])
        if use_subplotpars:
            kwargs['subplotpars'] = subplotpars

        # generated figure, with associated interactivity from pyplot
        super(Plot, self).__init__(*args, **kwargs)
        backend_mod, _, draw_if_interactive, _ = backends.pylab_setup()
        try:
            manager = backend_mod.new_figure_manager_given_figure(1, self)
        except AttributeError:
            canvas = backend_mod.FigureCanvas(self)
            manager = FigureManagerBase(canvas, 1)
        cid = manager.canvas.mpl_connect(
            'button_press_event',
            lambda ev: _pylab_helpers.Gcf.set_active(manager))
        manager._cidgcf = cid
        _pylab_helpers.Gcf.set_active(manager)
        draw_if_interactive()

        # finalise
        self.set_auto_refresh(refresh)
        self.colorbars = []
        self._coloraxes = []
Beispiel #3
0
    def __init__(self, canvas, num, window):
        FigureManagerBase.__init__(self, canvas, num)
        self.window = window
        self.window.withdraw()
        self.set_window_title("Figure %d" % num)
        self.canvas = canvas
        # If using toolmanager it has to be present when initializing the toolbar
        self.toolmanager = self._get_toolmanager()
        # packing toolbar first, because if space is getting low, last packed widget is getting shrunk first (-> the canvas)
        self.toolbar = self._get_toolbar()
        self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        self._num = num

        self.statusbar = None

        if self.toolmanager:
            backend_tools.add_tools_to_manager(self.toolmanager)
            if self.toolbar:
                backend_tools.add_tools_to_container(self.toolbar)
                self.statusbar = StatusbarTk(self.window, self.toolmanager)

        self._shown = False

        def notify_axes_change(fig):
            'this will be called whenever the current axes is changed'
            if self.toolmanager is not None:
                pass
            elif self.toolbar is not None:
                self.toolbar.update()
        self.canvas.figure.add_axobserver(notify_axes_change)
Beispiel #4
0
    def __init__(self, canvas, num, window):
        FigureManagerBase.__init__(self, canvas, num)
        # Fltk container window
        t1, t2, w, h = canvas.figure.bbox.get_bounds()
        w, h = int(w), int(h)
        self.window = window
        self.window.size(w, h + 30)
        self.window_title = "Figure %d" % num
        self.window.label(self.window_title)
        self.window.size_range(350, 200)
        self.window.callback(destroy_figure, self)
        self.canvas = canvas
        self._num = num
        if matplotlib.rcParams["toolbar"] == "classic":
            self.toolbar = NavigationToolbar(canvas, self)
        elif matplotlib.rcParams["toolbar"] == "toolbar2":
            self.toolbar = NavigationToolbar2FltkAgg(canvas, self)
        else:
            self.toolbar = None
        self.window.add_resizable(canvas.widget())
        if self.toolbar:
            self.window.add(self.toolbar.widget())
            self.toolbar.update()
        self.window.show()

        def notify_axes_change(fig):
            "this will be called whenever the current axes is changed"
            if self.toolbar != None:
                self.toolbar.update()

        self.canvas.figure.add_axobserver(notify_axes_change)
Beispiel #5
0
    def __init__(self, canvas, num):
        if DEBUG: print 'FigureManagerGTK.%s' % fn_name()
        FigureManagerBase.__init__(self, canvas, num)
        
        self.window = gtk.Window()
        self.window.set_title("Figure %d" % num)

        vbox = gtk.VBox()
        self.window.add(vbox)
        vbox.show()

        self.canvas.show()
        vbox.pack_start(self.canvas, True, True)

        # must be inited after the window, drawingArea and figure
        # attrs are set
        if matplotlib.rcParams['toolbar']=='classic':
            self.toolbar = NavigationToolbar (canvas, self.window)
        elif matplotlib.rcParams['toolbar']=='toolbar2':
            self.toolbar = NavigationToolbar2GTK (canvas, self.window)
        else:
            self.toolbar = None

        if self.toolbar != None:
            self.toolbar.show()
            vbox.pack_end(self.toolbar, False, False)

        def destroy(*args): Gcf.destroy(num)
        self.window.connect("destroy", destroy)
        self.window.connect("delete_event", destroy)        
        if matplotlib.is_interactive():
            self.window.show()
Beispiel #6
0
    def __init__( self, canvas, num ):
        if DEBUG: print 'FigureManagerQT.%s' % fn_name()
        FigureManagerBase.__init__( self, canvas, num )
        self.canvas = canvas
        self.window = qt.QMainWindow()
        
        self.canvas.reparent( self.window, qt.QPoint( 0, 0 ) )
        # Give the keyboard focus to the figure instead of the manager
        self.canvas.grabKeyboard()
        self.window.setCaption( "Figure %d" % num )
        self.window.setCentralWidget( self.canvas )

        if matplotlib.rcParams['toolbar'] == 'classic':
            print "Classic toolbar is not yet supported"
            #self.toolbar = NavigationToolbar( canvas, self.window )
            self.toolbar = None
        elif matplotlib.rcParams['toolbar'] == 'toolbar2':
            self.toolbar = NavigationToolbar2QT( canvas, self.window )
        else:
            self.toolbar = None

        self.window.resize( self.canvas.size() )
        
        if matplotlib.is_interactive():
            self.window.show()

        def notify_axes_change( fig ):
           # This will be called whenever the current axes is changed
           if self.toolbar != None: self.toolbar.update()
           self.canvas.figure.add_axobserver( notify_axes_change )
Beispiel #7
0
    def __init__(self, canvas, num, window):
        FigureManagerBase.__init__(self, canvas, num)
        self.window = window
        self.window.withdraw()
        self.window.wm_title("Figure %d" % num)
        self.canvas = canvas
        self._num =  num
        t1,t2,w,h = canvas.figure.bbox.bounds
        w, h = int(w), int(h)
        self.window.minsize(int(w*3/4),int(h*3/4))
        if matplotlib.rcParams['toolbar']=='classic':
            self.toolbar = NavigationToolbar( canvas, self.window )
        elif matplotlib.rcParams['toolbar']=='toolbar2':
            self.toolbar = NavigationToolbar2TkAgg( canvas, self.window )
        else:
            self.toolbar = None
        if self.toolbar is not None:
            self.toolbar.update()
        self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        self._shown = False

        def notify_axes_change(fig):
            'this will be called whenever the current axes is changed'
            if self.toolbar != None: self.toolbar.update()
        self.canvas.figure.add_axobserver(notify_axes_change)



        # attach a show method to the figure for pylab ease of use
        self.canvas.figure.show = lambda *args: self.show()
Beispiel #8
0
    def __init__(self, canvas, num):
        FigureManagerBase.__init__(self, canvas, num)
        self.canvas = canvas
        self.window = MainWindow()
        self.window.closing.connect(canvas.close_event)
        self.window.closing.connect(self._widgetclosed)

        self.window.setWindowTitle("Figure %d" % num)
        image = os.path.join(matplotlib.rcParams['datapath'],
                             'images', 'matplotlib.svg')
        self.window.setWindowIcon(QtGui.QIcon(image))

        # Give the keyboard focus to the figure instead of the
        # manager; StrongFocus accepts both tab and click to focus and
        # will enable the canvas to process event w/o clicking.
        # ClickFocus only takes the focus is the window has been
        # clicked
        # on. http://qt-project.org/doc/qt-4.8/qt.html#FocusPolicy-enum or
        # http://doc.qt.digia.com/qt/qt.html#FocusPolicy-enum
        self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.canvas.setFocus()

        self.window._destroying = False

        self.toolmanager = self._get_toolmanager()
        self.toolbar = self._get_toolbar(self.canvas, self.window)
        self.statusbar = None

        if self.toolmanager:
            backend_tools.add_tools_to_manager(self.toolmanager)
            if self.toolbar:
                backend_tools.add_tools_to_container(self.toolbar)
                self.statusbar = StatusbarQt(self.window, self.toolmanager)

        if self.toolbar is not None:
            self.window.addToolBar(self.toolbar)
            if not self.toolmanager:
                # add text label to status bar
                statusbar_label = QtWidgets.QLabel()
                self.window.statusBar().addWidget(statusbar_label)
                self.toolbar.message.connect(statusbar_label.setText)
            tbs_height = self.toolbar.sizeHint().height()
        else:
            tbs_height = 0

        # resize the main window so it will display the canvas with the
        # requested size:
        cs = canvas.sizeHint()
        sbs = self.window.statusBar().sizeHint()
        self._status_and_tool_height = tbs_height + sbs.height()
        height = cs.height() + self._status_and_tool_height
        self.window.resize(cs.width(), height)

        self.window.setCentralWidget(self.canvas)

        if matplotlib.is_interactive():
            self.window.show()
            self.canvas.draw_idle()

        self.window.raise_()
Beispiel #9
0
    def initWithFigure_number_(self, fig, num):
        """__init__"""

        win = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
            NSMakeRect(100, 100, 640, 480),
            NSBorderlessWindowMask
            | NSTitledWindowMask
            | NSClosableWindowMask
            | NSMiniaturizableWindowMask
            | NSResizableWindowMask,
            NSBackingStoreBuffered,
            True,
        )
        self = super(FigureManagerCocoa, self).initWithWindow_(win)
        if self != None:
            cViewBounds = self.window().contentView().bounds()
            plotViewFrame = NSMakeRect(0, 0, cViewBounds.size.width, cViewBounds.size.height)
            plotView = FigureCanvasView.alloc().initWithFrame_figure_(plotViewFrame, fig)
            plotView.setAutoresizingMask_(NSViewWidthSizable | NSViewHeightSizable)

            FigureManagerBase.__init__(self, plotView, num)

            self.window().contentView().addSubview_(plotView)
            self.window().setTitle_("Figure %d" % num)

            self.show_window()
        return self
Beispiel #10
0
    def __init__(self, canvas, num, window):
        FigureManagerBase.__init__(self, canvas, num)
        self.window = window
        self.window.withdraw()
        self.set_window_title("Figure %d" % num)
        self.canvas = canvas
        self._num = num
        _, _, w, h = canvas.figure.bbox.bounds
        w, h = int(w), int(h)
        self.window.minsize(int(w * 3 / 4), int(h * 3 / 4))
        if matplotlib.rcParams["toolbar"] == "classic":
            self.toolbar = NavigationToolbar(canvas, self.window)
        elif matplotlib.rcParams["toolbar"] == "toolbar2":
            self.toolbar = NavigationToolbar2TkAgg(canvas, self.window)
        else:
            self.toolbar = None
        if self.toolbar is not None:
            self.toolbar.update()
        self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        self._shown = False

        def notify_axes_change(fig):
            "this will be called whenever the current axes is changed"
            if self.toolbar != None:
                self.toolbar.update()

        self.canvas.figure.add_axobserver(notify_axes_change)
 def __init__(self, canvas, num):
     FigureManagerBase.__init__(self, canvas, num)
     global index
     index += 1
     self.canvas = canvas
     self._num = num
     self._shown = False
    def __init__(self, canvas, num):
        FigureManagerBase.__init__(self, canvas, num)
        self.canvas = canvas

        window = MatPlotWindow(mainWin.workSpace)
        window.setup(canvas, num)
        self.window = window


        QtCore.QObject.connect(window, QtCore.SIGNAL('destroyed()'),
                            self._widgetclosed)
        window._destroying = False

        toolbar = self._get_toolbar(canvas, window)
        window.toolbar = toolbar
        self.toolbar = toolbar
        if toolbar:
           window.mainLayout.addWidget(toolbar, 0)

        window.resize(640, 480)

        if matplotlib.is_interactive():
            window.setMinimumSize(200, 200)
            window.show()

        def notify_axes_change(fig):
           # This will be called whenever the current axes is changed
           if self.toolbar != None: self.toolbar.update()
           self.canvas.figure.add_axobserver(notify_axes_change)
Beispiel #13
0
    def __init__( self, canvas, num ):
        if DEBUG: print 'FigureManagerQT.%s' % fn_name()
        FigureManagerBase.__init__( self, canvas, num )
        self.canvas = canvas
        self.window = qt.QMainWindow( None, None, qt.Qt.WDestructiveClose )
        
        self.canvas.reparent( self.window, qt.QPoint( 0, 0 ) )
        # Give the keyboard focus to the figure instead of the manager
        self.canvas.setFocusPolicy( qt.QWidget.ClickFocus )
        self.canvas.setFocus()
        self.window.setCaption( "Figure %d" % num )
        self.window.setCentralWidget( self.canvas )
        qt.QObject.connect( self.window, qt.SIGNAL( 'destroyed()' ),
                            self._widgetclosed )
        self.window._destroying = False

        if matplotlib.rcParams['toolbar'] == 'classic':
            print "Classic toolbar is not yet supported"
            #self.toolbar = NavigationToolbar( canvas, self.window )
            self.toolbar = None
        elif matplotlib.rcParams['toolbar'] == 'toolbar2':
            self.toolbar = NavigationToolbar2QT( canvas, self.window )
        else:
            self.toolbar = None

        self.window.resize( self.canvas.size() )
        
        if matplotlib.is_interactive():
            self.window.show()

        def notify_axes_change( fig ):
           # This will be called whenever the current axes is changed
           if self.toolbar != None: self.toolbar.update()
           self.canvas.figure.add_axobserver( notify_axes_change )
Beispiel #14
0
 def __init__(self, canvas, num):
     if _debug: print 'FigureManagerGTK.%s' % fn_name()
     FigureManagerBase.__init__(self, canvas, num)
     self.window = gtk.Window()
     self.window.set_title("Figure %d" % num)
     if (window_icon):
         self.window.set_icon_from_file(window_icon)
     self.vbox = gtk.VBox()
     self.window.add(self.vbox)
     self.vbox.show()
     self.canvas.show()
     self.canvas.figure.show = lambda *args: self.window.show()
     self.vbox.pack_start(self.canvas, True, True)
     self.toolbar = self._get_toolbar(canvas)
     w = int (self.canvas.figure.bbox.width)
     h = int (self.canvas.figure.bbox.height)
     if self.toolbar is not None:
         self.toolbar.show()
         self.vbox.pack_end(self.toolbar, False, False)
         tb_w, tb_h = self.toolbar.size_request()
         h += tb_h
     self.window.set_default_size (w, h)
     def destroy(*args):
         Gcf.destroy(num)
     self.window.connect("destroy", destroy)
     self.window.connect("delete_event", destroy)
     if matplotlib.is_interactive():
         self.window.show()
     def notify_axes_change(fig):
         'this will be called whenever the current axes is changed'
         if self.toolbar is not None: self.toolbar.update()
     self.canvas.figure.add_axobserver(notify_axes_change)
     self.canvas.grab_focus()
Beispiel #15
0
 def __init__( self, canvas, num ):
     if DEBUG: print 'FigureManagerQT.%s' % fn_name()
     FigureManagerBase.__init__( self, canvas, num )
     self.canvas = canvas
     self.window = FigureWindow()
     self.window.setAttribute(QtCore.Qt.WA_DeleteOnClose)
     self.window.setWindowTitle("Figure %d" % num)
     image = os.path.join( matplotlib.rcParams['datapath'],'images','matplotlib.png' )
     self.window.setWindowIcon(QtGui.QIcon( image ))
     self.canvas.setFocusPolicy( QtCore.Qt.ClickFocus )
     self.canvas.setFocus()
     QtCore.QObject.connect( self.window, QtCore.SIGNAL( 'destroyed()' ),
                         self._widgetclosed )
     self.window._destroying = False
     self.toolbar = self._get_toolbar(self.canvas, self.window)
     self.window.addToolBar(self.toolbar)
     QtCore.QObject.connect(self.toolbar, QtCore.SIGNAL("message"),
             self.window.statusBar().showMessage)
     cs = canvas.sizeHint()
     tbs = self.toolbar.sizeHint()
     sbs = self.window.statusBar().sizeHint()
     self.window.resize(cs.width(), cs.height()+tbs.height()+sbs.height())
     self.window.setCentralWidget(self.canvas)
     if matplotlib.is_interactive():
         self.window.show()
     self.canvas.figure.show = lambda *args: self.window.show()
     def notify_axes_change( fig ):
        if self.toolbar != None: self.toolbar.update()
     self.canvas.figure.add_axobserver( notify_axes_change )
Beispiel #16
0
    def __init__(self, canvas, num, window):
        FigureManagerBase.__init__(self, canvas, num)
        self.window = window
        self.window.withdraw()
        self.set_window_title("Figure %d" % num)
        self.canvas = canvas
        self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        self._num = num

        self.toolmanager = self._get_toolmanager()
        self.toolbar = self._get_toolbar()
        self.statusbar = None

        if self.toolmanager:
            backend_tools.add_tools_to_manager(self.toolmanager)
            if self.toolbar:
                backend_tools.add_tools_to_container(self.toolbar)
                self.statusbar = StatusbarTk(self.window, self.toolmanager)

        self._shown = False

        def notify_axes_change(fig):
            'this will be called whenever the current axes is changed'
            if self.toolmanager is not None:
                pass
            elif self.toolbar is not None:
                self.toolbar.update()
        self.canvas.figure.add_axobserver(notify_axes_change)
Beispiel #17
0
    def __init__(self, canvas, num):
        FigureManagerBase.__init__(self, canvas, num)

        self.window = Gtk.Window()
        self.window.set_wmclass("matplotlib", "Matplotlib")
        self.set_window_title("Figure %d" % num)
        try:
            self.window.set_icon_from_file(window_icon)
        except Exception:
            # Some versions of gtk throw a glib.GError but not all, so I am not
            # sure how to catch it.  I am unhappy doing a blanket catch here,
            # but am not sure what a better way is - JDH
            _log.info('Could not load matplotlib icon: %s', sys.exc_info()[1])

        self.vbox = Gtk.Box()
        self.vbox.set_property("orientation", Gtk.Orientation.VERTICAL)
        self.window.add(self.vbox)
        self.vbox.show()

        self.canvas.show()

        self.vbox.pack_start(self.canvas, True, True, 0)
        # calculate size for window
        w = int(self.canvas.figure.bbox.width)
        h = int(self.canvas.figure.bbox.height)

        self.toolmanager = self._get_toolmanager()
        self.toolbar = self._get_toolbar()
        self.statusbar = None

        def add_widget(child, expand, fill, padding):
            child.show()
            self.vbox.pack_end(child, False, False, 0)
            size_request = child.size_request()
            return size_request.height

        if self.toolmanager:
            backend_tools.add_tools_to_manager(self.toolmanager)
            if self.toolbar:
                backend_tools.add_tools_to_container(self.toolbar)
                self.statusbar = StatusbarGTK3(self.toolmanager)
                h += add_widget(self.statusbar, False, False, 0)
                h += add_widget(Gtk.HSeparator(), False, False, 0)

        if self.toolbar is not None:
            self.toolbar.show()
            h += add_widget(self.toolbar, False, False, 0)

        self.window.set_default_size(w, h)

        def destroy(*args):
            Gcf.destroy(num)
        self.window.connect("destroy", destroy)
        self.window.connect("delete_event", destroy)
        if matplotlib.is_interactive():
            self.window.show()
            self.canvas.draw_idle()

        self.canvas.grab_focus()
    def __init__(self, canvas, num):
        FigureManagerBase.__init__(self, canvas, num)

        try:
            WMEnable('Matplotlib')
        except:
            # MULTIPLE FIGURES ARE BUGGY!
            pass # If there are multiple figures we only need to enable once
Beispiel #19
0
    def __init__(self, canvas, num):
        if _debug:
            print("FigureManagerGTK.%s" % fn_name())
        FigureManagerBase.__init__(self, canvas, num)

        self.window = gtk.Window()
        self.window.set_title("Figure %d" % num)
        if window_icon:
            try:
                self.window.set_icon_from_file(window_icon)
            except:
                # some versions of gtk throw a glib.GError but not
                # all, so I am not sure how to catch it.  I am unhappy
                # diong a blanket catch here, but an not sure what a
                # better way is - JDH
                verbose.report("Could not load matplotlib icon: %s" % sys.exc_info()[1])

        self.vbox = gtk.VBox()
        self.window.add(self.vbox)
        self.vbox.show()

        self.canvas.show()

        # attach a show method to the figure  for pylab ease of use
        self.canvas.figure.show = lambda *args: self.window.show()

        self.vbox.pack_start(self.canvas, True, True)

        self.toolbar = self._get_toolbar(canvas)

        # calculate size for window
        w = int(self.canvas.figure.bbox.width)
        h = int(self.canvas.figure.bbox.height)

        if self.toolbar is not None:
            self.toolbar.show()
            self.vbox.pack_end(self.toolbar, False, False)

            tb_w, tb_h = self.toolbar.size_request()
            h += tb_h
        self.window.set_default_size(w, h)

        def destroy(*args):
            Gcf.destroy(num)

        self.window.connect("destroy", destroy)
        self.window.connect("delete_event", destroy)
        if matplotlib.is_interactive():
            self.window.show()

        def notify_axes_change(fig):
            "this will be called whenever the current axes is changed"
            if self.toolbar is not None:
                self.toolbar.update()

        self.canvas.figure.add_axobserver(notify_axes_change)

        self.canvas.grab_focus()
    def __init__(self, canvas, num):
        if DEBUG:
            print("FigureManagerQT.%s" % fn_name())
        FigureManagerBase.__init__(self, canvas, num)
        self.canvas = canvas
        self.window = MainWindow()
        self.window.closing.connect(canvas.close_event)
        self.window.closing.connect(self._widgetclosed)

        self.window.setWindowTitle("Figure %d" % num)
        image = os.path.join(matplotlib.rcParams["datapath"], "images", "matplotlib.png")
        self.window.setWindowIcon(QtGui.QIcon(image))

        # Give the keyboard focus to the figure instead of the
        # manager; StrongFocus accepts both tab and click to focus and
        # will enable the canvas to process event w/o clicking.
        # ClickFocus only takes the focus is the window has been
        # clicked
        # on. http://qt-project.org/doc/qt-4.8/qt.html#FocusPolicy-enum or
        # http://doc.qt.digia.com/qt/qt.html#FocusPolicy-enum
        self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.canvas.setFocus()

        self.window._destroying = False

        self.toolbar = self._get_toolbar(self.canvas, self.window)
        if self.toolbar is not None:
            self.window.addToolBar(self.toolbar)
            self.toolbar.message.connect(self._show_message)
            tbs_height = self.toolbar.sizeHint().height()
        else:
            tbs_height = 0

        # add text label to status bar
        self.statusbar_label = QtWidgets.QLabel()
        self.window.statusBar().addWidget(self.statusbar_label)

        # resize the main window so it will display the canvas with the
        # requested size:
        cs = canvas.sizeHint()
        sbs = self.window.statusBar().sizeHint()
        self._status_and_tool_height = tbs_height + sbs.height()
        height = cs.height() + self._status_and_tool_height
        self.window.resize(cs.width(), height)

        self.window.setCentralWidget(self.canvas)

        if matplotlib.is_interactive():
            self.window.show()
            self.canvas.draw_idle()

        def notify_axes_change(fig):
            # This will be called whenever the current axes is changed
            if self.toolbar is not None:
                self.toolbar.update()

        self.canvas.figure.add_axobserver(notify_axes_change)
        self.window.raise_()
    def __init__(self, canvas, num):
        if _debug: print 'FigureManagerGTK3.%s' % fn_name()
        FigureManagerBase.__init__(self, canvas, num)

        self.window = Gtk.Window()
        self.set_window_title("Figure %d" % num)
        try:
            self.window.set_icon_from_file(window_icon)
        except (SystemExit, KeyboardInterrupt):
            # re-raise exit type Exceptions
            raise
        except:
            # some versions of gtk throw a glib.GError but not
            # all, so I am not sure how to catch it.  I am unhappy
            # doing a blanket catch here, but am not sure what a
            # better way is - JDH
            verbose.report('Could not load matplotlib icon: %s' % sys.exc_info()[1])

        self.vbox = Gtk.Box()
        self.vbox.set_property("orientation", Gtk.Orientation.VERTICAL)
        self.window.add(self.vbox)
        self.vbox.show()

        self.canvas.show()

        # attach a show method to the figure  for pylab ease of use
        self.canvas.figure.show = lambda *args: self.window.show()

        self.vbox.pack_start(self.canvas, True, True, 0)

        self.toolbar = self._get_toolbar(canvas)

        # calculate size for window
        w = int (self.canvas.figure.bbox.width)
        h = int (self.canvas.figure.bbox.height)

        if self.toolbar is not None:
            self.toolbar.show()
            self.vbox.pack_end(self.toolbar, False, False, 0)
            size_request = self.toolbar.size_request()
            h += size_request.height

        self.window.set_default_size (w, h)

        def destroy(*args):
            Gcf.destroy(num)
        self.window.connect("destroy", destroy)
        self.window.connect("delete_event", destroy)
        if matplotlib.is_interactive():
            self.window.show()

        def notify_axes_change(fig):
            'this will be called whenever the current axes is changed'
            if self.toolbar is not None: self.toolbar.update()
        self.canvas.figure.add_axobserver(notify_axes_change)

        self.canvas.grab_focus()
Beispiel #22
0
    def __init__( self, canvas, num ):
        if DEBUG: print 'FigureManagerQT.%s' % fn_name()
        FigureManagerBase.__init__( self, canvas, num )
        self.canvas = canvas
        self.window = QtGui.QMainWindow()
        self.window.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        self.window.setWindowTitle("Figure %d" % num)
        image = os.path.join( matplotlib.rcParams['datapath'],'images','matplotlib.png' )
        self.window.setWindowIcon(QtGui.QIcon( image ))

        centralWidget = QtGui.QWidget( self.window )
        self.canvas.setParent( centralWidget )

        # Give the keyboard focus to the figure instead of the manager
        self.canvas.setFocusPolicy( QtCore.Qt.ClickFocus )
        self.canvas.setFocus()

        QtCore.QObject.connect( self.window, QtCore.SIGNAL( 'destroyed()' ),
                            self._widgetclosed )
        self.window._destroying = False

        self.toolbar = self._get_toolbar(self.canvas, centralWidget)

        # Use a vertical layout for the plot and the toolbar.  Set the
        # stretch to all be in the plot so the toolbar doesn't resize.
        layout = QtGui.QVBoxLayout( centralWidget )
        layout.setMargin( 0 )
        layout.addWidget( self.canvas, 1 )
        if self.toolbar:
           layout.addWidget( self.toolbar, 0 )

        self.window.setCentralWidget( centralWidget )

        # Reset the window height so the canvas will be the right
        # size.  This ALMOST works right.  The first issue is that the
        # reported toolbar height does not include the margin (so
        # we add the margin).  The second is that the total width/height
        # is slightly smaller that we actually want.  It seems like
        # the border of the window is being included in the size but
        # AFAIK there is no way to get that size.
        w = self.canvas.width()
        h = self.canvas.height()
        if self.toolbar:
           h += self.toolbar.height() + NavigationToolbar2QT.margin
        self.window.resize( w, h )

        if matplotlib.is_interactive():
            self.window.show()

        # attach a show method to the figure for pylab ease of use
        self.canvas.figure.show = lambda *args: self.window.show()

        def notify_axes_change( fig ):
           # This will be called whenever the current axes is changed
           if self.toolbar != None: self.toolbar.update()
           self.canvas.figure.add_axobserver( notify_axes_change )
Beispiel #23
0
    def __init__( self, canvas, num ):
        if DEBUG: print 'FigureManagerQT.%s' % fn_name()
        FigureManagerBase.__init__( self, canvas, num )
        self.canvas = canvas
        self.window = qt.QMainWindow( None, None, qt.Qt.WDestructiveClose )

        centralWidget = qt.QWidget( self.window )
        self.canvas.reparent( centralWidget, qt.QPoint( 0, 0 ) )
        
        # Give the keyboard focus to the figure instead of the manager
        self.canvas.setFocusPolicy( qt.QWidget.ClickFocus )
        self.canvas.setFocus()
        self.window.setCaption( "Figure %d" % num )

        qt.QObject.connect( self.window, qt.SIGNAL( 'destroyed()' ),
                            self._widgetclosed )
        self.window._destroying = False

        if matplotlib.rcParams['toolbar'] == 'classic':
            print "Classic toolbar is not yet supported"
            #self.toolbar = NavigationToolbarQT( centralWidget, canvas )
            self.toolbar = None
        elif matplotlib.rcParams['toolbar'] == 'toolbar2':
            self.toolbar = NavigationToolbar2QT( centralWidget, canvas )
        else:
            self.toolbar = None

        # Use a vertical layout for the plot and the toolbar.  Set the
        # stretch to all be in the plot so the toolbar doesn't resize.
        layout = qt.QVBoxLayout( centralWidget )
        layout.addWidget( self.canvas, 1 )
        if self.toolbar:
           layout.addWidget( self.toolbar, 0 )

        self.window.setCentralWidget( centralWidget )

        # Reset the window height so the canvas will be the right
        # size.  This ALMOST works right.  The first issue is that the
        # height w/ a toolbar seems to be off by just a little bit (so
        # we add 4 pixels).  The second is that the total width/height
        # is slightly smaller that we actually want.  It seems like
        # the border of the window is being included in the size but
        # AFAIK there is no way to get that size.  
        w = self.canvas.width()
        h = self.canvas.height()
        if self.toolbar:
           h += self.toolbar.height() + 4
        self.window.resize( w, h )
        
        if matplotlib.is_interactive():
            self.window.show()

        def notify_axes_change( fig ):
           # This will be called whenever the current axes is changed
           if self.toolbar != None: self.toolbar.update()
           self.canvas.figure.add_axobserver( notify_axes_change )
Beispiel #24
0
    def __init__(self, canvas, num):
        if DEBUG:
            print("FigureManagerQT.%s" % fn_name())
        FigureManagerBase.__init__(self, canvas, num)
        self.canvas = canvas
        self.window = qt.QMainWindow(None, None, qt.Qt.WDestructiveClose)
        self.window.closeEvent = self._widgetCloseEvent

        centralWidget = qt.QWidget(self.window)
        self.canvas.reparent(centralWidget, qt.QPoint(0, 0))

        # Give the keyboard focus to the figure instead of the manager
        self.canvas.setFocusPolicy(qt.QWidget.ClickFocus)
        self.canvas.setFocus()
        self.window.setCaption("Figure %d" % num)

        self.window._destroying = False

        self.toolbar = self._get_toolbar(self.canvas, centralWidget)

        # Use a vertical layout for the plot and the toolbar.  Set the
        # stretch to all be in the plot so the toolbar doesn't resize.
        self.layout = qt.QVBoxLayout(centralWidget)
        self.layout.addWidget(self.canvas, 1)

        if self.toolbar:
            self.layout.addWidget(self.toolbar, 0)

        self.window.setCentralWidget(centralWidget)

        # Reset the window height so the canvas will be the right
        # size.  This ALMOST works right.  The first issue is that the
        # height w/ a toolbar seems to be off by just a little bit (so
        # we add 4 pixels).  The second is that the total width/height
        # is slightly smaller that we actually want.  It seems like
        # the border of the window is being included in the size but
        # AFAIK there is no way to get that size.
        w = self.canvas.width()
        h = self.canvas.height()
        if self.toolbar:
            h += self.toolbar.height() + 4
        self.window.resize(w, h)

        if matplotlib.is_interactive():
            self.window.show()

        # attach a show method to the figure for pylab ease of use
        self.canvas.figure.show = lambda *args: self.window.show()

        def notify_axes_change(fig):
            # This will be called whenever the current axes is changed
            if self.toolbar != None:
                self.toolbar.update()

        self.canvas.figure.add_axobserver(notify_axes_change)
    def __init__( self, canvas, num ):
        if DEBUG: print('FigureManagerQT.%s' % fn_name())
        FigureManagerBase.__init__( self, canvas, num )
        self.canvas = canvas
        self.window = QtGui.QMainWindow()
        self.window.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        self.window.setWindowTitle("Figure %d" % num)
        image = os.path.join( matplotlib.rcParams['datapath'],'images','matplotlib.png' )
        self.window.setWindowIcon(QtGui.QIcon( image ))

        # Give the keyboard focus to the figure instead of the
        # manager; StrongFocus accepts both tab and click to focus and
        # will enable the canvas to process event w/o clicking.
        # ClickFocus only takes the focus is the window has been
        # clicked
        # on. http://developer.qt.nokia.com/doc/qt-4.8/qt.html#FocusPolicy-enum
        self.canvas.setFocusPolicy( QtCore.Qt.StrongFocus )
        self.canvas.setFocus()

        QtCore.QObject.connect( self.window, QtCore.SIGNAL( 'destroyed()' ),
                            self._widgetclosed )
        self.window._destroying = False

        self.toolbar = self._get_toolbar(self.canvas, self.window)
        if self.toolbar is not None:
            self.window.addToolBar(self.toolbar)
            QtCore.QObject.connect(self.toolbar, QtCore.SIGNAL("message"),
                                   self._show_message)
            tbs_height = self.toolbar.sizeHint().height()
        else:
            tbs_height = 0

        # resize the main window so it will display the canvas with the
        # requested size:
        cs = canvas.sizeHint()
        sbs = self.window.statusBar().sizeHint()
        self._status_and_tool_height = tbs_height+sbs.height()
        height = cs.height() + self._status_and_tool_height
        self.window.resize(cs.width(), height)

        self.window.setCentralWidget(self.canvas)

        if matplotlib.is_interactive():
            self.window.show()

        # attach a show method to the figure for pylab ease of use
        self.canvas.figure.show = lambda *args: self.window.show()

        def notify_axes_change( fig ):
            # This will be called whenever the current axes is changed
            if self.toolbar is not None:
                self.toolbar.update()
        self.canvas.figure.add_axobserver( notify_axes_change )
Beispiel #26
0
    def __init__(self, num):
        """ overwrite the FigureManageAt.__init__ """
        #focused = QtGui.QApplication.focusWidget()
        self.window = MplTabWidget.get_singleton()
        self.canvas, self.widget = self.window.add_tab_canvas(num, self._widgetclosed)
        FigureManagerBase.__init__(self, self.canvas, num)

        # self.window.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        ##image = os.path.join( mpl.rcParams['datapath'],'images','matplotlib.png' )
        ##self.window.setWindowIcon(QtGui.QIcon( image ))

        # Give the keyboard focus to the figure instead of the
        # manager; StrongFocus accepts both tab and click to focus and
        # will enable the canvas to process event w/o clicking.
        # ClickFocus only takes the focus is the window has been
        # clicked
        # on. http://developer.qt.nokia.com/doc/qt-4.8/qt.html#FocusPolicy-enum
        self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
        # self.canvas.setFocus()

        # QtCore.QObject.connect( self.widget, QtCore.SIGNAL( 'destroyed()' ),
        # self._widgetclosed )
        self.window._destroying = False

        self.toolbar = self._get_toolbar(self.canvas, self.widget)
        if self.toolbar is not None:
            self.widget.addToolBar(self.toolbar)
            QtCore.QObject.connect(self.toolbar, QtCore.SIGNAL("message"),
                                   self._show_message)
            tbs_height = self.toolbar.sizeHint().height()
        else:
            tbs_height = 0

        # resize the main window so it will display the canvas with the
        # requested size:
        ##cs = canvas.sizeHint()
        ##sbs = self.window.statusBar().sizeHint()
        ##self._status_and_tool_height = tbs_height+sbs.height()
        ##height = cs.height() + self._status_and_tool_height
        ##self.window.resize(cs.width(), height)
        ##
        # self.window.setCentralWidget(self.canvas)

        if mpl.is_interactive():
            self.window.show()

        def notify_axes_change(fig):
            # This will be called whenever the current axes is changed
            self.window.setCurrentWidget(self.widget)
            if self.toolbar is not None:
                self.toolbar.update()
        self.canvas.figure.add_axobserver(notify_axes_change)
Beispiel #27
0
    def __init__(self, canvas, num):
        FigureManagerBase.__init__(self, canvas, num)

        self.window = gtk.Window()
        self.window.set_wmclass("matplotlib", "Matplotlib")
        self.set_window_title("Figure %d" % num)
        if window_icon:
            try:
                self.window.set_icon_from_file(window_icon)
            except:
                # some versions of gtk throw a glib.GError but not
                # all, so I am not sure how to catch it.  I am unhappy
                # diong a blanket catch here, but an not sure what a
                # better way is - JDH
                _log.info('Could not load matplotlib '
                         'icon: %s', sys.exc_info()[1])

        self.vbox = gtk.VBox()
        self.window.add(self.vbox)
        self.vbox.show()

        self.canvas.show()

        self.vbox.pack_start(self.canvas, True, True)

        self.toolbar = self._get_toolbar(canvas)

        # calculate size for window
        w = int (self.canvas.figure.bbox.width)
        h = int (self.canvas.figure.bbox.height)

        if self.toolbar is not None:
            self.toolbar.show()
            self.vbox.pack_end(self.toolbar, False, False)

            tb_w, tb_h = self.toolbar.size_request()
            h += tb_h
        self.window.set_default_size (w, h)

        def destroy(*args):
            Gcf.destroy(num)
        self.window.connect("destroy", destroy)
        self.window.connect("delete_event", destroy)
        if matplotlib.is_interactive():
            self.window.show()
            self.canvas.draw_idle()

        def notify_axes_change(fig):
            'this will be called whenever the current axes is changed'
            if self.toolbar is not None: self.toolbar.update()
        self.canvas.figure.add_axobserver(notify_axes_change)

        self.canvas.grab_focus()
Beispiel #28
0
    def __init__(self, canvas, num):
        FigureManagerBase.__init__(self, canvas, num)
        title = "Figure %d" % num
        _macosx.FigureManager.__init__(self, canvas, title)
        if rcParams['toolbar'] == 'toolbar2':
            self.toolbar = NavigationToolbar2Mac(canvas)
        else:
            self.toolbar = None
        if self.toolbar is not None:
            self.toolbar.update()

        if matplotlib.is_interactive():
            self.show()
            self.canvas.draw_idle()
    def __init__(self, canvas, num):
        print ("new figure manager")
        FigureManagerBase.__init__(self, canvas, num)
        self.canvas = canvas

        # Give the keyboard focus to the figure instead of the
        # manager; StrongFocus accepts both tab and click to focus and
        # will enable the canvas to process event w/o clicking.
        # ClickFocus only takes the focus if the window has been
        # clicked on. 
        # http://qt-project.org/doc/qt-4.8/qt.html#FocusPolicy-enum or
        # http://doc.qt.digia.com/qt/qt.html#FocusPolicy-enum
        self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.canvas.setFocus()
Beispiel #30
0
    def __init__(self, canvas, num):
        if DEBUG:
            print "FigureManagerGTK.%s" % fn_name()
        FigureManagerBase.__init__(self, canvas, num)

        self.window = gtk.Window()
        self.window.set_title("Figure %d" % num)

        self.vbox = gtk.VBox()
        self.window.add(self.vbox)
        self.vbox.show()

        self.canvas.show()
        self.vbox.pack_start(self.canvas, True, True)

        # must be inited after the window, drawingArea and figure
        # attrs are set
        if matplotlib.rcParams["toolbar"] == "classic":
            self.toolbar = NavigationToolbar(canvas, self.window)
        elif matplotlib.rcParams["toolbar"] == "toolbar2":
            self.toolbar = NavigationToolbar2GTK(canvas, self.window)
        else:
            self.toolbar = None

        # calculate size for window
        w = int(self.canvas.figure.bbox.width())
        h = int(self.canvas.figure.bbox.height())

        if self.toolbar != None:
            self.toolbar.show()
            self.vbox.pack_end(self.toolbar, False, False)

            tb_w, tb_h = self.toolbar.size_request()
            h += tb_h
        self.window.set_default_size(w, h)

        def destroy(*args):
            Gcf.destroy(num)

        self.window.connect("destroy", destroy)
        self.window.connect("delete_event", destroy)
        if matplotlib.is_interactive():
            self.window.show()

        def notify_axes_change(fig):
            "this will be called whenever the current axes is changed"
            if self.toolbar != None:
                self.toolbar.update()

        self.canvas.figure.add_axobserver(notify_axes_change)
Beispiel #31
0
    def __init__(self, canvas, num):
        if DEBUG: print 'FigureManagerQT.%s' % fn_name()
        FigureManagerBase.__init__(self, canvas, num)
        self.canvas = canvas
        self.window = QtGui.QMainWindow()
        self.window.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        self.window.setWindowTitle("Figure %d" % num)
        image = os.path.join(matplotlib.rcParams['datapath'], 'images',
                             'matplotlib.png')
        self.window.setWindowIcon(QtGui.QIcon(image))

        # Give the keyboard focus to the figure instead of the manager
        self.canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
        self.canvas.setFocus()

        QtCore.QObject.connect(self.window, QtCore.SIGNAL('destroyed()'),
                               self._widgetclosed)
        self.window._destroying = False

        self.toolbar = self._get_toolbar(self.canvas, self.window)
        self.window.addToolBar(self.toolbar)
        QtCore.QObject.connect(self.toolbar, QtCore.SIGNAL("message"),
                               self.window.statusBar().showMessage)

        self.window.setCentralWidget(self.canvas)

        if matplotlib.is_interactive():
            self.window.show()

        # attach a show method to the figure for pylab ease of use
        self.canvas.figure.show = lambda *args: self.window.show()

        def notify_axes_change(fig):
            # This will be called whenever the current axes is changed
            if self.toolbar != None: self.toolbar.update()

        self.canvas.figure.add_axobserver(notify_axes_change)
Beispiel #32
0
    def __init__(self, *args, **kwargs):
        # pull non-standard keyword arguments
        auto_refresh = kwargs.pop('auto_refresh', False)

        # generated figure, with associated interactivity from pyplot
        super(Plot, self).__init__(*args, **kwargs)
        backend_mod, _, draw_if_interactive, _ = backends.pylab_setup()
        try:
            manager = backend_mod.new_figure_manager_given_figure(1, self)
        except AttributeError:
            canvas = backend_mod.FigureCanvas(self)
            manager = FigureManagerBase(canvas, 1)
        cid = manager.canvas.mpl_connect(
            'button_press_event',
            lambda ev: _pylab_helpers.Gcf.set_active(manager))
        manager._cidgcf = cid
        _pylab_helpers.Gcf.set_active(manager)
        draw_if_interactive()

        # finalise
        self.set_auto_refresh(auto_refresh)
        self.colorbars = []
        self._coloraxes = []
Beispiel #33
0
    def __init__(self, canvas, num, window):
        FigureManagerBase.__init__(self, canvas, num)
        self.window = window
        self.window.withdraw()
        self.set_window_title("Figure %d" % num)
        self.canvas = canvas
        # If using toolmanager it has to be present when initializing the
        # toolbar
        self.toolmanager = self._get_toolmanager()
        # packing toolbar first, because if space is getting low, last packed
        # widget is getting shrunk first (-> the canvas)
        self.toolbar = self._get_toolbar()
        self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)

        self.statusbar = None

        if self.toolmanager:
            backend_tools.add_tools_to_manager(self.toolmanager)
            if self.toolbar:
                backend_tools.add_tools_to_container(self.toolbar)
                self.statusbar = StatusbarTk(self.window, self.toolmanager)

        self._shown = False
Beispiel #34
0
    def __init__(self, canvas, num, window):
        FigureManagerBase.__init__(self, canvas, num)
        self.window = window
        self.window.withdraw()
        self.set_window_title("Figure %d" % num)
        self.canvas = canvas
        self._num =  num
        _, _, w, h = canvas.figure.bbox.bounds
        w, h = int(w), int(h)
        self.window.minsize(int(w*3/4),int(h*3/4))
        if matplotlib.rcParams['toolbar']=='toolbar2':
            self.toolbar = NavigationToolbar2TkAgg( canvas, self.window )
        else:
            self.toolbar = None
        if self.toolbar is not None:
            self.toolbar.update()
        self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        self._shown = False

        def notify_axes_change(fig):
            'this will be called whenever the current axes is changed'
            if self.toolbar != None: self.toolbar.update()
        self.canvas.figure.add_axobserver(notify_axes_change)
Beispiel #35
0
 def __init__(self, canvas, num, window):
     FigureManagerBase.__init__(self, canvas, num)   
     #Fltk container window
     t1,t2,w,h = canvas.figure.bbox.get_bounds()
     w, h = int(w), int(h)
     self.window = window
     self.window.size(w,h+30)
     self.window_title="Figure %d" % num
     self.window.label(self.window_title)
     self.window.size_range(350,200)
     self.window.callback(destroy_figure,self)
     self.canvas = canvas
     self._num =  num
     if matplotlib.rcParams['toolbar']=='classic':
         self.toolbar = NavigationToolbar( canvas, self )
     elif matplotlib.rcParams['toolbar']=='toolbar2':
         self.toolbar = NavigationToolbar2FltkAgg( canvas, self )
     else:
         self.toolbar = None
     self.window.add_resizable(canvas.widget())
     if self.toolbar:
         self.window.add(self.toolbar.widget())
         self.toolbar.update()
     self.window.show()
Beispiel #36
0
    def __init__(self, canvas, num):
        FigureManagerBase.__init__(self, canvas, num)
        title = "Figure %d" % num
        _macosx.FigureManager.__init__(self, canvas, title)
        if rcParams['toolbar'] == 'classic':
            self.toolbar = NavigationToolbarMac(canvas)
        elif rcParams['toolbar'] == 'toolbar2':
            self.toolbar = NavigationToolbar2Mac(canvas)
        else:
            self.toolbar = None
        if self.toolbar is not None:
            self.toolbar.update()

        def notify_axes_change(fig):
            'this will be called whenever the current axes is changed'
            if self.toolbar != None: self.toolbar.update()

        self.canvas.figure.add_axobserver(notify_axes_change)

        # This is ugly, but this is what tkagg and gtk are doing.
        # It is needed to get ginput() working.
        self.canvas.figure.show = lambda *args: self.show()
        if matplotlib.is_interactive():
            self.show()
Beispiel #37
0
    def __init__(self, rows=1, cols=0, title='', size=None, buffering=False):
        """
        Create a new instance of the ASAPlot plotting class.

        If rows < 1 then a separate call to set_panels() is required to define
        the panel layout; refer to the doctext for set_panels().
        """
        v = vars()
        del v['self']
        asaplotbase.__init__(self, **v)
        _pylab_helpers.Gcf.destroy(0)
        self.window = None
        self.canvas = FigureCanvasAgg(self.figure)
        self.figmgr = FigureManagerBase(self.canvas, 0)
        # This seems necessary when using Gcf, as this is done in
        # pyplot.figure. Otherwise this can cause atexit errors at cleanup

        self.figmgr._cidgcf = None
        _pylab_helpers.Gcf.figs[self.figmgr.num] = self.figmgr
Beispiel #38
0
def new_figure_manager(num, *args, **kwargs):
    """
    Create a new figure manager instance
    """

    global remote_canvas
    global singleton_lock

    logger.debug("mpl_multiprocess_backend.new_figure_manager()")

    # get the pipe connection
    parent_conn = kwargs.pop('parent_conn')

    # and the threading.Event for turning events on and off
    process_events = kwargs.pop('process_events')

    # and the plot lock
    plot_lock = kwargs.pop('plot_lock')

    # make a new figure
    FigureClass = kwargs.pop('FigureClass', Figure)
    new_fig = FigureClass(*args, **kwargs)

    with singleton_lock:

        # the canvas is a singleton.
        if not remote_canvas:
            remote_canvas = FigureCanvasAggRemote(parent_conn, process_events,
                                                  plot_lock, new_fig)

        else:
            old_fig = remote_canvas.figure
            new_fig.set_size_inches(old_fig.get_figwidth(),
                                    old_fig.get_figheight())
            remote_canvas.figure = new_fig

    new_fig.set_canvas(remote_canvas)

    # close the current figure (to keep pyplot happy)
    matplotlib.pyplot.close()

    return FigureManagerBase(remote_canvas, num)
Beispiel #39
0
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, style=wx.BORDER_SUNKEN)

        self.sliceFigure = Figure(frameon=True, figsize=(2, 3))
        self.sliceFigure.set_facecolor('.82')
        self.sliceCanvas = FigureCanvas(self, -1, self.sliceFigure)
        self.sliceCanvas.SetAutoLayout(False)

        self.box = Toolbar(self.sliceCanvas)
        self.box.Hide()
        self.box.zoom()

        self.fm = FigureManagerBase(self.sliceCanvas, 1)
        _pylab_helpers.Gcf.set_active(self.fm)

        self.sliceAxis = self.sliceFigure.add_axes([0.1, 0.2, 0.8, 0.7])

        sliceSizer = wx.BoxSizer(wx.VERTICAL)
        sliceSizer.Add(self.sliceCanvas,
                       1,
                       wx.EXPAND | wx.RIGHT | wx.LEFT,
                       border=1)
        self.SetSizer(sliceSizer)
        return
Beispiel #40
0
    def __init__(self, canvas, num):
        FigureManagerBase.__init__(self, canvas, num)
        self.canvas = canvas
        self.window = MainWindow()
        self.window.closing.connect(canvas.close_event)
        self.window.closing.connect(self._widgetclosed)

        self.window.setWindowTitle("Figure %d" % num)
        image = os.path.join(matplotlib.rcParams['datapath'], 'images',
                             'matplotlib.svg')
        self.window.setWindowIcon(QtGui.QIcon(image))

        # Give the keyboard focus to the figure instead of the
        # manager; StrongFocus accepts both tab and click to focus and
        # will enable the canvas to process event w/o clicking.
        # ClickFocus only takes the focus is the window has been
        # clicked
        # on. http://qt-project.org/doc/qt-4.8/qt.html#FocusPolicy-enum or
        # http://doc.qt.digia.com/qt/qt.html#FocusPolicy-enum
        self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.canvas.setFocus()

        self.window._destroying = False

        self.toolmanager = self._get_toolmanager()
        self.toolbar = self._get_toolbar(self.canvas, self.window)
        self.statusbar = None

        if self.toolmanager:
            backend_tools.add_tools_to_manager(self.toolmanager)
            if self.toolbar:
                backend_tools.add_tools_to_container(self.toolbar)
                self.statusbar = StatusbarQt(self.window, self.toolmanager)

        if self.toolbar is not None:
            self.window.addToolBar(self.toolbar)
            if not self.toolmanager:
                # add text label to status bar
                statusbar_label = QtWidgets.QLabel()
                self.window.statusBar().addWidget(statusbar_label)
                self.toolbar.message.connect(statusbar_label.setText)
            tbs_height = self.toolbar.sizeHint().height()
        else:
            tbs_height = 0

        # resize the main window so it will display the canvas with the
        # requested size:
        cs = canvas.sizeHint()
        sbs = self.window.statusBar().sizeHint()
        self._status_and_tool_height = tbs_height + sbs.height()
        height = cs.height() + self._status_and_tool_height
        self.window.resize(cs.width(), height)

        self.window.setCentralWidget(self.canvas)

        if matplotlib.is_interactive():
            self.window.show()
            self.canvas.draw_idle()

        def notify_axes_change(fig):
            # This will be called whenever the current axes is changed
            if self.toolbar is not None:
                self.toolbar.update()

        self.canvas.figure.add_axobserver(notify_axes_change)
        self.window.raise_()
Beispiel #41
0
 def __init__(self, canvas):
     self.fm = FigureManagerBase(canvas, -1)
Beispiel #42
0
 def __getattribute__(self, *args, **kwargs):
     return FigureManagerBase.__getattribute__(self, *args, **kwargs)
Beispiel #43
0
 def __init__(self, canvas, num):
     FigureManagerBase.__init__(self, canvas, num)
     self.canvas = canvas
     self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
Beispiel #44
0
    def __init__(self,frame,id):
        wx.Panel.__init__(self,frame,id,style = wx.BORDER_RAISED)

        self.v = frame.v
        self.extent = frame.extent

        self.step = frame.step
        self.n = frame.n

        z_layer = 0
        self.halfstep = self.step[2]/2.0

        self.figure = Figure(frameon = True)

        self.figure.set_facecolor('.82')
        self.canvas = FigureCanvas(self, -1, self.figure)

        fm = FigureManagerBase(self.canvas, 0)
        _pylab_helpers.Gcf.set_active(fm)
        self.ax1 = self.figure.add_axes([0.1,0.1,0.7,0.8])

        plotExtent = ([self.extent[0,0],self.extent[0,1],
                       self.extent[1,0],self.extent[1,1]])

        self.im = self.ax1.imshow(self.v[:,:,z_layer].T,
                                  origin='lower',
                                  interpolation = 'nearest',
                                  extent = plotExtent,
                                  vmin = amin(self.v),
                                  vmax = amax(self.v))

        self.ax1.set_title('Z Slice = ' +
                        str(z_layer *self.step[2] + self.halfstep) +
                        ' Ang' ,size = 'xx-large')

        self.figure.colorbar(self.im,format = '%.2e')

        mpl_toolbar = Toolbar(self.canvas)
        mpl_toolbar.Realize()

        self.zselect = wx.Slider(self,-1,size = [300,40],minValue = int(0),
                                 maxValue = int(self.n[2]-1),
                                 style = wx.SL_AUTOTICKS)

        print self.extent[2,1]
        print self.halfstep
        print 'TEST', str(self.extent[2,1] - self.halfstep)
        self.label = wx.StaticText(self,-1,'Select Z layer: ')

        self.minVal = wx.StaticText(self,-1, '0.0')

        self.maxVal = wx.StaticText(self,-1, str(self.extent[2,1]
                                                 - self.halfstep))


        BotSize = wx.BoxSizer(wx.HORIZONTAL)
        vertSize = wx.BoxSizer(wx.VERTICAL)

        BotSize.Add(self.label,0,wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.minVal,0,wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.zselect,0,wx.TOP|wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.maxVal,0,wx.LEFT|wx.RIGHT,border = 5)

        vertSize.Add(self.canvas,-1,wx.EXPAND|wx.LEFT|wx.RIGHT)
        vertSize.Add(mpl_toolbar,0)
        vertSize.Add(BotSize,0,wx.ALL, border = 10)

        self.SetSizer(vertSize)

        self.Fit()
        self.zselect.Bind(wx.EVT_SCROLL,self.newUnitZ)
Beispiel #45
0
    def __init__(self, canvas, num):
        assert QAppThreadCall.is_qapp_thread(
        ), "FigureManagerWorkbench cannot be created outside of the QApplication thread"
        QObject.__init__(self)

        parent, flags = get_window_config()
        self.window = FigureWindow(canvas, parent=parent, window_flags=flags)
        self.window.activated.connect(self._window_activated)
        self.window.closing.connect(canvas.close_event)
        self.window.closing.connect(self.destroy)
        self.window.visibility_changed.connect(self.fig_visibility_changed)

        self.window.setWindowTitle("Figure %d" % num)
        canvas.figure.set_label("Figure %d" % num)

        FigureManagerBase.__init__(self, canvas, num)
        # Give the keyboard focus to the figure instead of the
        # manager; StrongFocus accepts both tab and click to focus and
        # will enable the canvas to process event w/o clicking.
        # ClickFocus only takes the focus is the window has been
        # clicked
        # on. http://qt-project.org/doc/qt-4.8/qt.html#FocusPolicy-enum or
        # http://doc.qt.digia.com/qt/qt.html#FocusPolicy-enum
        canvas.setFocusPolicy(Qt.StrongFocus)
        canvas.setFocus()

        self.window._destroying = False

        # add text label to status bar
        self.statusbar_label = QLabel()
        self.window.statusBar().addWidget(self.statusbar_label)

        self.plot_options_dialog = None
        self.toolbar = self._get_toolbar(canvas, self.window)
        if self.toolbar is not None:
            self.window.addToolBar(self.toolbar)
            self.toolbar.message.connect(self.statusbar_label.setText)
            self.toolbar.sig_grid_toggle_triggered.connect(self.grid_toggle)
            self.toolbar.sig_toggle_fit_triggered.connect(self.fit_toggle)
            self.toolbar.sig_toggle_superplot_triggered.connect(
                self.superplot_toggle)
            self.toolbar.sig_copy_to_clipboard_triggered.connect(
                self.copy_to_clipboard)
            self.toolbar.sig_plot_options_triggered.connect(
                self.launch_plot_options)
            self.toolbar.sig_plot_help_triggered.connect(self.launch_plot_help)
            self.toolbar.sig_generate_plot_script_clipboard_triggered.connect(
                self.generate_plot_script_clipboard)
            self.toolbar.sig_generate_plot_script_file_triggered.connect(
                self.generate_plot_script_file)
            self.toolbar.sig_home_clicked.connect(
                self.set_figure_zoom_to_display_all)
            self.toolbar.sig_waterfall_reverse_order_triggered.connect(
                self.waterfall_reverse_line_order)
            self.toolbar.sig_waterfall_offset_amount_triggered.connect(
                self.launch_waterfall_offset_options)
            self.toolbar.sig_waterfall_fill_area_triggered.connect(
                self.launch_waterfall_fill_area_options)
            self.toolbar.sig_waterfall_conversion.connect(
                self.update_toolbar_waterfall_plot)
            self.toolbar.sig_change_line_collection_colour_triggered.connect(
                self.change_line_collection_colour)
            self.toolbar.setFloatable(False)
            tbs_height = self.toolbar.sizeHint().height()
        else:
            tbs_height = 0

        # resize the main window so it will display the canvas with the
        # requested size:
        cs = canvas.sizeHint()
        sbs = self.window.statusBar().sizeHint()
        self._status_and_tool_height = tbs_height + sbs.height()
        height = cs.height() + self._status_and_tool_height
        self.window.resize(cs.width(), height)

        self.fit_browser = FitPropertyBrowser(
            canvas, ToolbarStateManager(self.toolbar))
        self.fit_browser.closing.connect(self.handle_fit_browser_close)
        self.window.setCentralWidget(canvas)
        self.window.addDockWidget(Qt.LeftDockWidgetArea, self.fit_browser)

        self.superplot = None

        # Need this line to stop the bug where the dock window snaps back to its original size after resizing.
        # 0 argument is arbitrary and has no effect on fit widget size
        # This is a qt bug reported at (https://bugreports.qt.io/browse/QTBUG-65592)
        if QT_VERSION >= LooseVersion("5.6"):
            self.window.resizeDocks([self.fit_browser], [1], Qt.Horizontal)
        self.fit_browser.hide()

        if matplotlib.is_interactive():
            self.window.show()
            canvas.draw_idle()

        def notify_axes_change(fig):
            # This will be called whenever the current axes is changed
            if self.toolbar is not None:
                self.toolbar.update()

        canvas.figure.add_axobserver(notify_axes_change)

        # Register canvas observers
        self._fig_interaction = FigureInteraction(self)
        self._ads_observer = FigureManagerADSObserver(self)

        self.window.raise_()
Beispiel #46
0
 def function_get_fig_manager(self):
     l_manager = FigureManagerBase()
Beispiel #47
0
    def __init__(self,frame,id):
        wx.Panel.__init__(self,frame,id,style = wx.BORDER_RAISED)

        z_layer = 0
        self.omf = frame.omf
        self.halfstep = (float(self.omf.parameters['zstepsize'])/2.0)*1.0e10

        self.figure = Figure(frameon = True)
        self.figure.set_facecolor('.82')

        self.canvas = FigureCanvas(self, -1, self.figure)

        fm = FigureManagerBase(self.canvas, 0)
        _pylab_helpers.Gcf.set_active(fm)

        self.wheel_cmap = LinearSegmentedColormap.from_list('wheel_rgby',
                               ['red', 'green', 'blue', 'yellow', 'red'])

        mpl_toolbar = Toolbar(self.canvas)
        mpl_toolbar.Realize()

        x,y = indices((100,100), dtype = float) - 50.
        wheel_angle = arctan2(x,y)

        self.ax1 = self.figure.add_axes([0.1,0.1,0.7,0.8])

        self.angle = ma.array(arctan2(-self.omf.my[:,:,z_layer],
                                 self.omf.mx[:,:,z_layer]),
                                  mask=(self.omf.M[:,:,z_layer] == 0.0))
        self.angle[self.angle==360] = 0.0
        print ma.getdata(self.angle)
        xmax = (float(self.omf.parameters['xnodes']) *
                float(self.omf.parameters['xstepsize']) * 1.0e10)

        ymax = (float(self.omf.parameters['ynodes']) *
                float(self.omf.parameters['ystepsize']) * 1.0e10)
        
        self.extent = [0., xmax, 0., ymax]

        self.im = self.ax1.imshow(self.angle.T, origin='lower',
                                  interpolation = 'nearest',
                                  extent = self.extent,
                                  cmap = self.wheel_cmap,
                                  vmin = -pi, vmax = pi)


        self.ax1.set_title('Z Slice = ' +
               str(z_layer*float(self.omf.parameters['zstepsize'])* 1.0e10
                   + self.halfstep) +' Ang' ,size = 'xx-large')

        self.ax1.set_xlabel('$x (\AA)$', size = 'x-large')
        self.ax1.set_ylabel('$y (\AA)$', size = 'x-large')


        self.ax1w = self.figure.add_axes([0.75,0.4,0.3,0.2], polar=True)

        self.ax1w.yaxis.set_visible(False)

        self.ax1w.imshow(wheel_angle, cmap=self.wheel_cmap,
                         extent=[0,2*pi,0,pi])

        self.ax1w.set_title('M direction\n(in-plane)')


        self.zselect = wx.Slider(self,-1,size = [300,40],minValue = int(0),
                                 maxValue = int(self.omf.dims[2]-1),
                                 style = wx.SL_AUTOTICKS)


        self.datavalue = wx.StatusBar(self,-1)
        self.datavalue.SetStatusText('Angle Value: ')
        self.label = wx.StaticText(self,-1,'Select Z layer: ')

        self.minVal = wx.StaticText(self,-1, '0.0')

        self.maxVal = wx.StaticText(self,-1, str(self.omf.dims[2]*
                         (float(self.omf.parameters['zstepsize'])* 1.0e10)
                         -self.halfstep))

        #Sizer Creation
        toolSize = wx.BoxSizer(wx.HORIZONTAL)
        BotSize = wx.BoxSizer(wx.HORIZONTAL)
        vertSize = wx.BoxSizer(wx.VERTICAL)

        BotSize.Add(self.label,0,wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.minVal,0,wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.zselect,0,wx.TOP|wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.maxVal,0,wx.LEFT|wx.RIGHT,border = 5)

        toolSize.Add(mpl_toolbar,0,wx.RIGHT,border = 20)
        toolSize.Add(self.datavalue,0,wx.LEFT|wx.RIGHT|wx.TOP,border = 20)

        vertSize.Add(self.canvas,-1,wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
        vertSize.Add(toolSize,0)
        vertSize.Add(BotSize,0,wx.ALL, border = 10)

        self.SetSizer(vertSize)

        self.Fit()


        self.zselect.Bind(wx.EVT_SCROLL,self.newMomentZ)
        self.canvas.mpl_connect('motion_notify_event',self.onMouseOver)
Beispiel #48
0
 def add_axes(self, rect, **kwargs):
     if DEBUG: print 'FigureManagerGTK.%s' % fn_name()
     a = FigureManagerBase.add_axes(self, rect, **kwargs)
     if self.toolbar != None: self.toolbar.update()
     return a
Beispiel #49
0
    def __init__(self, canvas, num):
        QObject.__init__(self)
        FigureManagerBase.__init__(self, canvas, num)
        # Patch show/destroy to be thread aware
        self._destroy_orig = self.destroy
        self.destroy = QAppThreadCall(self._destroy_orig)
        self._show_orig = self.show
        self.show = QAppThreadCall(self._show_orig)
        self._window_activated_orig = self._window_activated
        self._window_activated = QAppThreadCall(self._window_activated_orig)
        self.set_window_title_orig = self.set_window_title
        self.set_window_title = QAppThreadCall(self.set_window_title_orig)
        self.fig_visibility_changed_orig = self.fig_visibility_changed
        self.fig_visibility_changed = QAppThreadCall(
            self.fig_visibility_changed_orig)

        self.window = FigureWindow(canvas)
        self.window.activated.connect(self._window_activated)
        self.window.closing.connect(canvas.close_event)
        self.window.closing.connect(self.destroy)
        self.window.visibility_changed.connect(self.fig_visibility_changed)

        self.window.setWindowTitle("Figure %d" % num)
        canvas.figure.set_label("Figure %d" % num)

        # Give the keyboard focus to the figure instead of the
        # manager; StrongFocus accepts both tab and click to focus and
        # will enable the canvas to process event w/o clicking.
        # ClickFocus only takes the focus is the window has been
        # clicked
        # on. http://qt-project.org/doc/qt-4.8/qt.html#FocusPolicy-enum or
        # http://doc.qt.digia.com/qt/qt.html#FocusPolicy-enum
        canvas.setFocusPolicy(Qt.StrongFocus)
        canvas.setFocus()

        self.window._destroying = False

        # add text label to status bar
        self.statusbar_label = QLabel()
        self.window.statusBar().addWidget(self.statusbar_label)

        self.plot_options_dialog = None
        self.toolbar = self._get_toolbar(canvas, self.window)
        if self.toolbar is not None:
            self.window.addToolBar(self.toolbar)
            self.toolbar.message.connect(self.statusbar_label.setText)
            self.toolbar.sig_grid_toggle_triggered.connect(self.grid_toggle)
            self.toolbar.sig_toggle_fit_triggered.connect(self.fit_toggle)
            self.toolbar.sig_plot_options_triggered.connect(
                self.launch_plot_options)
            self.toolbar.sig_generate_plot_script_clipboard_triggered.connect(
                self.generate_plot_script_clipboard)
            self.toolbar.sig_generate_plot_script_file_triggered.connect(
                self.generate_plot_script_file)
            self.toolbar.sig_home_clicked.connect(
                self.set_figure_zoom_to_display_all)
            self.toolbar.sig_waterfall_reverse_order_triggered.connect(
                self.waterfall_reverse_line_order)
            self.toolbar.sig_waterfall_offset_amount_triggered.connect(
                self.launch_waterfall_offset_options)
            self.toolbar.sig_waterfall_fill_area_triggered.connect(
                self.launch_waterfall_fill_area_options)
            self.toolbar.sig_waterfall_conversion.connect(
                self.update_toolbar_waterfall_plot)
            self.toolbar.setFloatable(False)
            tbs_height = self.toolbar.sizeHint().height()
        else:
            tbs_height = 0

        # resize the main window so it will display the canvas with the
        # requested size:
        cs = canvas.sizeHint()
        sbs = self.window.statusBar().sizeHint()
        self._status_and_tool_height = tbs_height + sbs.height()
        height = cs.height() + self._status_and_tool_height
        self.window.resize(cs.width(), height)

        self.fit_browser = FitPropertyBrowser(
            canvas, ToolbarStateManager(self.toolbar))
        self.fit_browser.closing.connect(self.handle_fit_browser_close)
        self.window.setCentralWidget(canvas)
        self.window.addDockWidget(Qt.LeftDockWidgetArea, self.fit_browser)
        self.fit_browser.hide()

        if matplotlib.is_interactive():
            self.window.show()
            canvas.draw_idle()

        def notify_axes_change(fig):
            # This will be called whenever the current axes is changed
            if self.toolbar is not None:
                self.toolbar.update()

        canvas.figure.add_axobserver(notify_axes_change)

        # Register canvas observers
        self._fig_interaction = FigureInteraction(self)
        self._ads_observer = FigureManagerADSObserver(self)

        self.window.raise_()
Beispiel #50
0
    def __init__(self, canvas, num):
        self.canvas = canvas
        self.toolbar = NavigationToolbar2SWT(canvas)
        self.canvas.toolbar = self.toolbar

        FigureManagerBase.__init__(self, canvas, num)
Beispiel #51
0
 def __init__(self, canvas, num):
     FigureManagerBase.__init__(self, canvas, num)
Beispiel #52
0
 def __init__(self, canvas):
     # delay loading pylab until matplotlib.use() is called
     from matplotlib.backend_bases import FigureManagerBase
     self.fm = FigureManagerBase(canvas, -1)
Beispiel #53
0
 def __init__(self, canvas, num):
     FigureManagerBase.__init__(self, canvas, num)
     self.fig_id = "figure_{0}".format(uuid.uuid4().hex)
     self._shown = False
Beispiel #54
0
 def set_current_axes(self, a):
     if a not in self.axes.values():
         error_msg_Fltk('Axes is not in current figure')
     FigureManagerBase.set_current_axes(self, a)
Beispiel #55
0
    def __init__(self, canvas, num):
        FigureManagerBase.__init__(self, canvas, num)

        self.window = Gtk.Window()
        self.window.set_wmclass("matplotlib", "Matplotlib")
        self.set_window_title("Figure %d" % num)
        try:
            self.window.set_icon_from_file(window_icon)
        except (SystemExit, KeyboardInterrupt):
            # re-raise exit type Exceptions
            raise
        except:
            # some versions of gtk throw a glib.GError but not
            # all, so I am not sure how to catch it.  I am unhappy
            # doing a blanket catch here, but am not sure what a
            # better way is - JDH
            _log.info('Could not load matplotlib icon: %s', sys.exc_info()[1])

        self.vbox = Gtk.Box()
        self.vbox.set_property("orientation", Gtk.Orientation.VERTICAL)
        self.window.add(self.vbox)
        self.vbox.show()

        self.canvas.show()

        self.vbox.pack_start(self.canvas, True, True, 0)
        # calculate size for window
        w = int(self.canvas.figure.bbox.width)
        h = int(self.canvas.figure.bbox.height)

        self.toolmanager = self._get_toolmanager()
        self.toolbar = self._get_toolbar()
        self.statusbar = None

        def add_widget(child, expand, fill, padding):
            child.show()
            self.vbox.pack_end(child, False, False, 0)
            size_request = child.size_request()
            return size_request.height

        if self.toolmanager:
            backend_tools.add_tools_to_manager(self.toolmanager)
            if self.toolbar:
                backend_tools.add_tools_to_container(self.toolbar)
                self.statusbar = StatusbarGTK3(self.toolmanager)
                h += add_widget(self.statusbar, False, False, 0)
                h += add_widget(Gtk.HSeparator(), False, False, 0)

        if self.toolbar is not None:
            self.toolbar.show()
            h += add_widget(self.toolbar, False, False, 0)

        self.window.set_default_size(w, h)

        def destroy(*args):
            Gcf.destroy(num)

        self.window.connect("destroy", destroy)
        self.window.connect("delete_event", destroy)
        if matplotlib.is_interactive():
            self.window.show()
            self.canvas.draw_idle()

        def notify_axes_change(fig):
            'this will be called whenever the current axes is changed'
            if self.toolmanager is not None:
                pass
            elif self.toolbar is not None:
                self.toolbar.update()

        self.canvas.figure.add_axobserver(notify_axes_change)

        self.canvas.grab_focus()
Beispiel #56
0
    def __init__(self, canvas, num):
        QObject.__init__(self)
        FigureManagerBase.__init__(self, canvas, num)
        # Patch show/destroy to be thread aware
        self._destroy_orig = self.destroy
        self.destroy = QAppThreadCall(self._destroy_orig)
        self._show_orig = self.show
        self.show = QAppThreadCall(self._show_orig)
        self._window_activated_orig = self._window_activated
        self._window_activated = QAppThreadCall(self._window_activated_orig)
        self._widgetclosed_orig = self._widgetclosed
        self._widgetclosed = QAppThreadCall(self._widgetclosed_orig)
        self.set_window_title_orig = self.set_window_title
        self.set_window_title = QAppThreadCall(self.set_window_title_orig)
        self.fig_visibility_changed_orig = self.fig_visibility_changed
        self.fig_visibility_changed = QAppThreadCall(
            self.fig_visibility_changed_orig)

        self.window = FigureWindow(canvas)
        self.window.activated.connect(self._window_activated)
        self.window.closing.connect(canvas.close_event)
        self.window.closing.connect(self._widgetclosed)
        self.window.visibility_changed.connect(self.fig_visibility_changed)

        self.window.setWindowTitle("Figure %d" % num)
        canvas.figure.set_label("Figure %d" % num)

        # Give the keyboard focus to the figure instead of the
        # manager; StrongFocus accepts both tab and click to focus and
        # will enable the canvas to process event w/o clicking.
        # ClickFocus only takes the focus is the window has been
        # clicked
        # on. http://qt-project.org/doc/qt-4.8/qt.html#FocusPolicy-enum or
        # http://doc.qt.digia.com/qt/qt.html#FocusPolicy-enum
        canvas.setFocusPolicy(Qt.StrongFocus)
        canvas.setFocus()

        self.window._destroying = False

        # add text label to status bar
        self.statusbar_label = QLabel()
        self.window.statusBar().addWidget(self.statusbar_label)

        self.toolbar = self._get_toolbar(canvas, self.window)
        if self.toolbar is not None:
            self.window.addToolBar(self.toolbar)
            self.toolbar.message.connect(self.statusbar_label.setText)
            self.toolbar.sig_grid_toggle_triggered.connect(self.grid_toggle)
            tbs_height = self.toolbar.sizeHint().height()
        else:
            tbs_height = 0

        # resize the main window so it will display the canvas with the
        # requested size:
        cs = canvas.sizeHint()
        sbs = self.window.statusBar().sizeHint()
        self._status_and_tool_height = tbs_height + sbs.height()
        height = cs.height() + self._status_and_tool_height
        self.window.resize(cs.width(), height)

        self.window.setCentralWidget(canvas)

        if matplotlib.is_interactive():
            self.window.show()
            canvas.draw_idle()

        def notify_axes_change(fig):
            # This will be called whenever the current axes is changed
            if self.toolbar is not None:
                self.toolbar.update()

        canvas.figure.add_axobserver(notify_axes_change)

        # Register canvas observers
        self._cids = []
        self._cids.append(
            self.canvas.mpl_connect('button_press_event',
                                    self.on_button_press))

        self.window.raise_()
Beispiel #57
0
 def __init__(self, *args):
     FigureManagerBase.__init__(self, *args)
Beispiel #58
0
 def add_subplot(self, *args, **kwargs):
     a = FigureManagerBase.add_subplot(self, *args, **kwargs)
     self.toolbar.update()
     return a
Beispiel #59
0
 def add_axes(self, rect, **kwargs):
     a = FigureManagerBase.add_axes(self, rect, **kwargs)
     self.toolbar.update()
     return a
Beispiel #60
0
    def __init__(self,parent,id):
        wx.Panel.__init__(self,parent,id,style=wx.BORDER_SUNKEN)

        self.scale_collection = array([])
        self.real_data = flipud(parent.data.T)
        self.parent = parent

        self.raw_data = flipud(parent.model.T)
        self.scaled_data = copy(self.raw_data)
        self.plot_extent = parent.plot_extent

        lower_lim = amin(self.scaled_data[nonzero(self.scaled_data.real)])

        finite_real = self.real_data[isfinite(self.real_data)]
        finite_real = finite_real[nonzero(finite_real)]

        #Hack
        #self.vmin = amin(log(finite_real.real))
        self.vmax = amax(log(finite_real.real))
        self.vmin = self.vmax - 12
        self.figure = Figure()
        self.axes = self.figure.add_subplot(211)
        self.canvas = FigureCanvas(self, -1, self.figure)

        fm = FigureManagerBase(self.canvas, 0)
        _pylab_helpers.Gcf.set_active(fm)

        # Instantiate the matplotlib navigation toolbar and explicitly show it.
        mpl_toolbar = Toolbar(self.canvas)
        mpl_toolbar.Realize()

        self.myImage = self.showImage(log(abs(self.scaled_data)),self.axes)
        self.modelColor = self.figure.colorbar(self.myImage)

        self.dataaxes = self.figure.add_subplot(212)
        self.datamyImage = self.showImage(log(self.real_data),self.dataaxes)
        self.dataColor = self.figure.colorbar(self.datamyImage)

        self.scale = wx.TextCtrl(self,-1)

        self.updateButton = wx.Button(self,-1,'UPDATE')
        self.resetButton = wx.Button(self,-1,'RESET')
        self.areaScaleButton = wx.Button(self,-1,'AUTO SCALE')


        BotSize = wx.BoxSizer(wx.HORIZONTAL)
        vertSize = wx.BoxSizer(wx.VERTICAL)

        BotSize.Add(self.scale,0,wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.updateButton,0,wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.resetButton,0,wx.LEFT|wx.RIGHT,border = 5)
        BotSize.Add(self.areaScaleButton,0,wx.LEFT|wx.RIGHT, border = 5)

        vertSize.Add(self.canvas,-1,wx.EXPAND)
        vertSize.Add(mpl_toolbar,0)
        vertSize.Add(BotSize,0,wx.ALL, border = 10)
        self.SetSizer(vertSize)
        self.Fit()

        self.updateButton.Bind(wx.EVT_BUTTON,self.update)
        self.resetButton.Bind(wx.EVT_BUTTON,self.reset)
        self.areaScaleButton.Bind(wx.EVT_BUTTON,self.autoScale)