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): 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) 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.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, figure): if DEBUG: print('FigureCanvasQt: ', figure) _create_qApp() QtGui.QWidget.__init__(self) FigureCanvasBase.__init__(self, figure) self.figure = figure self.setMouseTracking(True) self._idle = True # hide until we can test and fix #self.startTimer(backend_IdleEvent.milliseconds) w, h = self.get_width_height() self.resize(w, h) # JDH: Note the commented out code below does not work as # expected, because according to Pierre Raybaut, The reason is # that PyQt fails (silently) to call a method of this object # just before detroying it. Using a lambda function will work, # exactly the same as using a function (which is not bound to # the object to be destroyed). # #QtCore.QObject.connect(self, QtCore.SIGNAL('destroyed()'), # self.close_event) QtCore.QObject.connect(self, QtCore.SIGNAL('destroyed()'), lambda: self.close_event())
def __init__(self, *args, **kwargs): TimerBase.__init__(self, *args, **kwargs) # Create a new timer and connect the timeout() signal to the # _on_timer method. self._timer = QtCore.QTimer() self._timer.connect(QtCore.SIGNAL('timeout()'), self._on_timer)
def destroy(self, *args): if self.window._destroying: return self.window._destroying = True self.window.disconnect(QtCore.SIGNAL('destroyed()'), self._widgetclosed) if self.toolbar: self.toolbar.destroy() if DEBUG: print "destroy figure manager" self.window.close()
def __del__(self): # Probably not necessary in practice, but is good behavior to disconnect try: TimerBase.__del__(self) QtCore.QObject.disconnect(self._timer, QtCore.SIGNAL('timeout()'), self._on_timer) except RuntimeError: # Timer C++ object already deleted pass
def destroy(self, *args): # check for qApp first, as PySide deletes it in its atexit handler if QtGui.QApplication.instance() is None: return if self.window._destroying: return self.window._destroying = True QtCore.QObject.disconnect(self.window, QtCore.SIGNAL('destroyed()'), self._widgetclosed) if self.toolbar: self.toolbar.destroy() if DEBUG: print("destroy figure manager") self.window.close()
def _create_qApp(): """ Only one qApp can exist at a time, so check before creating one. """ if QtGui.QApplication.startingUp(): if DEBUG: print("Starting up QApplication") global qApp app = QtGui.QApplication.instance() if app is None: qApp = QtGui.QApplication([" "]) QtCore.QObject.connect(qApp, QtCore.SIGNAL("lastWindowClosed()"), qApp, QtCore.SLOT("quit()")) else: qApp = app
def __init__(self, figure): if DEBUG: print 'FigureCanvasQt: ', figure _create_qApp() QtGui.QWidget.__init__(self) FigureCanvasBase.__init__(self, figure) self.figure = figure self.setMouseTracking(True) self._idle = True # hide until we can test and fix #self.startTimer(backend_IdleEvent.milliseconds) w, h = self.get_width_height() self.resize(w, h) self.connect(QtCore.SIGNAL('destroyed()'), self.close_event)
def _create_qApp(): """ Only one qApp can exist at a time, so check before creating one. """ return # Disabled since QApplication is already there if QtGui.QApplication.startingUp(): if DEBUG: print "Starting up QApplication" global qApp app = QtGui.QApplication.instance() if app is None: qApp = QtGui.QApplication([" "]) qApp.connect(QtCore.SIGNAL("lastWindowClosed()"), qApp, QtCore.SLOT("quit()")) else: qApp = app
def _create_qApp(): """ Only one qApp can exist at a time, so check before creating one. """ if QtGui.QApplication.startingUp(): if DEBUG: print("Starting up QApplication") global qApp app = QtGui.QApplication.instance() if app is None: # check for DISPLAY env variable on X11 build of Qt if hasattr(QtGui, "QX11Info"): display = os.environ.get('DISPLAY') if display is None or not re.search(':\d', display): raise RuntimeError('Invalid DISPLAY variable') qApp = QtGui.QApplication([" "]) QtCore.QObject.connect(qApp, QtCore.SIGNAL("lastWindowClosed()"), qApp, QtCore.SLOT("quit()")) else: qApp = app
def __init__(self, targetfig, parent): QtGui.QWidget.__init__(self, None) self.targetfig = targetfig self.parent = parent self.sliderleft = QtGui.QSlider(QtCore.Qt.Horizontal) self.sliderbottom = QtGui.QSlider(QtCore.Qt.Vertical) self.sliderright = QtGui.QSlider(QtCore.Qt.Horizontal) self.slidertop = QtGui.QSlider(QtCore.Qt.Vertical) self.sliderwspace = QtGui.QSlider(QtCore.Qt.Horizontal) self.sliderhspace = QtGui.QSlider(QtCore.Qt.Vertical) # constraints QtCore.QObject.connect(self.sliderleft, QtCore.SIGNAL("valueChanged(int)"), self.sliderright.setMinimum) QtCore.QObject.connect(self.sliderright, QtCore.SIGNAL("valueChanged(int)"), self.sliderleft.setMaximum) QtCore.QObject.connect(self.sliderbottom, QtCore.SIGNAL("valueChanged(int)"), self.slidertop.setMinimum) QtCore.QObject.connect(self.slidertop, QtCore.SIGNAL("valueChanged(int)"), self.sliderbottom.setMaximum) sliders = ( self.sliderleft, self.sliderbottom, self.sliderright, self.slidertop, self.sliderwspace, self.sliderhspace, ) adjustments = ('left:', 'bottom:', 'right:', 'top:', 'wspace:', 'hspace:') for slider, adjustment in zip(sliders, adjustments): slider.setMinimum(0) slider.setMaximum(1000) slider.setSingleStep(5) layout = QtGui.QGridLayout() leftlabel = QtGui.QLabel('left') layout.addWidget(leftlabel, 2, 0) layout.addWidget(self.sliderleft, 2, 1) toplabel = QtGui.QLabel('top') layout.addWidget(toplabel, 0, 2) layout.addWidget(self.slidertop, 1, 2) layout.setAlignment(self.slidertop, QtCore.Qt.AlignHCenter) bottomlabel = QtGui.QLabel('bottom') layout.addWidget(QtGui.QLabel('bottom'), 4, 2) layout.addWidget(self.sliderbottom, 3, 2) layout.setAlignment(self.sliderbottom, QtCore.Qt.AlignHCenter) rightlabel = QtGui.QLabel('right') layout.addWidget(rightlabel, 2, 4) layout.addWidget(self.sliderright, 2, 3) hspacelabel = QtGui.QLabel('hspace') layout.addWidget(hspacelabel, 0, 6) layout.setAlignment(hspacelabel, QtCore.Qt.AlignHCenter) layout.addWidget(self.sliderhspace, 1, 6) layout.setAlignment(self.sliderhspace, QtCore.Qt.AlignHCenter) wspacelabel = QtGui.QLabel('wspace') layout.addWidget(wspacelabel, 4, 6) layout.setAlignment(wspacelabel, QtCore.Qt.AlignHCenter) layout.addWidget(self.sliderwspace, 3, 6) layout.setAlignment(self.sliderwspace, QtCore.Qt.AlignBottom) layout.setRowStretch(1, 1) layout.setRowStretch(3, 1) layout.setColumnStretch(1, 1) layout.setColumnStretch(3, 1) layout.setColumnStretch(6, 1) self.setLayout(layout) self.sliderleft.setSliderPosition( int(targetfig.subplotpars.left * 1000)) self.sliderbottom.setSliderPosition(\ int(targetfig.subplotpars.bottom*1000)) self.sliderright.setSliderPosition(\ int(targetfig.subplotpars.right*1000)) self.slidertop.setSliderPosition(int(targetfig.subplotpars.top * 1000)) self.sliderwspace.setSliderPosition(\ int(targetfig.subplotpars.wspace*1000)) self.sliderhspace.setSliderPosition(\ int(targetfig.subplotpars.hspace*1000)) QtCore.QObject.connect(self.sliderleft, QtCore.SIGNAL("valueChanged(int)"), self.funcleft) QtCore.QObject.connect(self.sliderbottom, QtCore.SIGNAL("valueChanged(int)"), self.funcbottom) QtCore.QObject.connect(self.sliderright, QtCore.SIGNAL("valueChanged(int)"), self.funcright) QtCore.QObject.connect(self.slidertop, QtCore.SIGNAL("valueChanged(int)"), self.functop) QtCore.QObject.connect(self.sliderwspace, QtCore.SIGNAL("valueChanged(int)"), self.funcwspace) QtCore.QObject.connect(self.sliderhspace, QtCore.SIGNAL("valueChanged(int)"), self.funchspace)
def set_message(self, s): self.emit(QtCore.SIGNAL("message"), s) if self.coordinates: self.locLabel.setText(s.replace(', ', '\n'))
def __del__(self): # Probably not necessary in practice, but is good behavior to disconnect TimerBase.__del__(self) QtCore.QObject.disconnect(self._timer, QtCore.SIGNAL('timeout()'), self._on_timer)
def closeEvent(self, event): self.emit(QtCore.SIGNAL('closing()')) QtGui.QMainWindow.closeEvent(self, event)