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)
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): 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) h += add_widget(Gtk.HSeparator()) if self.toolbar is not None: self.toolbar.show() h += add_widget(self.toolbar) 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 mpl.is_interactive(): self.window.show() self.canvas.draw_idle() 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 = 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 )
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
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)
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()
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)
def __init__(self, canvas, num): FigureManagerBase.__init__(self, canvas, num) self.window = gtk.Window() self.window.set_title("Figure %d" % num) #self.window.set_border_width(5) vbox = gtk.VBox(spacing=3) 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) else: self.toolbar = None if self.toolbar is not None: self.toolbar.show() vbox.pack_end(self.toolbar, False, False) def destroy(*args): Gcf.destroy(num) self.window.connect("destroy", destroy) if matplotlib.is_interactive(): self.window.show()
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 )
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 )
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 ): 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 )
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) 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_()
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
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()
def __init__(self, canvas, num, window): FigureManagerBase.__init__(self, canvas, num) #Fltk container window t1, t2, w, h = canvas.figure.bbox.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)
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)
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()
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)
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) 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
def __init__(self, canvas, num): if _debug: print 'FigureManagerGTK3.%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.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()
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)
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 '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)
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, frame): FigureManagerBase.__init__(self, canvas, num) self.frame = frame self.window = frame.frame self.toolbar = frame.toolbar def notify_axes_change(fig): if self.toolbar is not None: self.toolbar.update()
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 )
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()
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 )
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()
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)
def __init__(self, canvas, num): _macosx.FigureManager.__init__(self, canvas) icon_path = str(cbook._get_data_path('images/matplotlib.pdf')) _macosx.FigureManager.set_icon(icon_path) FigureManagerBase.__init__(self, canvas, num) if self.toolbar is not None: self.toolbar.update() if mpl.is_interactive(): self.show() self.canvas.draw_idle()
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, 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)
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 )
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()
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)
def __init__(self, canvas, num): FigureManagerBase.__init__(self, canvas, num) self.window = MainWindow() self.window.closing.connect(canvas.close_event) self.window.closing.connect(self._widgetclosed) self.window.setWindowTitle("Figure %d" % num) image = str(cbook._get_data_path('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 without clicking. # https://doc.qt.io/qt-5/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) 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() height = cs.height() + tbs_height + sbs.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_()
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): _macosx.FigureManager.__init__(self, canvas) FigureManagerBase.__init__(self, canvas, num) if mpl.rcParams['toolbar'] == 'toolbar2': self.toolbar = NavigationToolbar2Mac(canvas) else: self.toolbar = None if self.toolbar is not None: self.toolbar.update() if mpl.is_interactive(): self.show() self.canvas.draw_idle()
def __init__(self, canvas, num): FigureManagerBase.__init__(self, canvas, num) title = "Figure %d" % num _ios.FigureManager.__init__(self, canvas, title) # if rcParams['toolbar']=='toolbar2': # self.toolbar = NavigationToolbar2Ios(canvas) # else: # self.toolbar = None # if self.toolbar is not None: # self.toolbar.update() def notify_axes_change(fig): return None
def __init__(self, canvas, num): FigureManagerBase.__init__(self, canvas, num) # If there are multiple figures we only need to enable once try: WMEnable('Matplotlib') except: pass # Load a new PlotWindow MPLBootstrap.alloc().init( ).performSelectorOnMainThread_withObject_waitUntilDone_( 'startWithBundle:', mplBundle, False)
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()
def __init__(self, canvas, num): FigureManagerBase.__init__(self, canvas, num) # If there are multiple figures we only need to enable once try: WMEnable('Matplotlib') except: pass # Load a new PlotWindow MPLBootstrap.alloc().init().performSelectorOnMainThread_withObject_waitUntilDone_( 'startWithBundle:', mplBundle, False)
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): 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)
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()
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)) # 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) if self.toolbar is not None: self.window.addToolBar(self.toolbar) QtCore.QObject.connect(self.toolbar, QtCore.SIGNAL("message"), self.window.statusBar().showMessage) 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.window.resize(cs.width(), cs.height() + tbs_height + sbs.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)
def __init__(self, canvas, num): from psyplot_gui.main import mainwindow self.main = mainwindow if mainwindow is None: return super(PsyplotCanvasManager, self).__init__(canvas, num) parent_widget = FigureWidget() parent_widget.vbox = vbox = QVBoxLayout() self.window = dock = parent_widget.to_dock( mainwindow, title="Figure %d" % num, position=Qt.TopDockWidgetArea, docktype=None) if mainwindow.figures: mainwindow.tabifyDockWidget(mainwindow.figures[-1], dock) mainwindow.figures.append(dock) FigureManagerBase.__init__(self, canvas, num) self.canvas = canvas self.window.setWindowTitle("Figure %d" % num) self.toolbar = self._get_toolbar(canvas, parent_widget) # add text label to status bar self.statusbar_label = mainwindow.figures_label if self.toolbar is not None: vbox.addWidget(self.toolbar) self.toolbar.message.connect(self.statusbar_label.setText) vbox.addWidget(canvas) parent_widget.setLayout(vbox) self.parent_widget = parent_widget # 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(Qt.StrongFocus) self.canvas.setFocus() self.window._destroying = False self.main.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)