from PyQt5 import QtCore, QtGui, QtWidgets, QtMultimedia
from PyQt5.QtCore import *
import sys
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(1001, 498)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.frame_4 = QtWidgets.QFrame(self.centralwidget)
        self.frame_4.setGeometry(QtCore.QRect(20, 100, 72, 135))
        self.frame_4.setAutoFillBackground(False)
        self.frame_4.setStyleSheet("background-color: lightblue")
        self.frame_4.setFrameShape(QtWidgets.QFrame.Box)
        self.frame_4.setFrameShadow(QtWidgets.QFrame.Plain)
        self.frame_4.setLineWidth(2)
        self.frame_4.setObjectName("frame_4")
        self.HAdisplayA = QtWidgets.QLCDNumber(self.frame_4)
        self.HAdisplayA.setGeometry(QtCore.QRect(7, 5, 60, 101))
        self.HAdisplayA.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.HAdisplayA.setDigitCount(1)
        self.HAdisplayA.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
        self.HAdisplayA.setObjectName("HAdisplayA")
        self.HAinputA = QtWidgets.QCheckBox(self.frame_4)
        self.HAinputA.setGeometry(QtCore.QRect(30, 110, 16, 17))
        self.HAinputA.setText("")
        self.HAinputA.setObjectName("HAinputA")
        self.frame_5 = QtWidgets.QFrame(self.centralwidget)
        self.frame_5.setGeometry(QtCore.QRect(20, 250, 72, 135))
        self.frame_5.setAutoFillBackground(False)
        self.frame_5.setStyleSheet("background-color: lightblue")
        self.frame_5.setFrameShape(QtWidgets.QFrame.Box)
        self.frame_5.setFrameShadow(QtWidgets.QFrame.Plain)
        self.frame_5.setLineWidth(2)
        self.frame_5.setObjectName("frame_5")
        self.HAdisplayB = QtWidgets.QLCDNumber(self.frame_5)
        self.HAdisplayB.setGeometry(QtCore.QRect(7, 5, 60, 101))
        self.HAdisplayB.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.HAdisplayB.setDigitCount(1)
        self.HAdisplayB.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
        self.HAdisplayB.setObjectName("HAdisplayB")
        self.HAinputB = QtWidgets.QCheckBox(self.frame_5)
        self.HAinputB.setGeometry(QtCore.QRect(30, 110, 16, 17))
        self.HAinputB.setText("")
        self.HAinputB.setObjectName("HAinputB")
        self.frame_6 = QtWidgets.QFrame(self.centralwidget)
        self.frame_6.setGeometry(QtCore.QRect(402, 110, 72, 111))
        self.frame_6.setAutoFillBackground(False)
        self.frame_6.setStyleSheet("background-color: lightblue")
        self.frame_6.setFrameShape(QtWidgets.QFrame.Box)
        self.frame_6.setFrameShadow(QtWidgets.QFrame.Plain)
        self.frame_6.setLineWidth(2)
        self.frame_6.setObjectName("frame_6")
        self.HACout = QtWidgets.QLCDNumber(self.frame_6)
        self.HACout.setGeometry(QtCore.QRect(7, 5, 60, 101))
        self.HACout.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.HACout.setDigitCount(1)
        self.HACout.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
        self.HACout.setObjectName("HACout")
        self.frame_7 = QtWidgets.QFrame(self.centralwidget)
        self.frame_7.setGeometry(QtCore.QRect(402, 270, 72, 111))
        self.frame_7.setAutoFillBackground(False)
        self.frame_7.setStyleSheet("background-color: lightblue")
        self.frame_7.setFrameShape(QtWidgets.QFrame.Box)
        self.frame_7.setFrameShadow(QtWidgets.QFrame.Plain)
        self.frame_7.setLineWidth(2)
        self.frame_7.setObjectName("frame_7")
        self.HASum = QtWidgets.QLCDNumber(self.frame_7)
        self.HASum.setGeometry(QtCore.QRect(7, 5, 60, 101))
        self.HASum.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.HASum.setDigitCount(1)
        self.HASum.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
        self.HASum.setObjectName("HASum")
        self.frame_8 = QtWidgets.QFrame(self.centralwidget)
        self.frame_8.setGeometry(QtCore.QRect(530, 180, 72, 135))
        self.frame_8.setAutoFillBackground(False)
        self.frame_8.setStyleSheet("background-color: lightblue")
        self.frame_8.setFrameShape(QtWidgets.QFrame.Box)
        self.frame_8.setFrameShadow(QtWidgets.QFrame.Plain)
        self.frame_8.setLineWidth(2)
        self.frame_8.setObjectName("frame_8")
        self.FAdisplayB = QtWidgets.QLCDNumber(self.frame_8)
        self.FAdisplayB.setGeometry(QtCore.QRect(7, 5, 60, 101))
        self.FAdisplayB.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.FAdisplayB.setDigitCount(1)
        self.FAdisplayB.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
        self.FAdisplayB.setObjectName("FAdisplayB")
        self.FAinputB = QtWidgets.QCheckBox(self.frame_8)
        self.FAinputB.setGeometry(QtCore.QRect(30, 110, 16, 17))
        self.FAinputB.setText("")
        self.FAinputB.setObjectName("FAinputB")
        self.frame_9 = QtWidgets.QFrame(self.centralwidget)
        self.frame_9.setGeometry(QtCore.QRect(530, 30, 72, 135))
        self.frame_9.setAutoFillBackground(False)
        self.frame_9.setStyleSheet("background-color: lightblue")
        self.frame_9.setFrameShape(QtWidgets.QFrame.Box)
        self.frame_9.setFrameShadow(QtWidgets.QFrame.Plain)
        self.frame_9.setLineWidth(2)
        self.frame_9.setObjectName("frame_9")
        self.FAdisplayA = QtWidgets.QLCDNumber(self.frame_9)
        self.FAdisplayA.setGeometry(QtCore.QRect(7, 5, 60, 101))
        self.FAdisplayA.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.FAdisplayA.setDigitCount(1)
        self.FAdisplayA.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
        self.FAdisplayA.setObjectName("FAdisplayA")
        self.FAinputA = QtWidgets.QCheckBox(self.frame_9)
        self.FAinputA.setGeometry(QtCore.QRect(30, 110, 16, 17))
        self.FAinputA.setText("")
        self.FAinputA.setObjectName("FAinputA")
        self.frame_10 = QtWidgets.QFrame(self.centralwidget)
        self.frame_10.setGeometry(QtCore.QRect(530, 330, 72, 135))
        self.frame_10.setAutoFillBackground(False)
        self.frame_10.setStyleSheet("background-color: lightblue")
        self.frame_10.setFrameShape(QtWidgets.QFrame.Box)
        self.frame_10.setFrameShadow(QtWidgets.QFrame.Plain)
        self.frame_10.setLineWidth(2)
        self.frame_10.setObjectName("frame_10")
        self.FAdisplayCin = QtWidgets.QLCDNumber(self.frame_10)
        self.FAdisplayCin.setGeometry(QtCore.QRect(7, 5, 60, 101))
        self.FAdisplayCin.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.FAdisplayCin.setDigitCount(1)
        self.FAdisplayCin.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
        self.FAdisplayCin.setObjectName("FAdisplayCin")
        self.FAinputCin = QtWidgets.QCheckBox(self.frame_10)
        self.FAinputCin.setGeometry(QtCore.QRect(30, 110, 16, 17))
        self.FAinputCin.setText("")
        self.FAinputCin.setObjectName("FAinputCin")
        self.frame_11 = QtWidgets.QFrame(self.centralwidget)
        self.frame_11.setGeometry(QtCore.QRect(909, 275, 72, 111))
        self.frame_11.setAutoFillBackground(False)
        self.frame_11.setStyleSheet("background-color: lightblue")
        self.frame_11.setFrameShape(QtWidgets.QFrame.Box)
        self.frame_11.setFrameShadow(QtWidgets.QFrame.Plain)
        self.frame_11.setLineWidth(2)
        self.frame_11.setObjectName("frame_11")
        self.FACout = QtWidgets.QLCDNumber(self.frame_11)
        self.FACout.setGeometry(QtCore.QRect(7, 5, 60, 101))
        self.FACout.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.FACout.setDigitCount(1)
        self.FACout.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
        self.FACout.setObjectName("FACout")
        self.frame_12 = QtWidgets.QFrame(self.centralwidget)
        self.frame_12.setGeometry(QtCore.QRect(908, 105, 72, 111))
        self.frame_12.setAutoFillBackground(False)
        self.frame_12.setStyleSheet("background-color: lightblue")
        self.frame_12.setFrameShape(QtWidgets.QFrame.Box)
        self.frame_12.setFrameShadow(QtWidgets.QFrame.Plain)
        self.frame_12.setLineWidth(2)
        self.frame_12.setObjectName("frame_12")
        self.FASum = QtWidgets.QLCDNumber(self.frame_12)
        self.FASum.setGeometry(QtCore.QRect(7, 5, 60, 101))
        self.FASum.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.FASum.setDigitCount(1)
        self.FASum.setSegmentStyle(QtWidgets.QLCDNumber.Flat)
        self.FASum.setObjectName("FASum")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(120, 118, 250, 250))
        self.label.setAutoFillBackground(False)
        self.label.setStyleSheet("background-color: lightblue")
        self.label.setFrameShape(QtWidgets.QFrame.Panel)
        self.label.setLineWidth(2)
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(630, 118, 250, 250))
        self.label_2.setAutoFillBackground(False)
        self.label_2.setStyleSheet("background-color: lightblue")
        self.label_2.setFrameShape(QtWidgets.QFrame.Panel)
        self.label_2.setLineWidth(2)
        self.label_2.setObjectName("label_2")
        self.line_3 = QtWidgets.QFrame(self.centralwidget)
        self.line_3.setGeometry(QtCore.QRect(90, 155, 40, 3))
        self.line_3.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line_3.setLineWidth(2)
        self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_3.setObjectName("line_3")
        self.line_4 = QtWidgets.QFrame(self.centralwidget)
        self.line_4.setGeometry(QtCore.QRect(90, 305, 40, 3))
        self.line_4.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line_4.setLineWidth(2)
        self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_4.setObjectName("line_4")
        self.line_5 = QtWidgets.QFrame(self.centralwidget)
        self.line_5.setGeometry(QtCore.QRect(370, 165, 33, 3))
        self.line_5.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line_5.setLineWidth(2)
        self.line_5.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_5.setObjectName("line_5")
        self.line_6 = QtWidgets.QFrame(self.centralwidget)
        self.line_6.setGeometry(QtCore.QRect(370, 325, 33, 3))
        self.line_6.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line_6.setLineWidth(2)
        self.line_6.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_6.setObjectName("line_6")
        self.line_7 = QtWidgets.QFrame(self.centralwidget)
        self.line_7.setGeometry(QtCore.QRect(600, 350, 35, 3))
        self.line_7.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line_7.setLineWidth(2)
        self.line_7.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_7.setObjectName("line_7")
        self.line_8 = QtWidgets.QFrame(self.centralwidget)
        self.line_8.setGeometry(QtCore.QRect(600, 235, 35, 3))
        self.line_8.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line_8.setLineWidth(2)
        self.line_8.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_8.setObjectName("line_8")
        self.line_9 = QtWidgets.QFrame(self.centralwidget)
        self.line_9.setGeometry(QtCore.QRect(600, 140, 35, 3))
        self.line_9.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line_9.setLineWidth(2)
        self.line_9.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_9.setObjectName("line_9")
        self.line_10 = QtWidgets.QFrame(self.centralwidget)
        self.line_10.setGeometry(QtCore.QRect(880, 330, 30, 3))
        self.line_10.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line_10.setLineWidth(2)
        self.line_10.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_10.setObjectName("line_10")
        self.line_11 = QtWidgets.QFrame(self.centralwidget)
        self.line_11.setGeometry(QtCore.QRect(880, 160, 30, 3))
        self.line_11.setFrameShadow(QtWidgets.QFrame.Plain)
        self.line_11.setLineWidth(2)
        self.line_11.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_11.setObjectName("line_11")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(630, 80, 151, 31))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.label_3.setFont(font)
        self.label_3.setObjectName("label_3")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(603, 330, 31, 16))
        font = QtGui.QFont()
        font.setPointSize(11)
        self.label_5.setFont(font)
        self.label_5.setObjectName("label_5")
        self.label_6 = QtWidgets.QLabel(self.centralwidget)
        self.label_6.setGeometry(QtCore.QRect(603, 120, 31, 16))
        font = QtGui.QFont()
        font.setPointSize(11)
        self.label_6.setFont(font)
        self.label_6.setObjectName("label_6")
        self.label_7 = QtWidgets.QLabel(self.centralwidget)
        self.label_7.setGeometry(QtCore.QRect(603, 215, 31, 16))
        font = QtGui.QFont()
        font.setPointSize(11)
        self.label_7.setFont(font)
        self.label_7.setObjectName("label_7")
        self.label_8 = QtWidgets.QLabel(self.centralwidget)
        self.label_8.setGeometry(QtCore.QRect(880, 310, 41, 16))
        font = QtGui.QFont()
        font.setPointSize(9)
        self.label_8.setFont(font)
        self.label_8.setObjectName("label_8")
        self.label_9 = QtWidgets.QLabel(self.centralwidget)
        self.label_9.setGeometry(QtCore.QRect(880, 140, 31, 16))
        font = QtGui.QFont()
        font.setPointSize(11)
        self.label_9.setFont(font)
        self.label_9.setObjectName("label_9")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(120, 80, 151, 31))
        font = QtGui.QFont()
        font.setPointSize(24)
        self.label_4.setFont(font)
        self.label_4.setObjectName("label_4")
        self.label_10 = QtWidgets.QLabel(self.centralwidget)
        self.label_10.setGeometry(QtCore.QRect(93, 130, 31, 16))
        font = QtGui.QFont()
        font.setPointSize(11)
        self.label_10.setFont(font)
        self.label_10.setObjectName("label_10")
        self.label_11 = QtWidgets.QLabel(self.centralwidget)
        self.label_11.setGeometry(QtCore.QRect(93, 280, 31, 16))
        font = QtGui.QFont()
        font.setPointSize(11)
        self.label_11.setFont(font)
        self.label_11.setObjectName("label_11")
        self.label_12 = QtWidgets.QLabel(self.centralwidget)
        self.label_12.setGeometry(QtCore.QRect(370, 145, 41, 16))
        font = QtGui.QFont()
        font.setPointSize(9)
        self.label_12.setFont(font)
        self.label_12.setObjectName("label_12")
        self.label_13 = QtWidgets.QLabel(self.centralwidget)
        self.label_13.setGeometry(QtCore.QRect(370, 305, 31, 16))
        font = QtGui.QFont()
        font.setPointSize(11)
        self.label_13.setFont(font)
        self.label_13.setObjectName("label_13")
        self.label.raise_()
        self.frame_4.raise_()
        self.frame_5.raise_()
        self.frame_6.raise_()
        self.frame_7.raise_()
        self.frame_8.raise_()
        self.frame_9.raise_()
        self.frame_10.raise_()
        self.frame_11.raise_()
        self.frame_12.raise_()
        self.label_2.raise_()
        self.line_3.raise_()
        self.line_4.raise_()
        self.line_5.raise_()
        self.line_6.raise_()
        self.line_7.raise_()
        self.line_8.raise_()
        self.line_9.raise_()
        self.line_10.raise_()
        self.line_11.raise_()
        self.label_3.raise_()
        self.label_5.raise_()
        self.label_6.raise_()
        self.label_7.raise_()
        self.label_8.raise_()
        self.label_9.raise_()
        self.label_4.raise_()
        self.label_10.raise_()
        self.label_11.raise_()
        self.label_12.raise_()
        self.label_13.raise_()
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1001, 21))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

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

        # Half Adder Signals
        self.HAinputA.stateChanged.connect(self.HAInputAUpdate)
        self.HAinputB.stateChanged.connect(self.HAInputBUpdate)

        # Full Adder Signals
        self.FAinputA.stateChanged.connect(self.FAInputAUpdate)
        self.FAinputB.stateChanged.connect(self.FAInputBUpdate)
        self.FAinputCin.stateChanged.connect(self.FAInputCUpdate)

    # Full Adder I/O
    def fullAdderLogic(self):
        self.FASum.display(0)
        self.FACout.display(0)

        AxorB = self.FAdisplayA.value() != self.FAdisplayB.value()

        if (AxorB) != self.FAdisplayCin.value():
            self.FASum.display(1)

        AxorBandC = AxorB and (self.FAdisplayCin.value() == 1)
        AandB = self.FAdisplayA.value() == 1 and self.FAdisplayB.value() == 1

        if AxorBandC or AandB:
            self.FACout.display(1)
        

    def FAInputAUpdate(self):
        if self.FAinputA.isChecked():
            self.FAdisplayA.display(1)
        else:
            self.FAdisplayA.display(0)
        self.fullAdderLogic()

    def FAInputBUpdate(self):
        if self.FAinputB.isChecked():
            self.FAdisplayB.display(1)
        else:
            self.FAdisplayB.display(0)
        self.fullAdderLogic()

    def FAInputCUpdate(self):
        if self.FAinputCin.isChecked():
            self.FAdisplayCin.display(1)
        else:
            self.FAdisplayCin.display(0)
        self.fullAdderLogic()

    # Half Adder I/O
    def halfAdderLogic(self):
        self.HACout.display(0)
        self.HASum.display(0)

        if self.HAdisplayA.value() == 1 and self.HAdisplayB.value() == 1:
            self.HACout.display(1)

        if self.HAdisplayA.value() == 1 or self.HAdisplayB.value() == 1:
            self.HASum.display(1)

    def HAInputAUpdate(self):
        if self.HAinputA.isChecked():
            self.HAdisplayA.display(1)
        else:
            self.HAdisplayA.display(0)
        self.halfAdderLogic()

    def HAInputBUpdate(self):
        if self.HAinputB.isChecked():
            self.HAdisplayB.display(1)
        else:
            self.HAdisplayB.display(0)
        self.halfAdderLogic()

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Half and Full Adder Simulator - Rafael Almazar"))
        self.label.setText(_translate("MainWindow", "<html><head/><body><p><img src=\":/Half-Adder/Half-Adder.png\"/></p></body></html>"))
        self.label_2.setText(_translate("MainWindow", "<html><head/><body><p><img src=\":/Full-Adder/Full-Adder.png\"/></p></body></html>"))
        self.label_3.setText(_translate("MainWindow", "Full Adder"))
        self.label_5.setText(_translate("MainWindow", "C in"))
        self.label_6.setText(_translate("MainWindow", "A"))
        self.label_7.setText(_translate("MainWindow", "B"))
        self.label_8.setText(_translate("MainWindow", "C out"))
        self.label_9.setText(_translate("MainWindow", "Sum"))
        self.label_4.setText(_translate("MainWindow", "Half Adder"))
        self.label_10.setText(_translate("MainWindow", "A"))
        self.label_11.setText(_translate("MainWindow", "B"))
        self.label_12.setText(_translate("MainWindow", "C out"))
        self.label_13.setText(_translate("MainWindow", "Sum"))
import images_rc

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