本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.keyReleaseEvent方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.keyReleaseEvent方法的具体用法?Python FigureCanvasQTAgg.keyReleaseEvent怎么用?Python FigureCanvasQTAgg.keyReleaseEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
的用法示例。
在下文中一共展示了FigureCanvasQTAgg.keyReleaseEvent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MplFigureCellWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import keyReleaseEvent [as 别名]
class MplFigureCellWidget(QCellWidget):
"""
MplFigureCellWidget is the actual QWidget taking the FigureManager
as a child for displaying figures
"""
save_formats = ["Portable Document Format (*.pdf)",
"Portable Network Graphic (*.png)",
"PostScript (*.ps *.eps)",
"Raw images (*.raw *.rgba)",
"Scalable Vector Graphics (*.svg *.svgz)"]
def __init__(self, parent=None):
""" MplFigureCellWidget(parent: QWidget) -> MplFigureCellWidget
Initialize the widget with its central layout
"""
QCellWidget.__init__(self, parent)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
centralLayout = QtGui.QVBoxLayout()
self.setLayout(centralLayout)
centralLayout.setMargin(0)
centralLayout.setSpacing(0)
self.canvas = None
self.figure = None
self.figManager = None
self.toolBarType = MplFigureCellToolBar
self.mplToolbar = None
def updateContents(self, inputPorts):
""" updateContents(inputPorts: tuple) -> None
Update the widget contents based on the input data
"""
(fig, ) = inputPorts
if not self.figure or self.figure.number != fig.figInstance.number:
if self.layout().count() > 0:
self.layout().removeWidget(self.canvas)
self.figure = fig.figInstance
self.canvas = FigureCanvasQTAgg(self.figure)
self.mplToolbar = MplNavigationToolbar(self.canvas, None)
self.canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
self.layout().addWidget(self.canvas)
def keyPressEvent(self, event):
print "KEY PRESS:", event.key()
self.canvas.keyPressEvent(event)
def keyReleaseEvent(self, event):
print "KEY RELEASE:", event.key()
self.canvas.keyReleaseEvent(event)
def deleteLater(self):
""" deleteLater() -> None
Overriding PyQt deleteLater to free up resources
"""
# Destroy the old one if possible
if self.figure is not None:
print "pylab:", pylab
print "self.figure:", self.figure
pylab.close(self.figure)
QCellWidget.deleteLater(self)
def grabWindowPixmap(self):
""" grabWindowPixmap() -> QPixmap
Widget special grabbing function
"""
return QtGui.QPixmap.grabWidget(self.canvas)
def dumpToFile(self, filename):
previous_size = tuple(self.figure.get_size_inches())
self.figure.set_size_inches(8.0,6.0)
self.canvas.print_figure(filename)
self.figure.set_size_inches(previous_size[0],previous_size[1])
self.canvas.draw()
def saveToPDF(self, filename):
previous_size = tuple(self.figure.get_size_inches())
self.figure.set_size_inches(8.0,6.0)
self.canvas.print_figure(filename)
self.figure.set_size_inches(previous_size[0],previous_size[1])
self.canvas.draw()
示例2: MplFigureCellWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import keyReleaseEvent [as 别名]
class MplFigureCellWidget(QCellWidget):
"""
MplFigureCellWidget is the actual QWidget taking the FigureManager
as a child for displaying figures
"""
def __init__(self, parent=None):
""" MplFigureCellWidget(parent: QWidget) -> MplFigureCellWidget
Initialize the widget with its central layout
"""
QCellWidget.__init__(self, parent)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
centralLayout = QtGui.QVBoxLayout()
self.setLayout(centralLayout)
centralLayout.setMargin(0)
centralLayout.setSpacing(0)
# self.figManager = pylab.get_current_fig_manager()
# self.figManager = None
# self.figNumber = None
self.canvas = None
self.figure = None
self.figManager = None
self.toolBarType = MplFigureCellToolBar
self.mplToolbar = None
# def getFigManager(self):
# if self.figNumber is not None:
# pylab.figure(self.figNumber)
# return pylab.get_current_fig_manager()
# return None
# def getFigure(self):
# if self.figNumber is not None:
# return pylab.figure(self.figNumber)
# return None
def updateContents(self, inputPorts):
""" updateContents(inputPorts: tuple) -> None
Update the widget contents based on the input data
"""
(fig, ) = inputPorts
if not self.figure or self.figure.number != fig.figInstance.number:
if self.layout().count() > 0:
self.layout().removeWidget(self.canvas)
self.figure = fig.figInstance
# self.figure.set_size_inches(8.0,6.0)
self.canvas = FigureCanvasQTAgg(self.figure)
self.mplToolbar = MplNavigationToolbar(self.canvas, None)
self.canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
# self.figManager = FigureManagerBase(self.canvas, self.figure.number)
self.layout().addWidget(self.canvas)
# Update the new figure canvas
# self.canvas.draw()
# self.layout().addWidget(self.getFigManager().window)
# Update the new figure canvas
# self.getFigManager().canvas.draw()
# # Replace the old one with the new one
# if newFigManager!=self.figManager:
# # Remove the old figure manager
# if self.figManager:
# self.figManager.window.hide()
# self.layout().removeWidget(self.figManager.window)
# # Add the new one in
# self.layout().addWidget(newFigManager.window)
# # Destroy the old one if possible
# if self.figManager:
# try:
# pylab.close(self.figManager.canvas.figure)
# # There is a bug in Matplotlib backend_qt4. It is a
# # wrong command for Qt4. Just ignore it and continue
# # to destroy the widget
# except:
# pass
# self.figManager.window.deleteLater()
# del self.figManager
# # Save back the manager
# self.figManager = newFigManager
# self.update()
def keyPressEvent(self, event):
print "KEY PRESS:", event.key()
self.canvas.keyPressEvent(event)
def keyReleaseEvent(self, event):
print "KEY RELEASE:", event.key()
self.canvas.keyReleaseEvent(event)
#.........这里部分代码省略.........