Salome HOME
Merge master branch into V9_dev
[modules/gui.git] / tools / CurvePlot / src / python / ui / PlotSettings.py
1 from pyqtside import QtGui, QtCore
2 from pyqtside.uic import loadUiGen
3 from utils import completeResPath
4
5 class PlotSettings(QtGui.QDialog):
6   def __init__(self):
7     QtGui.QDialog.__init__(self)
8     loadUiGen(completeResPath("PlotSettings.ui"), self)
9     self.initialize()
10
11   def initialize(self):
12     self.legendPositionComboBox.addItem("Bottom")
13     self.legendPositionComboBox.addItem("Right")
14     self._r = 0
15     self._g = 0
16     self._b = 1
17    
18   @QtCore.Slot(int)
19   def onShowLegend(self, index):
20     if index > 0 :
21       self.legendPositionComboBox.setEnabled(True)
22     else :
23       self.legendPositionComboBox.setEnabled(False)
24   
25   @QtCore.Slot() 
26   def onChangeColor(self):
27     col = QtGui.QColorDialog.getColor()
28
29     if col.isValid():
30       r, g, b = [c/255.0 for c in col.getRgb()[:3]]
31       self.setRGB(r, g, b)
32       
33   def setSelectedCurveName(self, name):
34     if name :
35       self.selectedCurvePanel.setTitle("Selected curve : " + name)
36       self.selectedCurvePanel.show()
37     else :
38       self.selectedCurvePanel.hide()
39    
40   def setRGB(self, r, g, b):
41     self._r = r
42     self._g = g
43     self._b = b
44     self.colorCurve.setIcon(QtGui.QIcon(self.drawColorPixmap(int(r*255), int(g*255), int(b*255))))
45    
46   def getRGB(self):
47     return self._r, self._g, self._b
48    
49   def drawColorPixmap(self, r, g, b):
50     pix = QtGui.QPixmap( 16, 16 )
51     color = QtGui.QColor(r, g, b)
52     pix.fill(color)
53     return pix
54
55   def accept(self):
56     xminText = str(self.axisXMinEdit.text())
57     xmaxText = str(self.axisXMaxEdit.text())
58     yminText = str(self.axisYMinEdit.text())
59     ymaxText = str(self.axisYMaxEdit.text())
60     if (yminText == "" or ymaxText == "") :
61       QtGui.QMessageBox.critical(self, "Plot settings", "A field \"YMin\" or \"YMax\" is empty")
62     else :
63       try:
64         xmin = float(xminText)
65       except ValueError:
66         QtGui.QMessageBox.critical(self, "Plot settings", "It is not possible to convert XMin")
67       try:
68         xmax = float(xmaxText)
69       except ValueError:
70         QtGui.QMessageBox.critical(self, "Plot settings", "It is not possible to convert XMax")
71       try:
72         ymin = float(yminText)
73       except ValueError:
74         QtGui.QMessageBox.critical(self, "Plot settings", "It is not possible to convert YMin")
75       try:
76         ymax = float(ymaxText)
77       except ValueError:
78         QtGui.QMessageBox.critical(self, "Plot settings", "It is not possible to convert YMax")
79       if ((xmax-xmin) == 0) :
80         QtGui.QMessageBox.critical(self, "Plot settings", "XMax is is equal to XMin.")
81         return
82       if ((ymax-ymin) == 0) :
83         QtGui.QMessageBox.critical(self, "Plot settings", "YMax is is equal to YMin.")
84         return
85       if ((xmax-xmin) < 0) :
86         QtGui.QMessageBox.warning(self, "Plot settings", "XMax is less than XMin.")
87       if ((ymax-ymin) < 0) :
88         QtGui.QMessageBox.warning(self, "Plot settings", "YMax is less than YMin.")
89       super(PlotSettings, self).accept()