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


Python NavigationToolbar2QT.insertAction方法代码示例

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


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

示例1: _initToolbar

# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QT import insertAction [as 别名]
    def _initToolbar(self):
        toolbar = NavigationToolbar(self._canvas, self.parent())

        act_save = toolbar._actions['save_figure']

        act_copy = QAction(getIcon('edit-copy'), 'Copy', toolbar)
        toolbar.insertAction(act_save, act_copy)

        # Signals
        act_save.triggered.disconnect(toolbar.save_figure)
        act_save.triggered.connect(self.save)

        act_copy.triggered.connect(self.copy)

        return toolbar
开发者ID:pymontecarlo,项目名称:pymontecarlo-gui,代码行数:17,代码来源:results.py

示例2: PlotWidget

# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QT import insertAction [as 别名]
class PlotWidget(QWidget):
    """A wrapper over CanvasWidget to handle additional MOOSE-specific
    stuff.

    modelRoot - path to the entire model our plugin is handling

    dataRoot - path to the container of data tables.

    pathToLine - map from moose path to Line2D objects in plot. Can
    one moose table be plotted multiple times? Maybe yes (e.g., when
    you want multiple other tables to be compared with the same data).

    lineToDataSource - map from Line2D objects to moose paths

    """

    widgetClosedSignal = pyqtSignal(object)
    addGraph           = pyqtSignal(object)

    def __init__(self, model, graph, index, parentWidget, *args, **kwargs):
        super(PlotWidget, self).__init__()
        self.model = model
        self.graph = graph
        self.index = index

        self.menu = self.getContextMenu()
        self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.connect( self
                    , SIGNAL("customContextMenuRequested(QPoint)")
                    , self
                    , SLOT("contextMenuRequested(QPoint)")
                    )

        self.canvas = CanvasWidget(self.model, self.graph, self.index)
        self.canvas.setParent(self)
        self.navToolbar = NavigationToolbar(self.canvas, self)
        self.hackNavigationToolbar()
        self.canvas.mpl_connect('pick_event',self.togglePlot)
        layout = QtGui.QGridLayout()
        layout.addWidget(self.navToolbar, 0, 0)
        layout.addWidget(self.canvas, 1, 0)
        self.setLayout(layout)
        self.pathToLine = defaultdict(set)
        self.lineToDataSource = {}
        self.axesRef = self.canvas.addSubplot(1, 1)
        self.legend  = None
        desktop = QtGui.QApplication.desktop()
        self.setMinimumSize(desktop.screenGeometry().width() / 4, desktop.screenGeometry().height() / 3)
        self.canvas.updateSignal.connect(self.plotAllData)
        self.plotAllData()

    def hackNavigationToolbar(self):
        # ADD Graph Action
        pixmap = QPixmap(
                os.path.join( config.MOOSE_ICON_DIR, 'add_graph.png' )
                )
        icon   = QIcon(pixmap)
        action  = QAction(icon, "Add a graph", self.navToolbar)
        # self.navToolbar.addAction(action)
        action.triggered.connect( self.addGraph.emit )
        self.navToolbar.insertAction(self.navToolbar.actions()[0], action)

        # Delete Graph Action
        pixmap = QPixmap( os.path.join( config.MOOSE_ICON_DIR,
            "delete_graph.png") )
        icon   = QIcon(pixmap)
        action  = QAction(icon, "Delete this graph", self.navToolbar)
        action.triggered.connect(self.delete)
        self.navToolbar.insertAction(self.navToolbar.actions()[1], action)

        #Toggle Grid Action
        pixmap = QPixmap(
                os.path.join( config.MOOSE_ICON_DIR, "grid.png" )
                )
        icon   = QIcon(pixmap)
        action  = QAction(icon, "Toggle Grid", self.navToolbar)
        action.triggered.connect(self.canvas.toggleGrid)
        self.navToolbar.insertAction(self.navToolbar.actions()[2], action)
        self.navToolbar.insertSeparator(self.navToolbar.actions()[3])


    @property
    def plotAll(self):
        return len(self.pathToLine) == 0

    def toggleLegend(self):
        if self.legend is not None:
            self.legend.set_visible(not self.legend.get_visible())
        self.canvas.draw()

    def getContextMenu(self):
        menu =  QMenu()
        # closeAction      = menu.addAction("Delete")
        exportCsvAction = menu.addAction("Export to CSV")
        exportCsvAction.triggered.connect(self.saveAllCsv)
        toggleLegendAction = menu.addAction("Toggle legend")
        toggleLegendAction.triggered.connect(self.toggleLegend)
        self.removeSubmenu = menu.addMenu("Remove")
        # configureAction.triggered.connect(self.configure)
        # self.connect(,SIGNAL("triggered()"),
#.........这里部分代码省略.........
开发者ID:dilawar,项目名称:moose-gui,代码行数:103,代码来源:default.py


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