from builtins import object
from PyQt5 import QtGui, QtCore
from PyQt5.QtWidgets import *
from qgis.core import *
from qgis.gui import *

class Ui_RUSLE_runoff(object):
    def setupUi(self, RUSLE_runoff):
        
        # create main window
        RUSLE_runoff.setWindowModality(QtCore.Qt.ApplicationModal)
        RUSLE_runoff.resize(500,400)  
        
        # input file meteorological data
        # create gridLayout
        self.gridLayout1 = QGridLayout(RUSLE_runoff)
        self.gridLayout1.setObjectName("gridLayout1")
        # create label in gridLayout 
        self.label_meteo = QLabel(RUSLE_runoff)
        self.label_meteo.setObjectName("label_meteo")
        # define label (QWidget, row, column, QtAlignement)
        self.gridLayout1.addWidget(self.label_meteo,0,0,1,1)
        # create select button to input file
        self.selectButton_meteo = QPushButton(RUSLE_runoff)
        self.selectButton_meteo.setObjectName("selectButton_meteo")
        self.gridLayout1.addWidget(self.selectButton_meteo,0,2,1,1)
        self.inputLayerCombo_meteo = QComboBox(RUSLE_runoff)
        self.inputLayerCombo_meteo.setObjectName("inputLayerCombo_meteo")
        self.gridLayout1.addWidget(self.inputLayerCombo_meteo, 0,1,1,1)
        
        # field to mask shapefile input
        self.maskLabel = QLabel(RUSLE_runoff)
        self.maskLabel.setObjectName("maskLabel")
        self.gridLayout1.addWidget(self.maskLabel, 1,0,1,1)
        # create select button to input mask
        self.selectMask = QPushButton(RUSLE_runoff)
        self.selectMask.setObjectName("selectMask")
        self.gridLayout1.addWidget(self.selectMask, 1,2,1,1)
        self.inputMaskCombo = QComboBox(RUSLE_runoff)
        self.inputMaskCombo.setEditable(True)
        self.inputMaskCombo.setObjectName("inputMaskCombo")
        self.gridLayout1.addWidget(self.inputMaskCombo, 1,1,1,1)
        # stretch to extend the widget in column1
        self.gridLayout1.setColumnStretch(1,1)        
        
        # field to interpolation method (the user must to choose)
        self.methodLabel = QLabel(RUSLE_runoff)
        self.methodLabel.setObjectName("methodLabel")
        self.gridLayout1.addWidget(self.methodLabel, 2,0,1,1)
        # combobox to choose the method
        self.comboBoxMethod = QComboBox(RUSLE_runoff)
        self.comboBoxMethod.setObjectName("comboBoxMethod")
        self.gridLayout1.addWidget(self.comboBoxMethod,2,1,1,1)
        self.styles = ['Inverse Distance Weighting', 'Kriging', 'Cubic spline approximation (SAGA)', 'Spatial approximation using spline with tension (GRASS)']
        self.comboBoxMethod.addItems(self.styles)      
        
        # create groudpbox
        self.groupBox1 = QGroupBox(RUSLE_runoff)
        self.groupBox1.setObjectName("groupBox1")
        self.gridLayout3 = QGridLayout(self.groupBox1)
        self.gridLayout3.setObjectName("gridLayout3")
        self.gridLayout1.addWidget(self.groupBox1, 3,0,1,-1)  
        # R value in case of user has it
        self.labelR = QLabel(RUSLE_runoff)
        self.labelR.setObjectName("labelR")
        self.gridLayout3.addWidget(self.labelR,0,0,-1,1)
        self.lineR = QComboBox(RUSLE_runoff)
        self.lineR.setObjectName("lineR")
        self.gridLayout3.addWidget(self.lineR,0,1,-1,1)         
        # fields to rain10 and days10
        self.labelrain = QLabel(RUSLE_runoff)
        self.labelrain.setObjectName("labelrain")
        self.gridLayout3.addWidget(self.labelrain,1,0,-1,1)
        self.linerain = QComboBox(RUSLE_runoff)
        self.linerain.setObjectName("linerain")
        self.gridLayout3.addWidget(self.linerain,1,1,-1,1)  
        self.labeldays = QLabel(RUSLE_runoff)
        self.labeldays.setObjectName("labeldays")
        self.gridLayout3.addWidget(self.labeldays,2,0,-1,1)
        self.linedays = QComboBox(RUSLE_runoff)
        self.linedays.setObjectName("linedays")
        self.gridLayout3.addWidget(self.linedays, 2,1,-1,1)
 
    
       
        # define pixel size
        self.labelPix = QLabel(RUSLE_runoff)
        self.labelPix.setObjectName("labelPix")
        self.gridLayout3.addWidget(self.labelPix, 2,2,1,1)
        self.linePix = QSpinBox()
        self.linePix.setValue(29)
        self.linePix.stepBy(1)
        self.linePix.setObjectName("linePix")
        self.gridLayout3.addWidget(self.linePix,2,3,1,1)     
        
        # field to choose the method for runnof erosivity
        self.erosivityLabel = QLabel(RUSLE_runoff)
        self.erosivityLabel.setObjectName("erosivityLabel")
        self.gridLayout1.addWidget(self.erosivityLabel, 4,0,1,1)
        # combobox to choose the method
        self.comboBoxErosivity = QComboBox(RUSLE_runoff)
        self.comboBoxErosivity.setObjectName("comboBoxErosivity")
        self.gridLayout1.addWidget(self.comboBoxErosivity,4,1,1,1)
        self.styles_erosivity = ['R values','EI30 = 7.05rain(10)-88.92days(10) Loureiro e Coutinho 2001']
        self.comboBoxErosivity.addItems(self.styles_erosivity)    
        # other methods (future):'E = 0.29[1-0.72 exp(-0.05I)] Brown and Foster (1987)', 'R = (0.07397xF^1.847)/17.2 (F<55mm), R = ((95.77-(0.681xF)+(0.477xF^2)))/17.2 (F>=55mm) Renard and Freimund (1994)', 'R(m) = 0.689P^1.474 Xu et al (2007)', 'R = 0.1215xF^2.2421 Irvem and others (2007)', 'R = 0.264 F^1.50 Ferro et al (1991)'
       
        # output file
        # create label in gridLayout
        self.label_out = QLabel(RUSLE_runoff)
        self.label_out.setObjectName("label_out")
        # define label (QWidget, row, column, QtAlignement)
        self.gridLayout1.addWidget(self.label_out,5,0,1,1)
        # create select button to output file
        self.selectButton_out = QPushButton(RUSLE_runoff)
        self.selectButton_out.setObjectName("selectButton_out")
        self.gridLayout1.addWidget(self.selectButton_out,5,2,1,1)
        self.inputLayerCombo_out = QLineEdit(RUSLE_runoff)
        self.inputLayerCombo_out.setObjectName("inputLayerCombo_out")
        self.gridLayout1.addWidget(self.inputLayerCombo_out, 5,1,1,1)
        # stretch to extend the widget in column 1
        self.gridLayout1.setColumnStretch(1,1)                   
 
    
        # button Ok, Close and Help
        self.buttonBox = QDialogButtonBox(RUSLE_runoff)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Help|QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.gridLayout1.addWidget(self.buttonBox, 6, 1, 1, 1)           
                  
    
        self.retranslateUi(RUSLE_runoff)
        self.buttonBox.rejected.connect(RUSLE_runoff.close)
            
    def retranslateUi(self, RUSLE_runoff):
        RUSLE_runoff.setWindowTitle("RUSLE Surface and Runoff")
        self.label_meteo.setText( 'Input meteorological data:')      
        self.label_out.setText( 'Output R:')    
        self.selectButton_meteo.setText( 'Browse')
        self.selectButton_out.setText( 'Browse')
        self.methodLabel.setText("Interpolation Method")
        self.maskLabel.setText("Mask:")
        self.selectMask.setText( 'Browse')
        self.labelrain.setText( 'Rain10:') 
        self.labeldays.setText( 'Days10:') 
        self.labelR.setText( 'R value:') 
        self.labelPix.setText( 'Cell size:')       
        self.erosivityLabel.setText("Runnof Erosivity Method")