本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.setContextMenuPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.setContextMenuPolicy方法的具体用法?Python FigureCanvasQTAgg.setContextMenuPolicy怎么用?Python FigureCanvasQTAgg.setContextMenuPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
的用法示例。
在下文中一共展示了FigureCanvasQTAgg.setContextMenuPolicy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setContextMenuPolicy [as 别名]
def __init__(self, parent=None, width=9, height=6, dpi=None):
self.fig = Figure(figsize=(width, height), facecolor=(.94,.94,.94), dpi=dpi)
FigureCanvas.__init__(self, self.fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self,
QSizePolicy.Expanding,
QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
self.axes = self.fig.add_axes([0.06, 0.10, 0.9, 0.85], facecolor=(.94,.94,.94))
self.compute_initial_figure()
# horizontal x range span
axxspan = self.fig.add_axes([0.06, 0.05, 0.9, 0.02])
axxspan.axis([-0.2, 1.2, -0.2, 1.2])
axxspan.tick_params('y', labelright = False ,labelleft = False ,length=0)
self.xspan = SpanSelector(axxspan, self.onselectX, 'horizontal',useblit=True, span_stays=True, rectprops=dict(alpha=0.5, facecolor='blue'))
# vertical y range span
axyspan = self.fig.add_axes([0.02, 0.10, 0.01, 0.85])
axyspan.axis([-0.2, 1.2, -0.2, 1.2])
axyspan.tick_params('x', labelbottom = False ,labeltop = False ,length=0)
self.yspan = SpanSelector(axyspan, self.onselectY, 'vertical',useblit=True, span_stays=True, rectprops=dict(alpha=0.5, facecolor='blue'))
# reset x y spans
axReset = self.fig.add_axes([0.01, 0.05, 0.03, 0.03],frameon=False, )
self.bnReset = Button(axReset, 'Reset')
self.bnReset.on_clicked( self.xyReset )
# contextMenu
acExportPlot = QAction(self.tr("Export plot"), self)
FigureCanvas.connect(acExportPlot,SIGNAL('triggered()'), self, SLOT('exportPlot()') )
FigureCanvas.addAction(self, acExportPlot )
FigureCanvas.setContextMenuPolicy(self, Qt.ActionsContextMenu )
示例2: __init__
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setContextMenuPolicy [as 别名]
def __init__(self, parent=None, width=9, height=6, dpi=None):
self.fig = Figure(figsize=(width, height), facecolor=(.94,.94,.94), dpi=dpi)
FigureCanvas.__init__(self, self.fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self,
QSizePolicy.Expanding,
QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
# contextMenu
acExportPlot = QAction(self.tr("Export plot"), self)
FigureCanvas.connect(acExportPlot,SIGNAL('triggered()'), self, SLOT('exportPlot()') )
FigureCanvas.addAction(self, acExportPlot )
FigureCanvas.setContextMenuPolicy(self, Qt.ActionsContextMenu )
示例3: XYView
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setContextMenuPolicy [as 别名]
#.........这里部分代码省略.........
""" MPL callback when picking
"""
if event.mouseevent.button == 1:
selected_id = -1
a = event.artist
for crv_id, cv in self._curveViews.items():
if cv._mplLines[0] is a:
selected_id = crv_id
# Use the plotmanager so that other plot sets get their current reset:
self._controller._plotManager.setCurrentCurve(selected_id)
def createAndAddLocalAction(self, icon_file, short_name):
return self._toolbar.addAction(self._sgPyQt.loadIcon("CURVEPLOT", icon_file), short_name)
def createPlotWidget(self):
self._mplFigure = Figure((8.0,5.0), dpi=100)
self._mplCanvas = FigureCanvasQTAgg(self._mplFigure)
self._mplCanvas.installEventFilter(self._eventHandler)
self._mplCanvas.mpl_connect('pick_event', self.onPick)
self._mplAxes = self._mplFigure.add_subplot(1, 1, 1)
self._plotWidget = PlotWidget()
self._toobarMPL = NavigationToolbar2QT(self._mplCanvas, None)
for act in self._toobarMPL.actions():
actionName = str(act.text()).strip()
self._mplNavigationActions[actionName] = act
self._plotWidget.setCentralWidget(self._mplCanvas)
self._toolbar = self._plotWidget.toolBar
self.populateToolbar()
self._popupMenu = QtGui.QMenu()
self._popupMenu.addAction(self._actionLegend)
# Connect evenement for the graphic scene
self._mplCanvas.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self._mplCanvas.customContextMenuRequested.connect(self.onContextMenu)
self._mplCanvas.mpl_connect('scroll_event', self.onScroll)
self._mplCanvas.mpl_connect('button_press_event', self.onMousePress)
def populateToolbar(self):
# Action to dump view in a file
a = self.createAndAddLocalAction("dump_view.png", trQ("DUMP_VIEW_TXT"))
a.triggered.connect(self.dumpView)
self._toolbar.addSeparator()
# Actions to manipulate the scene
a = self.createAndAddLocalAction("fit_all.png", trQ("FIT_ALL_TXT"))
a.triggered.connect(self.autoFit)
# Zoom and pan are mutually exclusive but can be both de-activated:
self._zoomAction = self.createAndAddLocalAction("fit_area.png", trQ("FIT_AREA_TXT"))
self._zoomAction.triggered.connect(self.zoomArea)
self._zoomAction.setCheckable(True)
self._panAction = self.createAndAddLocalAction("zoom_pan.png", trQ("ZOOM_PAN_TXT"))
self._panAction.triggered.connect(self.pan)
self._panAction.setCheckable(True)
self._toolbar.addSeparator()
# Actions to change the representation of curves
self._curveActionGroup = QtGui.QActionGroup(self._plotWidget)
self._pointsAction = self.createAndAddLocalAction("draw_points.png", trQ("DRAW_POINTS_TXT"))
self._pointsAction.setCheckable(True)
self._linesAction = self.createAndAddLocalAction("draw_lines.png", trQ("DRAW_LINES_TXT"))
self._linesAction.setCheckable(True)
self._curveActionGroup.addAction(self._pointsAction)
self._curveActionGroup.addAction(self._linesAction)
self._linesAction.setChecked(True)
self._curveActionGroup.triggered.connect(self.changeModeCurve)
self._curveActionGroup.setExclusive(True)
self._toolbar.addSeparator()
示例4: Calculatrice
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setContextMenuPolicy [as 别名]
class Calculatrice(Panel_simple):
__titre__ = u"Calculatrice" # Donner un titre a chaque module
def __init__(self, *args, **kw):
Panel_simple.__init__(self, *args, **kw)
self.interprete = Interprete(calcul_exact = self.param("calcul_exact"),
ecriture_scientifique = self.param("ecriture_scientifique"),
changer_separateurs = self.param("changer_separateurs"),
separateurs_personnels = self.param("separateurs_personnels"),
copie_automatique = self.param("copie_automatique"),
formatage_OOo = self.param("formatage_OOo"),
formatage_LaTeX = self.param("formatage_LaTeX"),
ecriture_scientifique_decimales = self.param("ecriture_scientifique_decimales"),
precision_calcul = self.param("precision_calcul"),
precision_affichage = self.param("precision_affichage"),
simpify = True,
)
## self.entrees = wx.BoxSizer(wx.HORIZONTAL)
## self.entree = wx.TextCtrl(self, size = (550, -1), style = wx.TE_PROCESS_ENTER)
## self.entrees.Add(self.entree, 1, wx.ALL|wx.GROW, 5)
## self.valider = wx.Button(self, wx.ID_OK)
## self.entrees.Add(self.valider, 0, wx.ALL, 5)
self.entree = entree = LigneCommande(self, longueur = 550, action = self.affichage_resultat)
entree.setToolTip(u"[Maj]+[Entrée] pour une valeur approchée.")
self.entree.texte.setContextMenuPolicy(Qt.CustomContextMenu)
self.entree.texte.customContextMenuRequested.connect(self.EvtMenu)
self.sizer = sizer = QVBoxLayout()
sizer.addWidget(entree)
self.corps = corps = QHBoxLayout()
sizer.addLayout(corps)
self.gauche = gauche = QVBoxLayout()
corps.addLayout(gauche, 1)
self.resultats = resultats = QTextEdit(self)
resultats.setMinimumSize(450, 310)
resultats.setReadOnly(True)
gauche.addWidget(resultats)
self.figure = Figure(figsize=(5,1.3), frameon=True, facecolor="w")
self.visualisation = FigureCanvas(self.figure)
self.axes = axes = self.figure.add_axes([0, 0, 1, 1], frameon=False)
axes.axison = False
self.pp_texte = axes.text(0.5, 0.5, "", horizontalalignment='center', verticalalignment='center', transform = axes.transAxes, size=18)
gauche.addWidget(self.visualisation) # wx.ALL|wx.ALIGN_CENTER
self.visualisation.setContextMenuPolicy(Qt.CustomContextMenu)
self.visualisation.customContextMenuRequested.connect(self.EvtMenuVisualisation)
### Pave numerique de la calculatrice ###
# On construit le pavé de la calculatrice.
# Chaque bouton du pavé doit provoquer l'insertion de la commande correspondante.
self.pave = pave = QVBoxLayout()
corps.addLayout(pave)
# pave.setSpacing(1)
boutons = ["2nde", "ans", "ouv", "ferm", "egal", "7", "8", "9", "div", "x", "4", "5", "6", "mul", "y", "1", "2", "3", "minus", "z", "0", "pt", "pow", "plus", "t", "rac", "sin", "cos", "tan", "exp", "i", "pi", "e", "abs", "mod"]
inserer = ["", "ans()", "(", ")", "=", "7", "8", "9", "/", "x", "4", "5", "6", "*", "y", "1", "2", "3", "-", "z", "0", ".", "^", "+", "t", "sqrt(", ("sin(", "asin(", "sinus / arcsinus"), ("cos(", "acos(", "cosinus / arccosinus"), ("tan(", "atan(", "tangente / arctangente"), ("exp(", "ln(", "exponentielle / logarithme neperien"), ("i", "cbrt(", "i / racine cubique"), ("pi", "sinh(", "pi / sinus hyperbolique"), ("e", "cosh", "e / cosinus hyperbolique"), ("abs(", "tanh", "valeur absolue / tangente hyperbolique"), (" mod ", "log10(", "modulo / logarithme decimal")]
self.seconde = False # indique si la touche 2nde est activee.
def action(event = None):
self.seconde = not self.seconde
if self.seconde:
self.message(u"Touche [2nde] activée.")
else:
self.message("")
self.actions = [action]
for i in range(len(boutons)):
# On aligne les boutons de la calculatrice par rangées de 5.
if i%5 == 0:
self.rangee = rangee = QHBoxLayout()
rangee.addStretch(1)
pave.addLayout(rangee)
# Ensuite, on construit une liste de fonctions, parallèlement à la liste des boutons.
if i > 0:
#XXX: ce serait plus propre en utilisant partial().
def action(event = None, entree = self.entree, j = i):
if type(inserer[j]) == tuple:
entree.insert(inserer[j][self.seconde])
else:
entree.insert(inserer[j])
n = entree.cursorPosition()
entree.setFocus()
entree.setCursorPosition(n)
self.seconde = False
self.message("")
self.actions.append(action)
bouton = QPushButton()
pix = png('btn_' + boutons[i])
bouton.setIcon(QIcon(pix))
bouton.setIconSize(pix.size())
bouton.setFlat(True)
# bouton.setSize()
# bouton.SetBackgroundColour(self.GetBackgroundColour())
rangee.addWidget(bouton)
#.........这里部分代码省略.........
示例5: Calculatrice
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setContextMenuPolicy [as 别名]
class Calculatrice(Panel_simple):
titre = u"Calculatrice" # Donner un titre a chaque module
def __init__(self, *args, **kw):
Panel_simple.__init__(self, *args, **kw)
self.interprete = Interprete(
calcul_exact=self.param("calcul_exact"),
ecriture_scientifique=self.param("ecriture_scientifique"),
formatage_OOo=self.param("formatage_OOo"),
formatage_LaTeX=self.param("formatage_LaTeX"),
ecriture_scientifique_decimales=self.param("ecriture_scientifique_decimales"),
precision_calcul=self.param("precision_calcul"),
precision_affichage=self.param("precision_affichage"),
simpify=True,
)
bouton = BoutonValider(self)
bouton.setToolTip(u"Laissez appuyé pour changer de mode.")
self.entree = entree = LigneCommande(self, longueur=550, action=self.affichage_resultat, bouton=bouton)
entree.setToolTip(u"[Maj]+[Entrée] pour une valeur approchée.")
self.entree.texte.setContextMenuPolicy(Qt.CustomContextMenu)
self.entree.texte.customContextMenuRequested.connect(self.EvtMenu)
self.sizer = sizer = QVBoxLayout()
sizer.addWidget(entree)
self.corps = corps = QHBoxLayout()
sizer.addLayout(corps)
self.resultats = resultats = QTextEdit(self)
resultats.setMinimumSize(450, 310)
resultats.setReadOnly(True)
corps.addWidget(resultats, 1)
corps.addWidget(OngletsCalc(self))
self.figure = Figure(figsize=(5, 1.3), frameon=True, facecolor="w")
self.visualisation = FigureCanvas(self.figure)
self.axes = axes = self.figure.add_axes([0, 0, 1, 1], frameon=False)
axes.axison = False
self.pp_texte = axes.text(
0.5, 0.5, "", horizontalalignment="center", verticalalignment="center", transform=axes.transAxes, size=18
)
self.visualisation.setContextMenuPolicy(Qt.CustomContextMenu)
self.visualisation.customContextMenuRequested.connect(self.EvtMenuVisualisation)
sizer.addWidget(self.visualisation)
self.setLayout(self.sizer)
self.initialiser()
def activer(self):
Panel_simple.activer(self)
# Actions à effectuer lorsque l'onglet devient actif
self.entree.setFocus()
def _sauvegarder(self, fgeo):
fgeo.contenu["Calculatrice"] = [{}]
fgeo.contenu["Calculatrice"][0]["Historique"] = [repr(self.entree.historique)]
# fgeo.contenu["Calculatrice"][0]["Resultats"] = [repr(self.interprete.derniers_resultats)]
fgeo.contenu["Calculatrice"][0]["Affichage"] = [self.resultats.toPlainText()]
fgeo.contenu["Calculatrice"][0]["Etat_interne"] = [self.interprete.save_state()]
##fgeo.contenu["Calculatrice"][0]["Options"] = [{}]
##for i in range(len(self.options)):
##fgeo.contenu["Calculatrice"][0]["Options"][0][self.options[i][1]] = [str(self.options_box[i].isChecked())]
def _ouvrir(self, fgeo):
if fgeo.contenu.has_key("Calculatrice"):
calc = fgeo.contenu["Calculatrice"][0]
self.initialiser()
self.entree.historique = eval_safe(calc["Historique"][0])
# self.interprete.derniers_resultats = securite.eval_safe(calc["Resultats"][0])
resultats = calc["Affichage"][0]
if resultats:
resultats += "\n\n"
self.resultats.setPlainText(resultats)
self.resultats.moveCursor(QTextCursor.End)
self.interprete.load_state(calc["Etat_interne"][0])
##liste = calc["Options"][0].items()
##options = [option for aide, option in self.options]
##for key, value in liste:
##value = eval_safe(value[0])
##self.param(key, value)
##if key in options:
##self.options_box[options.index(key)].setChecked(value)
# il faudrait encore sauvegarder les variables, mais la encore, 2 problemes :
# - pb de securite pour evaluer les variables
# - pb pour obtenir le code source d'une fonction.
# Pour remedier a cela, il faut envisager de :
# - creer un module d'interpretation securisee.
# - rajouter a chaque fonction un attribut __code__, ou creer une nouvelle classe.
def modifier_pp_texte(self, chaine):
u"""Modifier le résultat affiché en LaTeX (pretty print)."""
if self.param("latex"):
# On utilise directement LaTeX pour le rendu
chaine = "$" + chaine + "$"
else:
# On utilise le parser matplotlib.mathtext, moins complet mais bien
# plus rapide. Certaines adaptations doivent être faites.
chaine = latex2mathtext(chaine)
self.pp_texte.set_text(chaine)
#.........这里部分代码省略.........