当前位置: 首页>>代码示例>>Python>>正文


Python FigureCanvasQTAgg.keyPressEvent方法代码示例

本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.keyPressEvent方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.keyPressEvent方法的具体用法?Python FigureCanvasQTAgg.keyPressEvent怎么用?Python FigureCanvasQTAgg.keyPressEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg的用法示例。


在下文中一共展示了FigureCanvasQTAgg.keyPressEvent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: keyPressEvent

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import keyPressEvent [as 别名]
    def keyPressEvent(self, event):
        if self.redetecter:
            self.detecter()

        key = event.key()
        txt = event.text()
        modifiers = event.modifiers()
        accept = True
        debug(u"key: ", key)
        if key == Qt.Key_Delete and self.select:
            if shift_down(event):
                self.executer(u"%s.cacher()" %self.select.nom)
            else:
                self.executer(u"%s.supprimer()" %self.select.nom)
        elif key in (Qt.Key_Return, Qt.Key_Enter) and self.editeur.objet is not self.select:
            self.editer(shift_down(event))
        elif self.editeur and not self.editeur.key(key, txt, modifiers):
            accept = False

        if key == Qt.Key_Escape and self.interaction:
            print "ESCAPE !"
            self.interaction(special="ESC")
            accept = True

        if not accept:
            FigureCanvasQTAgg.keyPressEvent(self, event)
开发者ID:TeddyBoomer,项目名称:geophar,代码行数:28,代码来源:wxcanvas.py

示例2: MplFigureCellWidget

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import keyPressEvent [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()
开发者ID:tacaswell,项目名称:VisTrails,代码行数:90,代码来源:figure_cell.py

示例3: MplFigureCellWidget

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import keyPressEvent [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)
#.........这里部分代码省略.........
开发者ID:cjh1,项目名称:VisTrails,代码行数:103,代码来源:figure_cell.py


注:本文中的matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.keyPressEvent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。