from qgis.PyQt import QtCore, QtGui
from qgis.core import *
from qgis.gui import *
from qgis.PyQt.QtWidgets import *
from qgis.PyQt.QtCore import QDate


class Ui_downloadWindow(object):

    def setupUi(self, downloadWindow):
        # create NormalI window
        downloadWindow.setWindowModality(QtCore.Qt.ApplicationModal)
        downloadWindow.resize(450, 400)

        # ROI
        # create gridLayout
        self.gridLayout1 = QGridLayout(downloadWindow)
        self.gridLayout1.setObjectName("gridLayout1")

        # select button to download
        self.selectButton = QPushButton(downloadWindow)
        self.selectButton.setObjectName("selectButton")
        self.gridLayout1.addWidget(self.selectButton, 0, 0, 1, 1)

        # group box to input files
        self.groupBox = QGroupBox(downloadWindow)
        self.groupBox.setObjectName("groupBox")
        self.gridLayout2 = QGridLayout(self.groupBox)
        self.gridLayout2.setObjectName("gridLayout2")
        self.gridLayout1.addWidget(self.groupBox, 0, 1, 1, -1)

        self.labelshp = QLabel(downloadWindow)
        self.labelshp.setObjectName("labelshp")
        # define label (QWidget, row, column, QtAlignement)
        self.gridLayout2.addWidget(self.labelshp, 0, 0, 1, 1)
        # line edit
        self.inputLayerComboshp = QComboBox(downloadWindow)
        self.inputLayerComboshp.setObjectName("inputLayerComboshp")
        self.gridLayout2.addWidget(self.inputLayerComboshp, 0, 1, 1, 1)
        # create button
        self.selectbutton_shp = QPushButton(downloadWindow)
        self.selectbutton_shp.setObjectName("selectbutton_shp")
        self.gridLayout2.addWidget(self.selectbutton_shp, 0, 2, 1, 1)


        # downloadification
        # group box
        self.groupBox2 = QGroupBox(downloadWindow)
        self.groupBox2.setObjectName("groupBox2")
        self.gridLayout3 = QGridLayout(self.groupBox2)
        self.gridLayout3.setObjectName("gridLayout3")
        self.gridLayout1.addWidget(self.groupBox2, 1, 0, 1, -1)

        #user and password
        self.label_user = QLabel(downloadWindow)
        self.label_user.setObjectName("label_user")
        self.gridLayout3.addWidget(self.label_user, 0, 0, 1, 1)
        self.line_user = QLineEdit(downloadWindow)
        self.line_user.setObjectName("line_user")
        self.gridLayout3.addWidget(self.line_user, 0, 1, 1, 1)
        self.label_pass = QLabel(downloadWindow)
        self.label_pass.setObjectName("label_pass")
        self.gridLayout3.addWidget(self.label_pass, 1, 0, 1, 1)
        self.line_pass = QLineEdit(downloadWindow)
        self.line_pass.setObjectName("line_pass")
        self.gridLayout3.addWidget(self.line_pass, 1, 1, 1, 1)

        #dates
        # start date
        self.label_startdate = QLabel(downloadWindow)
        self.label_startdate.setObjectName("label_startdate")
        self.gridLayout3.addWidget(self.label_startdate, 2, 0, 1, 1)
        self.startdate = QDateTimeEdit()
        self.startdate.setCalendarPopup(True)
        self.dat = QDate()
        self.today = self.dat.currentDate()
        self.startdate.setDate(self.today)
        self.gridLayout3.addWidget(self.startdate, 2,1,1,1)

        # final date
        self.label_finaldate = QLabel(downloadWindow)
        self.label_finaldate.setObjectName("label_finaldate")
        self.gridLayout3.addWidget(self.label_finaldate, 3, 0, 1, 1)
        self.finaldate = QDateTimeEdit()
        self.finaldate.setCalendarPopup(True)
        self.datf = QDate()
        self.todayf = self.datf.currentDate()
        self.finaldate.setDate(self.todayf)
        self.gridLayout3.addWidget(self.finaldate, 3, 1, 1, 1)

        # cloud cover
        self.label_cloud = QLabel(downloadWindow)
        self.label_cloud.setObjectName("label_cloud")
        self.gridLayout3.addWidget(self.label_cloud, 4, 0, 1, 1)
        self.cloud = QSpinBox()
        self.cloud.setMinimum(0)
        self.cloud.setMaximum(1000)
        self.cloud.setValue(10)
        self.cloud.stepBy(1)
        self.cloud.setObjectName("cloud")
        self.gridLayout3.addWidget(self.cloud, 4, 1, 1, 1)



        # create label in gridLayout
        self.label = QLabel(downloadWindow)
        self.label.setObjectName("label")
        # define label (QWidget, row, column, QtAlignement)
        self.gridLayout3.addWidget(self.label, 5, 0, 1, 1)
        # line edit
        self.outputLayerCombo = QComboBox(downloadWindow)
        self.outputLayerCombo.setObjectName("outputLayerCombo")
        self.gridLayout3.addWidget(self.outputLayerCombo, 5, 1, 1, 1)
        # create button
        self.selectbutton_roi = QPushButton(downloadWindow)
        self.selectbutton_roi.setObjectName("selectbutton_roi")
        self.gridLayout3.addWidget(self.selectbutton_roi, 5, 2, 1, 1)

        # button Ok, Close and Help
        self.buttonBox = QDialogButtonBox(downloadWindow)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Cancel | QDialogButtonBox.Help | QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.gridLayout1.addWidget(self.buttonBox, 2, 1, 1, 1)

        self.retranslateUi(downloadWindow)
        self.buttonBox.rejected.connect(downloadWindow.close)

    def retranslateUi(self, downloadWindow):
        downloadWindow.setWindowTitle('ROI definition')
        self.labelshp.setText('Input limit')
        self.label.setText('Output')
        self.label_startdate.setText('Start date')
        self.label_finaldate.setText('Final date')
        self.label_user.setText('User:')
        self.label_pass.setText('Password:')
        self.label_cloud.setText('Cloud (%):')
        self.selectbutton_roi.setText('Browse')
        self.selectbutton_shp.setText('Browse')
        self.selectButton.setText('Install sentinel package')
        self.groupBox.setTitle("Insert the limit zone (WGS84)")
        self.groupBox2.setTitle("Output")

