# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'interfaz.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.

import time
import serial 
from PyQt5 import QtCore, QtGui, QtWidgets
puertoSerial = serial.Serial('COM4', 9600,timeout=1)
#Retardo para establecer la conexión serial
time.sleep(1.8) 

puertoSerial.write(str.encode('a'))
time.sleep(1)



class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(640, 480)
        MainWindow.setStyleSheet("*{\n"
"font-family:century gothic;\n"
"}\n"
"\n"
"QWidget{\n"
"background-image: url(:/images/images/fondo.png)\n"
"}\n"
"\n"
"QFrame#contenedor{\n"
"background: #1c94a7;\n"
"border-radius:18;\n"
"}\n"
"\n"
"QLabel#label, #label_2, #label_5,#label_6{\n"
"background: #1c94a7;\n"
"color: white;\n"
"font-size: 24px;\n"
"font-position: center;\n"
"\n"
"}\n"
"\n"
"QToolButton#b1, #b2{\n"
"color: #DAA520;\n"
"font-size: 18px;\n"
"background: #1c94a7;\n"
"font-family:century gothic;\n"
"}\n"
"\n"
"QPushButton#boton{\n"
"background: black;\n"
"border-radius:18;\n"
"color: white;\n"
"font-size: 18px;\n"
"}\n"
"\n"
"QLabel#label_4,#label_3{\n"
"background: #1c94a7;\n"
"color: #DAA520;\n"
"font-size: 18px;\n"
"font-position: center;\n"
"\n"
"}\n"
"")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.contenedor = QtWidgets.QFrame(self.centralwidget)
        self.contenedor.setGeometry(QtCore.QRect(30, 30, 591, 421))
        self.contenedor.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.contenedor.setFrameShadow(QtWidgets.QFrame.Raised)
        self.contenedor.setObjectName("contenedor")
        self.label = QtWidgets.QLabel(self.contenedor)
        self.label.setGeometry(QtCore.QRect(60, 150, 151, 31))
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(self.contenedor)
        self.label_2.setGeometry(QtCore.QRect(380, 140, 151, 31))
        self.label_2.setObjectName("label_2")
        self.comboBox = QtWidgets.QComboBox(self.contenedor)
        self.comboBox.setGeometry(QtCore.QRect(150, 230, 104, 26))
        self.comboBox.setObjectName("comboBox")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.comboBox.addItem("")
        self.label_3 = QtWidgets.QLabel(self.contenedor)
        self.label_3.setGeometry(QtCore.QRect(20, 240, 101, 21))
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(self.contenedor)
        self.label_4.setGeometry(QtCore.QRect(20, 330, 101, 21))
        self.label_4.setObjectName("label_4")
        self.comboBox_2 = QtWidgets.QComboBox(self.contenedor)
        self.comboBox_2.setGeometry(QtCore.QRect(150, 330, 104, 26))
        self.comboBox_2.setObjectName("comboBox_2")
        self.comboBox_2.addItem("")
        self.comboBox_2.addItem("")
        self.comboBox_2.addItem("")
        self.comboBox_3 = QtWidgets.QComboBox(self.contenedor)
        self.comboBox_3.setGeometry(QtCore.QRect(410, 270, 104, 26))
        self.comboBox_3.setObjectName("comboBox_3")
        self.comboBox_3.addItem("")
        self.comboBox_3.addItem("")
        self.comboBox_3.addItem("")
        self.comboBox_3.addItem("")
        self.label_5 = QtWidgets.QLabel(self.contenedor)
        self.label_5.setGeometry(QtCore.QRect(80, 180, 151, 31))
        self.label_5.setObjectName("label_5")
        self.label_6 = QtWidgets.QLabel(self.contenedor)
        self.label_6.setGeometry(QtCore.QRect(390, 170, 151, 31))
        self.label_6.setObjectName("label_6")
        self.b1 = QtWidgets.QToolButton(self.contenedor)
        self.b1.setGeometry(QtCore.QRect(70, 20, 101, 111))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/images/images/escudo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.b1.setIcon(icon)
        self.b1.setIconSize(QtCore.QSize(90, 90))
        self.b1.setObjectName("b1")
        self.b2 = QtWidgets.QToolButton(self.contenedor)
        self.b2.setGeometry(QtCore.QRect(400, 20, 101, 111))
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap(":/images/images/fi.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.b2.setIcon(icon1)
        self.b2.setIconSize(QtCore.QSize(100, 100))
        self.b2.setObjectName("b2")
        self.boton = QtWidgets.QPushButton(self.contenedor)
        self.boton.setGeometry(QtCore.QRect(410, 350, 113, 32))
        self.boton.setObjectName("boton")
        MainWindow.setCentralWidget(self.centralwidget)

        self.boton.clicked.connect(self.sending)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.label.setText(_translate("MainWindow", "Velocidad de "))
        self.label_2.setText(_translate("MainWindow", "Velocidad de "))
        self.comboBox.setItemText(0, _translate("MainWindow", "Alta"))
        self.comboBox.setItemText(1, _translate("MainWindow", "Media"))
        self.comboBox.setItemText(2, _translate("MainWindow", "Baja"))
        self.label_3.setText(_translate("MainWindow", "Ventilador 1"))
        self.label_4.setText(_translate("MainWindow", "Ventilador 2"))
        self.comboBox_2.setItemText(0, _translate("MainWindow", "Alta"))
        self.comboBox_2.setItemText(1, _translate("MainWindow", "Media"))
        self.comboBox_2.setItemText(2, _translate("MainWindow", "Baja"))
        self.comboBox_3.setItemText(0, _translate("MainWindow", "Modo 1"))
        self.comboBox_3.setItemText(1, _translate("MainWindow", "Modo 2"))
        self.comboBox_3.setItemText(2, _translate("MainWindow", "Modo 3"))
        self.comboBox_3.setItemText(3, _translate("MainWindow", "Modo 4"))
        self.label_5.setText(_translate("MainWindow", "Ventilador"))
        self.label_6.setText(_translate("MainWindow", "Iluminacion"))
        self.b1.setText(_translate("MainWindow", "..."))
        self.b2.setText(_translate("MainWindow", "..."))
        self.boton.setText(_translate("MainWindow", "Activar"))

    def sending(self):
      v1=self.comboBox.currentText()
      v2=self.comboBox_2.currentText()
      led1=self.comboBox_3.currentText()
      if v1=='Alta' and v2=='Alta':
        puertoSerial.write(str.encode('a'))
      elif v1=='Alta' and v2=='Media':
        puertoSerial.write(str.encode('b'))
      elif v1=='Alta' and v2=='Baja':
        puertoSerial.write(str.encode('c'))
      elif v1=='Media' and v2=='Alta':
        puertoSerial.write(str.encode('d'))
      elif v1=='Media' and v2=='Media':
        puertoSerial.write(str.encode('e'))
      elif v1=='Media' and v2=='Baja':
        puertoSerial.write(str.encode('f'))
      elif v1=='Baja' and v2=='Alta':
        puertoSerial.write(str.encode('g'))
      elif v1=='Baja' and v2=='Media':
        puertoSerial.write(str.encode('h'))
      elif v1=='Baja' and v2=='Baja':
        puertoSerial.write(str.encode('i'))
      time.sleep(3)
      #-----------------------------------
      if led1=='Modo 1':
        puertoSerial.write(str.encode('j'))
      elif led1=='Modo 2':
        puertoSerial.write(str.encode('k'))
      elif led1=='Modo 3':
        puertoSerial.write(str.encode('l'))
      elif led1=='Modo 4':
        puertoSerial.write(str.encode('m'))
      time.sleep(3)
import sourceP


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())

puertoSerial.close()