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

class Ui_RUSLE_practice(object):
    def setupUi(self, RUSLE_practice):
        
        # create main window
        RUSLE_practice.setWindowModality(QtCore.Qt.ApplicationModal)
        RUSLE_practice.resize(500,300)  
        
        # input clc
        # create gridLayout
        self.gridLayout1 = QGridLayout(RUSLE_practice)
        self.gridLayout1.setObjectName("gridLayout1")        
        # create label in gridLayout 
        self.label_dem = QLabel(RUSLE_practice)
        self.label_dem.setObjectName("label_dem")
        # define label (QWidget, row, column, QtAlignement)
        self.gridLayout1.addWidget(self.label_dem,0,0,1,1)
        # create select button to input file
        self.selectButton_dem = QPushButton(RUSLE_practice)
        self.selectButton_dem.setObjectName("selectButton_dem")
        self.gridLayout1.addWidget(self.selectButton_dem,0,2,1,1)
        self.inputLayerCombo_dem = QComboBox(RUSLE_practice)
        self.inputLayerCombo_dem.setObjectName("inputLayerCombo_dem")
        self.gridLayout1.addWidget(self.inputLayerCombo_dem, 0,1,1,1) 
        
        
        # define a groupbox to specify the cell size and attribute
        self.groupBox1 = QGroupBox(RUSLE_practice)
        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_practice)
        self.labelAttrib.setObjectName("labelAttrib")
        self.gridLayout3.addWidget(self.labelAttrib,0,0,-1,1)
        self.lineAttrib = QComboBox(RUSLE_practice)
        self.lineAttrib.setObjectName("lineAttrib")
        self.gridLayout3.addWidget(self.lineAttrib,0,1,-1,1)
        # define pixel size
        self.labelPix = QLabel(RUSLE_practice)
        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)           
        
                 
        
        # define the indexes
        # create a group box
        self.groupBox = QGroupBox(RUSLE_practice)
        self.groupBox.setObjectName("groupBox")
        self.gridLayout2 = QGridLayout(self.groupBox)
        self.gridLayout2.setObjectName("gridLayout2")
        self.gridLayout1.addWidget(self.groupBox, 2,0,1,-1)
        # table for classes and indexes
        self.tableWidget = QTableWidget(15,2,RUSLE_practice)
        self.gridLayout2.addWidget(self.tableWidget,0,0,1,1)
        self.newItem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(0,self.newItem)
        self.newItem = QTableWidgetItem()
        self.tableWidget.setHorizontalHeaderItem(1,self.newItem)           
        # set the slope values (percent) minimum
        self.line = QLineEdit("Agriculture land-1")
        self.tableWidget.setItem(0,0,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("Agriculture land-2")
        self.tableWidget.setItem(1,0,QTableWidgetItem(self.line.text()))        
        self.line = QLineEdit("Orchard")
        self.tableWidget.setItem(2,0,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("Very dense forest")
        self.tableWidget.setItem(3,0,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("Dense forest")
        self.tableWidget.setItem(4,0,QTableWidgetItem(self.line.text()))  
        self.line = QLineEdit("Moderately dense forest")
        self.tableWidget.setItem(5,0,QTableWidgetItem(self.line.text()))   
        self.line = QLineEdit("Open forest")
        self.tableWidget.setItem(6,0,QTableWidgetItem(self.line.text())) 
        self.line = QLineEdit("Dense scrub")
        self.tableWidget.setItem(7,0,QTableWidgetItem(self.line.text())) 
        self.line = QLineEdit("Forest blank")
        self.tableWidget.setItem(8,0,QTableWidgetItem(self.line.text()))  
        self.line = QLineEdit("Forest plantation")
        self.tableWidget.setItem(9,0,QTableWidgetItem(self.line.text())) 
        self.line = QLineEdit("Wasteland with scrub")
        self.tableWidget.setItem(10,0,QTableWidgetItem(self.line.text()))    
        self.line = QLineEdit("Wasteland without scrub")
        self.tableWidget.setItem(11,0,QTableWidgetItem(self.line.text())) 
        self.line = QLineEdit("Built-up (settlement)")
        self.tableWidget.setItem(12,0,QTableWidgetItem(self.line.text()))      
        self.line = QLineEdit("Mixed built-up land")
        self.tableWidget.setItem(13,0,QTableWidgetItem(self.line.text()))  
        self.line = QLineEdit("Water bodies (river/ponds)")
        self.tableWidget.setItem(14,0,QTableWidgetItem(self.line.text()))         
        # set the maximum of interval
        self.line = QLineEdit("0.5")
        self.tableWidget.setItem(0,1,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("0.4")
        self.tableWidget.setItem(1,1,QTableWidgetItem(self.line.text()))        
        self.line = QLineEdit("0.5")
        self.tableWidget.setItem(2,1,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("1.0")
        self.tableWidget.setItem(3,1,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("1.0")
        self.tableWidget.setItem(4,1,QTableWidgetItem(self.line.text()))  
        self.line = QLineEdit("1.0")
        self.tableWidget.setItem(5,1,QTableWidgetItem(self.line.text()))   
        self.line = QLineEdit("1.0")    
        self.tableWidget.setItem(6,1,QTableWidgetItem(self.line.text()))
        self.line = QLineEdit("1.0")    
        self.tableWidget.setItem(7,1,QTableWidgetItem(self.line.text())) 
        self.line = QLineEdit("1.0")
        self.tableWidget.setItem(8,1,QTableWidgetItem(self.line.text()))  
        self.line = QLineEdit("0.8")
        self.tableWidget.setItem(9,1,QTableWidgetItem(self.line.text())) 
        self.line = QLineEdit("1.0")
        self.tableWidget.setItem(10,1,QTableWidgetItem(self.line.text()))    
        self.line = QLineEdit("1.0")
        self.tableWidget.setItem(11,1,QTableWidgetItem(self.line.text())) 
        self.line = QLineEdit("-")
        self.tableWidget.setItem(12,1,QTableWidgetItem(self.line.text()))      
        self.line = QLineEdit("0.3")
        self.tableWidget.setItem(13,1,QTableWidgetItem(self.line.text()))  
        self.line = QLineEdit("-")
        self.tableWidget.setItem(14,1,QTableWidgetItem(self.line.text()))         
        # create a box layout to insert the buttons Add and Remove
        self.boxLayout = QVBoxLayout()
        self.boxLayout.setObjectName("boxLayout")
        # button Add
        self.buttonAdd = QPushButton(RUSLE_practice)
        self.buttonAdd.setObjectName("buttonAdd")
        self.boxLayout.addWidget(self.buttonAdd)
        # button Remove
        self.buttonRemove = QPushButton(RUSLE_practice)
        self.buttonRemove.setObjectName("buttonRemove") 
        self.boxLayout.addWidget(self.buttonRemove)       
        self.gridLayout2.addLayout(self.boxLayout,0,1,-1,1) 
        # attribute table button
        self.buttonAttribute = QPushButton(RUSLE_practice)
        self.buttonAttribute.setObjectName("buttonAttribute")
        self.boxLayout.addWidget(self.buttonAttribute)       
        self.gridLayout2.addLayout(self.boxLayout,0,2,-1,1)              
        
        # output file
        # create label in gridLayout
        self.label_out = QLabel(RUSLE_practice)
        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_practice)
        self.selectButton_out.setObjectName("selectButton_out")
        self.gridLayout1.addWidget(self.selectButton_out,3,2,1,1)
        self.inputLayerCombo_out = QLineEdit(RUSLE_practice)
        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_practice)
        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_practice)
        self.buttonBox.rejected.connect(RUSLE_practice.close)
        
    
    def retranslateUi(self, RUSLE_practice):
        RUSLE_practice.setWindowTitle("RUSLE Support Practice Factor")
        self.label_dem.setText('Input Land Cover/Land use:')    
        self.label_out.setText('Output P:')    
        self.selectButton_dem.setText('Browse')
        self.selectButton_out.setText('Browse')
        self.tableWidget.horizontalHeaderItem(0).setText("Land use/Land cover")
        self.tableWidget.horizontalHeaderItem(1).setText("Factor P")     
        self.buttonAdd.setText( "Add")
        self.buttonRemove.setText( "Remove")     
        self.buttonAttribute.setText( "Import attribute table")
        self.labelAttrib.setText('Attribute:') 
        self.labelPix.setText('Cell size:')        