Salome HOME
Update copyrights
[modules/gui.git] / tools / CurvePlot / src / python / ui / PlotSettings.py
1 # Copyright (C) 2016-2019  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from pyqtside import QtGui, QtCore
21 from pyqtside.uic import loadUiGen
22 from utils import completeResPath
23
24 class PlotSettings(QtGui.QDialog):
25   def __init__(self):
26     QtGui.QDialog.__init__(self)
27     loadUiGen(completeResPath("PlotSettings.ui"), self)
28     self.initialize()
29
30   def initialize(self):
31     self.legendPositionComboBox.addItem("Bottom")
32     self.legendPositionComboBox.addItem("Right")
33     self._r = 0
34     self._g = 0
35     self._b = 1
36    
37   @QtCore.Slot(int)
38   def onShowLegend(self, index):
39     if index > 0 :
40       self.legendPositionComboBox.setEnabled(True)
41     else :
42       self.legendPositionComboBox.setEnabled(False)
43   
44   @QtCore.Slot() 
45   def onChangeColor(self):
46     col = QtGui.QColorDialog.getColor()
47
48     if col.isValid():
49       r, g, b = [c/255.0 for c in col.getRgb()[:3]]
50       self.setRGB(r, g, b)
51       
52   def setSelectedCurveName(self, name):
53     if name :
54       self.selectedCurvePanel.setTitle("Selected curve : " + name)
55       self.selectedCurvePanel.show()
56     else :
57       self.selectedCurvePanel.hide()
58    
59   def setRGB(self, r, g, b):
60     self._r = r
61     self._g = g
62     self._b = b
63     self.colorCurve.setIcon(QtGui.QIcon(self.drawColorPixmap(int(r*255), int(g*255), int(b*255))))
64    
65   def getRGB(self):
66     return self._r, self._g, self._b
67    
68   def drawColorPixmap(self, r, g, b):
69     pix = QtGui.QPixmap( 16, 16 )
70     color = QtGui.QColor(r, g, b)
71     pix.fill(color)
72     return pix
73
74   def accept(self):
75     xminText = str(self.axisXMinEdit.text())
76     xmaxText = str(self.axisXMaxEdit.text())
77     yminText = str(self.axisYMinEdit.text())
78     ymaxText = str(self.axisYMaxEdit.text())
79     if (yminText == "" or ymaxText == "") :
80       QtGui.QMessageBox.critical(self, "Plot settings", "A field \"YMin\" or \"YMax\" is empty")
81     else :
82       try:
83         xmin = float(xminText)
84       except ValueError:
85         QtGui.QMessageBox.critical(self, "Plot settings", "It is not possible to convert XMin")
86       try:
87         xmax = float(xmaxText)
88       except ValueError:
89         QtGui.QMessageBox.critical(self, "Plot settings", "It is not possible to convert XMax")
90       try:
91         ymin = float(yminText)
92       except ValueError:
93         QtGui.QMessageBox.critical(self, "Plot settings", "It is not possible to convert YMin")
94       try:
95         ymax = float(ymaxText)
96       except ValueError:
97         QtGui.QMessageBox.critical(self, "Plot settings", "It is not possible to convert YMax")
98       if ((xmax-xmin) == 0) :
99         QtGui.QMessageBox.critical(self, "Plot settings", "XMax is is equal to XMin.")
100         return
101       if ((ymax-ymin) == 0) :
102         QtGui.QMessageBox.critical(self, "Plot settings", "YMax is is equal to YMin.")
103         return
104       if ((xmax-xmin) < 0) :
105         QtGui.QMessageBox.warning(self, "Plot settings", "XMax is less than XMin.")
106       if ((ymax-ymin) < 0) :
107         QtGui.QMessageBox.warning(self, "Plot settings", "YMax is less than YMin.")
108       super(PlotSettings, self).accept()