~ubuntu-branches/ubuntu/saucy/pyacidobasic/saucy

« back to all changes in this revision

Viewing changes to phPlot.py

  • Committer: Bazaar Package Importer
  • Author(s): Georges Khaznadar
  • Date: 2011-02-10 23:53:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110210235350-cxistp3c035n59e1
Tags: 1.0-1
released a new revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
 
licence={}
3
 
licence['en']="""
4
 
    phPLot.py
5
 
    
6
 
    this file is part of the package pyacidobasic version %s:
7
 
 
8
 
    a program to simulate acido-basic equilibria
9
 
    
10
 
    Copyright (C) 2010 Georges Khaznadar <georgesk@ofset.org>
11
 
 
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.
16
 
 
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.
21
 
 
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/>.
24
 
"""
25
 
 
26
 
from PyQt4 import QtGui, QtCore, Qwt5, QtSvg
27
 
import re
28
 
 
29
 
class phPlot(Qwt5.QwtPlot):
30
 
    def __init__(self, parent=None):
31
 
        Qwt5.QwtPlot.__init__(self,parent)
32
 
        self.setMouseTracking(True)
33
 
        
34
 
        self.picker = Qwt5.QwtPlotPicker(self.canvas())
35
 
        self.picker.setRubberBand (Qwt5.QwtPlotPicker.PointSelection | Qwt5.QwtPicker.DragSelection)
36
 
        self.picker.setTrackerMode(Qwt5.QwtPicker.AlwaysOn)
37
 
        
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, 
43
 
QtCore.Qt.DashLine))
44
 
        #self.marker.setSymbol(QwtSymbol.XCross)
45
 
        self.marker.setValue(1.0, 0.0)
46
 
        self.marker.attach(self)
47
 
 
48
 
        self.exportNo=1
49
 
 
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)
55
 
        self.replot()
56
 
 
57
 
    def getFileName(self, fichier, ext, filtre):
58
 
        """
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
65
 
        """
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)
69
 
        try:
70
 
            self.exportNo=int(re.compile('.*([0-9]).*').match(fichier).group(1))+1
71
 
        except:
72
 
            self.exportNo=1
73
 
        return fichier
74
 
 
75
 
    def exportSVG(self):
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)
82
 
 
83
 
    def exportPDF(self):
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)
90
 
 
91
 
            printer.setCreator('PDF example')
92
 
            self.print_(printer)
93
 
            
94
 
    def exportJPG(self):
95
 
        fileName = self.getFileName('graphe', 'jpg', 'Images JPEG (*.jpg)')
96
 
        if not fileName.isEmpty():
97
 
            QtGui.QPixmap.grabWidget(self).save(fileName, 'JPG')
98
 
 
99
 
    def newTitle(self):
100
 
        title = QtGui.QInputDialog.getText(self, u"Titre",
101
 
                        u"Indiquer le titre à afficher sur le graphique")
102
 
        if title[1]:
103
 
            self.setTitle(title[0])