1
# -*- encoding: utf-8 -*-
6
this file is part of the package pyacidobasic version %s:
8
a program to simulate acido-basic equilibria
10
Copyright (C) 2010 Georges Khaznadar <georgesk@ofset.org>
12
This program is free software: you can redistribute it and/or modify
13
it under the terms of the GNU General Public License as published by
14
the Free Software Foundation, either version 3 of the License, or
15
(at your option) any later version.
17
This program is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
GNU General Public License for more details.
22
You should have received a copy of the GNU General Public License
23
along with this program. If not, see <http://www.gnu.org/licenses/>.
26
from PyQt4 import QtGui, QtCore, Qwt5, QtSvg
29
class phPlot(Qwt5.QwtPlot):
30
def __init__(self, parent=None):
31
Qwt5.QwtPlot.__init__(self,parent)
32
self.setMouseTracking(True)
34
self.picker = Qwt5.QwtPlotPicker(self.canvas())
35
self.picker.setRubberBand (Qwt5.QwtPlotPicker.PointSelection | Qwt5.QwtPicker.DragSelection)
36
self.picker.setTrackerMode(Qwt5.QwtPicker.AlwaysOn)
38
self.marker = Qwt5.QwtPlotMarker()
39
self.marker.setLineStyle(Qwt5.QwtPlotMarker.VLine | Qwt5.QwtPlotMarker.HLine)
40
self.marker.setLabelAlignment(QtCore.Qt.AlignRight |
41
QtCore.Qt.AlignBottom)
42
self.marker.setLinePen(QtGui.QPen(QtCore.Qt.darkGray, 1,
44
#self.marker.setSymbol(QwtSymbol.XCross)
45
self.marker.setValue(1.0, 0.0)
46
self.marker.attach(self)
50
def mouseMoveEvent(self, e):
51
canvasPos = self.canvas().mapFrom(self, e.pos())
52
xFloat = self.invTransform(Qwt5.QwtPlot.xBottom, canvasPos.x())
53
yFloat = self.invTransform(Qwt5.QwtPlot.yLeft, canvasPos.y())
54
self.marker.setValue(xFloat, yFloat)
57
def getFileName(self, fichier, ext, filtre):
59
Renvoie un nom de fichier à ouvrir pour un enregistrement
60
@param fichier une proposition initiale pour le nom du fichier
61
@param nb numero à inscrire dans le nom de fichier
62
@param ext extension du nom de fichier
63
@param filtre filtre les noms de fichiers visibles
64
@result le nom du fichier choisi
66
msg=u'Nom du fichier à exporter'
67
fichier="%s%03d.%s" %(fichier, self.exportNo, ext)
68
fichier= QtGui.QFileDialog.getSaveFileName(self,msg,fichier,filtre)
70
self.exportNo=int(re.compile('.*([0-9]).*').match(fichier).group(1))+1
76
fileName = self.getFileName('graphe', 'svg', 'Documents SVG (*.svg)')
77
if not fileName.isEmpty():
78
generator = QtSvg.QSvgGenerator()
79
generator.setFileName(fileName)
80
generator.setSize(QtCore.QSize(800, 600))
81
self.print_(generator)
84
fileName = self.getFileName('graphe', 'pdf', 'Documents PDF (*.pdf)')
85
if not fileName.isEmpty():
86
printer = QtGui.QPrinter()
87
printer.setOutputFormat(QtGui.QPrinter.PdfFormat)
88
printer.setOrientation(QtGui.QPrinter.Landscape)
89
printer.setOutputFileName(fileName)
91
printer.setCreator('PDF example')
95
fileName = self.getFileName('graphe', 'jpg', 'Images JPEG (*.jpg)')
96
if not fileName.isEmpty():
97
QtGui.QPixmap.grabWidget(self).save(fileName, 'JPG')
100
title = QtGui.QInputDialog.getText(self, u"Titre",
101
u"Indiquer le titre à afficher sur le graphique")
103
self.setTitle(title[0])