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

class Ui_RUSLE_soil(object):
    def setupUi(self, RUSLE_soil):
        
        # create main window
        RUSLE_soil.setWindowModality(QtCore.Qt.ApplicationModal)
        RUSLE_soil.resize(1000,600)  
        
        # input file soil map
        # create gridLayout
        self.gridLayout1 = QGridLayout(RUSLE_soil)
        self.gridLayout1.setObjectName("gridLayout1")
        # create label in gridLayout 
        self.label_soil = QLabel(RUSLE_soil)
        self.label_soil.setObjectName("label_soil")
        # define label (QWidget, row, column, QtAlignement)
        self.gridLayout1.addWidget(self.label_soil,0,0,1,1)
        # create select button to input file
        self.selectButton_soil = QPushButton(RUSLE_soil)
        self.selectButton_soil.setObjectName("selectButton_soil")
        self.gridLayout1.addWidget(self.selectButton_soil,0,2,1,1)
        self.inputLayerCombo_soil = QComboBox(RUSLE_soil)
        self.inputLayerCombo_soil.setObjectName("inputLayerCombo_soil")
        self.gridLayout1.addWidget(self.inputLayerCombo_soil, 0,1,1,1)
        
        # define a groupbox to specify the cell size and attribute
        self.groupBox1 = QGroupBox(RUSLE_soil)
        self.groupBox1.setObjectName("groupBox1")
        self.gridLayout3 = QGridLayout(self.groupBox1)
        self.gridLayout3.setObjectName("gridLayout3")
        self.gridLayout1.addWidget(self.groupBox1, 1,0,1,-1)
        # define attribute "Elevation"
        self.labelAttrib = QLabel(RUSLE_soil)
        self.labelAttrib.setObjectName("labelAttrib")
        self.gridLayout3.addWidget(self.labelAttrib,0,0,-1,1)
        self.lineAttrib = QComboBox(RUSLE_soil)
        self.lineAttrib.setObjectName("lineAttrib")
        self.gridLayout3.addWidget(self.lineAttrib,0,1,-1,1)
        # define pixel size
        self.labelPix = QLabel(RUSLE_soil)
        self.labelPix.setObjectName("labelPix")
        self.gridLayout3.addWidget(self.labelPix, 0,3,-1,1)
        self.linePix = QSpinBox()
        self.linePix.setValue(29)
        self.linePix.stepBy(1)
        self.linePix.setObjectName("linePix")
        self.gridLayout3.addWidget(self.linePix,0,4,-1,1)              
        
        # create a group box
        self.groupBox = QGroupBox(RUSLE_soil)
        self.groupBox.setObjectName("groupBox")
        self.gridLayout2 = QGridLayout(self.groupBox)
        self.gridLayout2.setObjectName("gridLayout2")
        self.gridLayout1.addWidget(self.groupBox, 2,0,1,-1)
        
        self.label_table1 = QLabel(RUSLE_soil)
        self.label_table1.setObjectName("label_table1")
        self.gridLayout2.addWidget(self.label_table1,0,0,1,1)  
        self.label_table2 = QLabel(RUSLE_soil)
        self.label_table2.setObjectName("label_table2")
        self.gridLayout2.addWidget(self.label_table2,2,0,1,1)   
        
        # table for classes and indexes
        self.tableWidget = QTableWidget(8,7,RUSLE_soil)
        self.gridLayout2.addWidget(self.tableWidget,1,0,1,1)
        self.newItem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(0,self.newItem)
        self.newItem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(1,self.newItem)   
        self.newItem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(2,self.newItem)     
        self.newItem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(3,self.newItem)  
        self.newItem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(4,self.newItem) 
        self.newItem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(5,self.newItem)  
        self.newItem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(6,self.newItem)          
        # soil map classifications
        self.line = QLineEdit("")
        self.tableWidget.setItem(0,0,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(1,0,QTableWidgetItem(self.line.text()))        
        self.line = QLineEdit("")
        self.tableWidget.setItem(2,0,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(3,0,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(4,0,QTableWidgetItem(self.line.text()))  
        self.line = QLineEdit("")
        self.tableWidget.setItem(5,0,QTableWidgetItem(self.line.text()))   
        self.line = QLineEdit("")
        self.tableWidget.setItem(6,0,QTableWidgetItem(self.line.text())) 
        self.line = QLineEdit("")
        self.tableWidget.setItem(7,0,QTableWidgetItem(self.line.text()))         
        # set the permeability values
        self.line = QLineEdit("")
        self.tableWidget.setItem(0,1,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(1,1,QTableWidgetItem(self.line.text()))        
        self.line = QLineEdit("")
        self.tableWidget.setItem(2,1,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(3,1,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(4,1,QTableWidgetItem(self.line.text()))  
        self.line = QLineEdit("")
        self.tableWidget.setItem(5,1,QTableWidgetItem(self.line.text()))   
        self.line = QLineEdit("")    
        self.tableWidget.setItem(6,1,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")    
        self.tableWidget.setItem(7,1,QTableWidgetItem(self.line.text()))        
        # set the structure values
        self.line = QLineEdit("")
        self.tableWidget.setItem(0,2,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(1,2,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(2,2,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(3,2,QTableWidgetItem(self.line.text()))        
        self.line = QLineEdit("")
        self.tableWidget.setItem(4,2,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("") 
        self.tableWidget.setItem(5,2,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")           
        self.tableWidget.setItem(6,2,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")    
        self.tableWidget.setItem(7,2,QTableWidgetItem(self.line.text()))   
        # set the clay percentage
        self.line = QLineEdit("")
        self.tableWidget.setItem(0,3,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(1,3,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(2,3,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(3,3,QTableWidgetItem(self.line.text()))        
        self.line = QLineEdit("")
        self.tableWidget.setItem(4,3,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("") 
        self.tableWidget.setItem(5,3,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")           
        self.tableWidget.setItem(6,3,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")    
        self.tableWidget.setItem(7,3,QTableWidgetItem(self.line.text())) 
        # set the silt and very fine sand percentage
        self.line = QLineEdit("")
        self.tableWidget.setItem(0,4,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(1,4,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(2,4,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(3,4,QTableWidgetItem(self.line.text()))        
        self.line = QLineEdit("")
        self.tableWidget.setItem(4,4,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("") 
        self.tableWidget.setItem(5,4,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")           
        self.tableWidget.setItem(6,4,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")    
        self.tableWidget.setItem(7,4,QTableWidgetItem(self.line.text()))            
        # set the gravel percentage
        self.line = QLineEdit("")
        self.tableWidget.setItem(0,5,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(1,5,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(2,5,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(3,5,QTableWidgetItem(self.line.text()))        
        self.line = QLineEdit("")
        self.tableWidget.setItem(4,5,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("") 
        self.tableWidget.setItem(5,5,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")           
        self.tableWidget.setItem(6,5,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")    
        self.tableWidget.setItem(7,5,QTableWidgetItem(self.line.text()))    
        # set the organic matter (MO) percentage
        self.line = QLineEdit("")
        self.tableWidget.setItem(0,6,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(1,6,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(2,6,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget.setItem(3,6,QTableWidgetItem(self.line.text()))        
        self.line = QLineEdit("")
        self.tableWidget.setItem(4,6,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("") 
        self.tableWidget.setItem(5,6,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")           
        self.tableWidget.setItem(6,6,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")    
        self.tableWidget.setItem(7,6,QTableWidgetItem(self.line.text()))    
        
        # table in case of the user has the k values
        self.tableWidget_k = QTableWidget(8,2,RUSLE_soil)
        self.gridLayout2.addWidget(self.tableWidget_k,3,0,1,1)        
        self.newItem = QTableWidgetItem()
        self.tableWidget_k.setHorizontalHeaderItem(0,self.newItem)
        self.newItem = QTableWidgetItem()
        self.tableWidget_k.setHorizontalHeaderItem(1,self.newItem) 
        # soil classifications
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(0,0,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(1,0,QTableWidgetItem(self.line.text()))        
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(2,0,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(3,0,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(4,0,QTableWidgetItem(self.line.text()))  
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(5,0,QTableWidgetItem(self.line.text()))   
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(6,0,QTableWidgetItem(self.line.text())) 
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(7,0,QTableWidgetItem(self.line.text())) 
        # factor K values
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(0,1,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(1,1,QTableWidgetItem(self.line.text()))        
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(2,1,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(3,1,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(4,1,QTableWidgetItem(self.line.text()))  
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(5,1,QTableWidgetItem(self.line.text()))   
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(6,1,QTableWidgetItem(self.line.text())) 
        self.line = QLineEdit("")
        self.tableWidget_k.setItem(7,1,QTableWidgetItem(self.line.text()))           
        
        # create a box layout to insert the buttons Add and Remove
        self.boxLayout = QVBoxLayout()
        self.boxLayout.setObjectName("boxLayout")
        
        # checkbox to identify the table to use
        self.checkBox1 = QCheckBox(RUSLE_soil)
        self.boxLayout.addWidget(self.checkBox1)
        self.checkBox2 = QCheckBox(RUSLE_soil)
        self.boxLayout.addWidget(self.checkBox2)
        
        # button Add
        self.buttonAdd = QPushButton(RUSLE_soil)
        self.buttonAdd.setObjectName("buttonAdd")
        self.boxLayout.addWidget(self.buttonAdd)
        # button Remove
        self.buttonRemove = QPushButton(RUSLE_soil)
        self.buttonRemove.setObjectName("buttonRemove") 
        self.boxLayout.addWidget(self.buttonRemove)        
        # connection to pdf files with codes button
        self.buttonPDF = QPushButton(RUSLE_soil)
        self.buttonPDF.setObjectName("buttonPDF")
        self.boxLayout.addWidget(self.buttonPDF)
        # attribute table button
        self.buttonAttribute = QPushButton(RUSLE_soil)
        self.buttonAttribute.setObjectName("buttonAttribute")
        self.boxLayout.addWidget(self.buttonAttribute)       
        self.gridLayout2.addLayout(self.boxLayout,0,1,-1,1)            
    
        # output file
        # create label in gridLayout
        self.label_out = QLabel(RUSLE_soil)
        self.label_out.setObjectName("label_out")
        # define label (QWidget, row, column, QtAlignement)
        self.gridLayout1.addWidget(self.label_out,3,0,1,1)
        # create select button to output file
        self.selectButton_out = QPushButton(RUSLE_soil)
        self.selectButton_out.setObjectName("selectButton_out")
        self.gridLayout1.addWidget(self.selectButton_out,3,2,1,1)
        self.inputLayerCombo_out = QLineEdit(RUSLE_soil)
        self.inputLayerCombo_out.setObjectName("inputLayerCombo_out")
        self.gridLayout1.addWidget(self.inputLayerCombo_out, 3,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_soil)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Help|QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.gridLayout1.addWidget(self.buttonBox, 4, 1, 1, 1)           
                  
    
        self.retranslateUi(RUSLE_soil)
        self.buttonBox.rejected.connect(RUSLE_soil.close)
            
    def retranslateUi(self, RUSLE_soil):
        RUSLE_soil.setWindowTitle("RUSLE Soil Erodibility")
        self.label_soil.setText( 'Input soil map:')      
        self.label_out.setText( 'Output K:')    
        self.selectButton_soil.setText( 'Browse')
        self.selectButton_out.setText( 'Browse')
        self.tableWidget.horizontalHeaderItem(0).setText("Soil classifications")
        self.tableWidget.horizontalHeaderItem(1).setText("Permeability")
        self.tableWidget.horizontalHeaderItem(2).setText("Structure")
        self.tableWidget.horizontalHeaderItem(3).setText("Clay (%)")       
        self.tableWidget.horizontalHeaderItem(4).setText("Silt and very fine sand (%)")
        self.tableWidget.horizontalHeaderItem(5).setText("Gravel (%)")
        self.tableWidget.horizontalHeaderItem(6).setText("Organic Matter (MO) (%)")
        self.tableWidget_k.horizontalHeaderItem(0).setText("Soil classifications")
        self.tableWidget_k.horizontalHeaderItem(1).setText("K Factor")        
        self.buttonAdd.setText("Add")
        self.checkBox1.setText("Table 1")
        self.checkBox2.setText("Table 2")
        self.buttonRemove.setText("Remove")  
        self.buttonPDF.setText("Tables")  
        self.buttonAttribute.setText("Import attribute table")    
        self.labelAttrib.setText( 'Attribute:') 
        self.label_table1.setText( 'Table 1: the user have the parameters') 
        self.label_table2.setText( 'Table 2: the user get the values through pdf') 
        self.labelPix.setText( 'Cell size:')         