summaryrefslogtreecommitdiff
path: root/lib/taurus/qt/qtgui/panel/qrawdatachooser.py
blob: 5d8d15d260d811b62e8a5ba3105a545723eee75b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python

#############################################################################
##
## This file is part of Taurus
## 
## http://taurus-scada.org
##
## Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain
## 
## Taurus is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
## 
## Taurus is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Lesser General Public License for more details.
## 
## You should have received a copy of the GNU Lesser General Public License
## along with Taurus.  If not, see <http://www.gnu.org/licenses/>.
##
#############################################################################

"""
RawDataChooser.py:  widget for importing RawData (from file or from a function)
"""

import numpy

from taurus.external.qt import Qt
from taurus.core.util.safeeval import SafeEvaluator
from taurus.qt.qtgui.util.ui import UILoadable


@UILoadable
class QRawDataWidget(Qt.QWidget):
    
    def __init__(self, parent=None):
        super(QRawDataWidget,self).__init__(parent)
        self.loadUi()

        #connecttions
        self.connect(self.openFilesBT,Qt.SIGNAL( "clicked()"), self.onOpenFilesButtonClicked)
        self.connect(self.addCurveBT,Qt.SIGNAL( "clicked()"), self.onAddCurveButtonClicked)
                
        #set validators in LE's
        self.xFromLE.setValidator(Qt.QDoubleValidator(self))
        self.xToLE.setValidator(Qt.QDoubleValidator(self))
        self.xStepLE.setValidator(Qt.QDoubleValidator(self))
        
        
    def onOpenFilesButtonClicked(self):
        """ Emit a ReadFromFiles signal with the selected xcol and skiprows as parameters"""
        xcol = self.xcolSB.value()
        if xcol == self.xcolSB.minimum(): xcol = None
        skiprows = self.headerSB.value()
        self.emit(Qt.SIGNAL("ReadFromFiles"),xcol, skiprows)
        
    def onAddCurveButtonClicked(self):
        """ Emit a AddCurve signal with a rawdata dictionary as a parameter.
        The rawdata dictionary is prepared from the from the GUI's selection."""
        rawdata = {}
        if self.xRangeRB.isChecked():
            rawdata['x']=numpy.arange(float(self.xFromLE.text()), float(self.xToLE.text()), float(self.xStepLE.text()) )
        else:
            sev=SafeEvaluator() 
            try: 
                rawdata['x']=sev.eval(str(self.xValuesLE.text()))
            except:
                Qt.QMessageBox.warning(self, 'Invalid x values' 'Cannot interpret the x values.\n Use Python expressions like "[1, 3 , 67]" or "arange(100)")')
                return
        rawdata['f(x)']=str(self.f_xLE.text())
        self.emit(Qt.SIGNAL("AddCurve"),rawdata)
        
if __name__ == "__main__":
    import sys 
    app = Qt.QApplication(sys.argv)
    form = QRawDataWidget()
    form.show()
    sys.exit(app.exec_())