import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QMessageBox, QApplication,  QWidget, QMainWindow, QSizePolicy
from PyQt5.QtGui import QPixmap, QIcon
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
from numpy import clip, linspace, expm1
from scipy.constants import sigma, pi


class PlotCanvas(FigureCanvas):
    def __init__(self, parent=None, width=5, height=4, dpi=100):
        fig = Figure(figsize=(width, height), dpi=dpi)
        self.axes = fig.add_subplot(111)

        FigureCanvas.__init__(self, fig)
        self.setParent(parent)

        size_policy = QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
        FigureCanvas.setSizePolicy(self, size_policy)
        FigureCanvas.updateGeometry(self)

    def plot(self, vlnova_delka_rozsah, teplota, label=None):
        # If no label is provided, use the temperature as the label
        if label is None:
            label = 'T = {} K'.format(teplota)

        self.axes.axvspan(0.380, 0.435, alpha=0.6, color=(0.5, 0, 1)) # viole
        self.axes.axvspan(0.435, 0.5, alpha=0.5, color=(0/255, 0/255, 204/255)) # blue
        self.axes.axvspan(0.5, 0.520, alpha=0.6, color=(0, 1, 1)) # cyan
        self.axes.axvspan(0.520, 0.565, alpha=0.6, color=(0, 1, 0)) # green
        self.axes.axvspan(0.565, 0.590, alpha=0.6, color=(1, 1, 0)) # yellow
        self.axes.axvspan(0.590, 0.625, alpha=0.6, color=(1, 0.5, 0)) # orange
        self.axes.axvspan(0.625, 0.740, alpha=0.6, color=(1, 0, 0)) # red

        # Plot
        h = 6.626e-34  # Planckova konstanta (J.s)
        c0 = 2.998e8  # Rychlost světla (m/s)
        k = 1.381e-23  # Boltzmannova konstanta (J/K)


        def planckuv_zakon(vlnova_delka, teplota):
            c1 = 2.0 * pi * h * (c0 ** 2)
            c2 = (h * c0) / k
            c3 = c2 / (vlnova_delka * teplota)
            c3_clip = clip(c3, None, 700)  # clip the value of c3 to prevent overflow
            hustota_zariveho_toku = c1 / ((vlnova_delka ** 5) * (expm1(c3) - 1))
            return hustota_zariveho_toku

        hustota_zariveho_toku = planckuv_zakon(vlnova_delka_rozsah, teplota)
        self.axes.plot(vlnova_delka_rozsah * 1e6, hustota_zariveho_toku, label=label)
        self.axes.plot(vlnova_delka_rozsah * 1e6, hustota_zariveho_toku)
        self.axes.set_xlabel('Vlnová délka (μm)')
        self.axes.set_ylabel('Spektrální hustota zářivého toku (W/(m^2. μm))')
        self.axes.set_title('Planckův vyzařovací zákon o T = {} K'.format(teplota))

        # Add a legend to the plot
        self.axes.legend()

        self.draw()

    def clear_graph(self):
        self.axes.clear()
        self.draw()


class MyWindow(QMainWindow):
    def __init__(self):
        super(MyWindow, self).__init__()
        uic.loadUi("windowTverze5.ui", self)

        # Tlacitka pro zalozku 1
        self.calculate_pushButton.clicked.connect(self.vypocet_tepelneho_toku_stit_1)
        self.clear_pushButton.clicked.connect(self.clear_1)
        # Tlacitka pro zalozku 2
        self.calculate2_pushButton.clicked.connect(self.vypocet_tepelneho_toku_2)
        self.clear2_pushButton.clicked.connect(self.clear_2)
        # Tlacitka pro zalozku 3
        self.calculate4_pushButton.clicked.connect(self.vypocet_tepelneho_toku_4)
        self.clear4_pushButton.clicked.connect(self.clear_4)
        # Tlacitka pro zalozku 4
        self.calculate5v2_pushButton.clicked.connect(self.vypocet_tepelneho_toku_5)
        self.clear5v2_pushButton.clicked.connect(self.clear_5)
        # Priklad pro zalozku 1
        self.pushButton_1.clicked.connect(self.help_window)
        self.priklad1_pushButton.clicked.connect(self.priklad1_dosad)
        self.edit = self.findChild(QWidget, "widget")
        self.edit.hide()
        self.hidden = True
        # Priklad pro zalozku 2
        self.priklad2_pushButton.clicked.connect(self.priklad2_dosad)
        self.pushButton_2.clicked.connect(self.help_window_2)
        self.edit_2 = self.findChild(QWidget, "widget_2")
        self.edit_2.hide()
        # Priklad pro zalozku 3
        self.priklad3_pushButton.clicked.connect(self.priklad3_dosad)
        self.pushButton_3.clicked.connect(self.help_window_3)
        self.edit_3 = self.findChild(QWidget, "widget_3")
        self.edit_3.hide()
        # Priklad pro zalozku 4
        self.edit_4 = self.findChild(QWidget, "widget_7")
        self.edit_4.hide()
        self.priklad4_pushButton.clicked.connect(self.priklad4_dosad)
        # zalozka 5
        self.pushButton_5.clicked.connect(self.help_window_4)
        self.graf_clearButton.clicked.connect(self.clear_6)
        # obr
        self.obecny = QPixmap("obr/obecny.png")
        self.obecny_image.setPixmap(self.obecny)
        self.obecny_image.setScaledContents(True)
        # obr
        priklad_ml = QPixmap("obr/malyvelkyv2.png")
        self.priklad_maly.setPixmap(priklad_ml)
        self.priklad_maly.setScaledContents(True)

        # Radiacni stit
        self.frame.setVisible(False)
        self.gridWidget_7.setVisible(False)
        self.label_18.setVisible(False)
        self.stit_pushButton.clicked.connect(self.radiacni_stit)

        # Radiacni stit 2
        self.emisivita_stit_3.setVisible(False)
        self.gridWidget_9.setVisible(False)
        self.label_46.setVisible(False)
        self.stit_pushButton_2.clicked.connect(self.radiacni_stit_2)

        # Spinbox
        self.spinBox.valueChanged.connect(self.combobox_zmena)
        self.spinBox.setValue(0)
        self.spinBox.setVisible(False)
        self.frame_2.setVisible(False)
        self.frame_5.setVisible(False)
        self.frame_6.setVisible(False)
        self.frame_7.setVisible(False)
        self.frame_8.setVisible(False)
        self.frame_9.setVisible(False)
        self.frame_10.setVisible(False)
        self.frame_11.setVisible(False)
        self.frame_12.setVisible(False)
        self.frame_14.setVisible(False)

        self.emisivita32.setVisible(False)
        self.emisivita42.setVisible(False)
        self.emisivita52.setVisible(False)

        # SpinBox2
        self.spinBox2.setVisible(False)
        self.spinBox2.valueChanged.connect(self.combobox_zmena)

        # SpinBox3
        self.spinBox3.setVisible(False)
        self.spinBox3.valueChanged.connect(self.combobox_zmena)

        # SpinBox3_2
        self.spinBox3_2.valueChanged.connect(self.comboBox2_zmena)

        # comboBox priklad 1 stit
        self.comboBox.setCurrentIndex(0)
        self.comboBox.currentIndexChanged.connect(self.combobox_zmena)

        # Priklad 2
        self.gridFrame_10.setVisible(False)
        self.gridFrame_11.setVisible(False)

        # Teploty 1
        self.comboBox_CK_1.setCurrentIndex(0)
        self.teploty_1()
        self.comboBox_CK_1.currentIndexChanged.connect(self.teploty_1)

        # Teploty 1
        self.comboBox_CK_21.setCurrentIndex(0)
        self.comboBox_CK_22.setCurrentIndex(0)
        self.comboBox_CK_23.setCurrentIndex(0)
        self.teploty_2()
        self.comboBox_CK_21.currentIndexChanged.connect(self.teploty_2)
        self.comboBox_CK_22.currentIndexChanged.connect(self.teploty_2)
        self.comboBox_CK_23.currentIndexChanged.connect(self.teploty_2)

        # Teploty 3
        self.comboBox_CK_3.setCurrentIndex(0)
        self.teploty_3()
        self.comboBox_CK_3.currentIndexChanged.connect(self.teploty_3)

        # Teploty 4
        self.comboBox_CK_4.setCurrentIndex(0)
        self.teploty_4()
        self.comboBox_CK_4.currentIndexChanged.connect(self.teploty_4)

        # combobox2
        self.comboBox_2.setCurrentIndex(0)
        self.comboBox_3.setCurrentIndex(0)
        self.comboBox2_zmena()
        self.comboBox_2.currentIndexChanged.connect(self.comboBox2_zmena)
        self.comboBox_3.currentIndexChanged.connect(self.comboBox2_zmena)

        # Graf prostredi
        self.plot_canvas = PlotCanvas(self)
        self.toolbar = NavigationToolbar(self.plot_canvas, self)

        # Layout pro Graf
        layout = self.plotlayout
        layout.addWidget(self.toolbar)
        layout.addWidget(self.plot_canvas)

        self.graph_cleared = False

        # zalozka 4
        self.pushButton_4.clicked.connect(self.clear_or_reset_graph)
        self.graf_pushButton.clicked.connect(lambda: self.add_curve())

        # Obrazek pro priklad 1
        priklad1_stit_1 = QPixmap("obr/priklad1_stit_1.png")
        self.priklad1_label.setPixmap(priklad1_stit_1)
        self.priklad1_label.setScaledContents(True)

        # Zakony
        self.zakony_pushButton.clicked.connect(self.Wien)
        self.zakony_pushButton.clicked.connect(self.Stefan_Boltzmann)

        # Ikonky pro napovedu

        self.pushButton_1.setIcon(QIcon('obr/otaznik.png'))
        self.pushButton_2.setIcon(QIcon('obr/otaznik.png'))
        self.pushButton_3.setIcon(QIcon('obr/otaznik.png'))
        self.pushButton_5.setIcon(QIcon('obr/otaznik.png'))

    def add_curve(self):
        # Input teplota
        teplota_str = self.teplota_G_lineEdit.text()
        try:
            teplota = float(teplota_str.replace(",", "."))
        except ValueError:
            # Chybějící hlaseni pokud je spatne zadano
            QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
            return

        vlnova_delka_rozsah = self.calculate_wavelength_range(teplota)
        self.plot_canvas.plot(vlnova_delka_rozsah, teplota)

    def calculate_wavelength_range(self, teplota): # nastaveni pro zmenu x-osy
        if 1000 < teplota < 2000:
            return linspace(1e-9, 9e-6, 1000)
        elif 2000 <= teplota <= 3000:
            return linspace(1e-9, 5e-6, 1000)
        elif 3000 < teplota < 4000:
            return linspace(1e-9, 4e-6, 1000)
        elif 4000 <= teplota <= 5000:
            return linspace(1e-9, 3e-6, 1000)
        elif 5000 < teplota < 6000:
            return linspace(1e-9, 2e-6, 1000)
        elif 6000 <= teplota <= 7000:
            return linspace(1e-9, 2e-6, 1000)
        elif 500 < teplota < 1000:
            return linspace(5e-9, 11e-6, 1000)
        elif 100 < teplota < 500:
            return linspace(50e-9, 33e-6, 1000)
        elif teplota < 100:
            return linspace(366e-9, 123e-6, 1000)
        elif teplota < 50:
            return linspace(566e-9, 846e-6, 1000)
        else:
            return linspace(1e-9, 1e-6, 1000)

    def clear_or_reset_graph(self):
        if self.graph_cleared:
            self.reset_graph()
        else:
            self.clear_graph()

        self.graph_cleared = not self.graph_cleared
        self.vlnova_delka_rozsah = None

    def clear_graph(self):
        self.plot_canvas.axes.clear()
        self.plot_canvas.draw()

    def reset_graph(self):
        self.clear_graph()

    def combobox_zmena(self):
        index = self.comboBox.currentIndex()
        self.label_48.setVisible(True)
        self.emisivita12_lineEdit.setVisible(True)
        self.label_50.setVisible(True)

        if index == 1:
            self.frame_2.setVisible(True)
            self.spinBox2.setVisible(True)
            self.spinBox.setVisible(False)
            self.spinBox3.setVisible(False)
            self.spinBox.setVisible(False)
            self.frame_7.setVisible(False)
            self.frame_5.setVisible(False)
            self.frame_6.setVisible(False)
            self.frame_10.setVisible(False)
            self.frame_8.setVisible(False)
            self.frame_9.setVisible(False)
            self.frame_11.setVisible(False)
            self.frame_12.setVisible(False)
            self.frame_14.setVisible(False)
            value = self.spinBox2.value()
            if value == 1:
                priklad1_stit_1 = QPixmap("obr/priklad1_emisivita3_stit_1.png")
                self.priklad1_label.setPixmap(priklad1_stit_1)
                self.priklad1_label.setScaledContents(True)
            elif value == 2:
                priklad1_stit_2_3 = QPixmap("obr/priklad1_emisivita3_stit_2.png")
                self.priklad1_label.setPixmap(priklad1_stit_2_3)
                self.priklad1_label.setScaledContents(True)
            elif value == 3:
                priklad1_stit_2_3 = QPixmap("obr/priklad1_emisivita3_stit_3.png")
                self.priklad1_label.setPixmap(priklad1_stit_2_3)
                self.priklad1_label.setScaledContents(True)
            else:
                priklad1_stit_2_3 = QPixmap("obr/priklad1_emisivita3_stit_4.png")
                self.priklad1_label.setPixmap(priklad1_stit_2_3)
                self.priklad1_label.setScaledContents(True)

        elif index == 0:
            self.frame_2.setVisible(False)
            self.spinBox.setVisible(False)
            self.spinBox2.setVisible(False)
            self.spinBox3.setVisible(False)
            self.frame_7.setVisible(False)
            self.frame_5.setVisible(False)
            self.frame_6.setVisible(False)
            self.frame_10.setVisible(False)
            self.frame_8.setVisible(False)
            self.frame_9.setVisible(False)
            self.frame_11.setVisible(False)
            self.frame_12.setVisible(False)
            self.frame_14.setVisible(False)
            priklad1_stit_0 = QPixmap("obr/priklad1_stit_1.png")
            self.priklad1_label.setPixmap(priklad1_stit_0)
            self.priklad1_label.setScaledContents(True)

        elif index == 2:
            self.frame_2.setVisible(False)
            self.spinBox.setVisible(True)
            self.spinBox2.setVisible(False)
            self.spinBox3.setVisible(False)
            value = self.spinBox.value()
            if value == 1:
                priklad1_stit_2 = QPixmap("obr/priklad1_emisivita3_1_stit_1.png")
                self.priklad1_label.setPixmap(priklad1_stit_2)
                self.priklad1_label.setScaledContents(True)
                self.frame_7.setVisible(True)
                self.frame_5.setVisible(False)
                self.frame_6.setVisible(False)
                self.frame_10.setVisible(False)
                self.frame_8.setVisible(False)
                self.frame_9.setVisible(False)
                self.frame_11.setVisible(False)
                self.frame_12.setVisible(False)
                self.frame_14.setVisible(False)
            elif value == 2:
                self.frame_7.setVisible(True)
                self.frame_5.setVisible(True)
                self.frame_6.setVisible(False)
                self.frame_10.setVisible(False)
                self.frame_8.setVisible(False)
                self.frame_9.setVisible(False)
                self.frame_11.setVisible(False)
                self.frame_12.setVisible(False)
                self.frame_14.setVisible(False)
                priklad1_stit_2_1 = QPixmap("obr/priklad1_emisivita3_1_stit_2.png")
                self.priklad1_label.setPixmap(priklad1_stit_2_1)
                self.priklad1_label.setScaledContents(True)
            elif value == 3:
                self.frame_7.setVisible(True)
                self.frame_5.setVisible(True)
                self.frame_6.setVisible(True)
                self.frame_10.setVisible(False)
                self.frame_8.setVisible(False)
                self.frame_9.setVisible(False)
                self.frame_11.setVisible(False)
                self.frame_12.setVisible(False)
                self.frame_14.setVisible(False)
                priklad1_stit_2_2 = QPixmap("obr/priklad1_emisivita3_1_stit_3.png")
                self.priklad1_label.setPixmap(priklad1_stit_2_2)
                self.priklad1_label.setScaledContents(True)
            elif value == 4:
                self.frame_7.setVisible(True)
                self.frame_5.setVisible(True)
                self.frame_6.setVisible(True)
                self.frame_10.setVisible(True)
                self.frame_8.setVisible(False)
                self.frame_9.setVisible(False)
                self.frame_11.setVisible(False)
                self.frame_12.setVisible(False)
                self.frame_14.setVisible(False)
                priklad1_stit_2_4 = QPixmap("obr/priklad1_emisivita3_1_stit_4.png")
                self.priklad1_label.setPixmap(priklad1_stit_2_4)
                self.priklad1_label.setScaledContents(True)
            elif value == 5:
                self.frame_7.setVisible(True)
                self.frame_5.setVisible(True)
                self.frame_6.setVisible(True)
                self.frame_10.setVisible(True)
                self.frame_8.setVisible(True)
                self.frame_9.setVisible(False)
                self.frame_11.setVisible(False)
                self.frame_12.setVisible(False)
                self.frame_14.setVisible(False)
            elif value == 6:
                self.frame_7.setVisible(True)
                self.frame_5.setVisible(True)
                self.frame_6.setVisible(True)
                self.frame_10.setVisible(True)
                self.frame_8.setVisible(True)
                self.frame_9.setVisible(True)
                self.frame_11.setVisible(False)
                self.frame_12.setVisible(False)
                self.frame_14.setVisible(False)
            elif value == 7:
                self.frame_7.setVisible(True)
                self.frame_5.setVisible(True)
                self.frame_6.setVisible(True)
                self.frame_10.setVisible(True)
                self.frame_8.setVisible(True)
                self.frame_9.setVisible(True)
                self.frame_11.setVisible(True)
                self.frame_12.setVisible(False)
                self.frame_14.setVisible(False)
            elif value == 8:
                self.frame_7.setVisible(True)
                self.frame_5.setVisible(True)
                self.frame_6.setVisible(True)
                self.frame_10.setVisible(True)
                self.frame_8.setVisible(True)
                self.frame_9.setVisible(True)
                self.frame_11.setVisible(True)
                self.frame_12.setVisible(True)
                self.frame_11.setVisible(True)
                self.frame_14.setVisible(False)
            elif value == 9:
                self.frame_7.setVisible(True)
                self.frame_5.setVisible(True)
                self.frame_6.setVisible(True)
                self.frame_10.setVisible(True)
                self.frame_8.setVisible(True)
                self.frame_9.setVisible(True)
                self.frame_11.setVisible(True)
                self.frame_12.setVisible(True)
                self.frame_14.setVisible(True)
            else:
                self.frame_7.setVisible(False)
                self.frame_5.setVisible(False)
                self.frame_6.setVisible(False)
                self.frame_10.setVisible(False)
                self.frame_8.setVisible(False)
                self.frame_9.setVisible(False)
                self.frame_11.setVisible(False)
                self.frame_12.setVisible(False)
                self.frame_14.setVisible(False)

        elif index == 3:
            self.spinBox2.setVisible(False)
            self.spinBox3.setVisible(True)
            self.frame_2.setVisible(False)
            self.spinBox.setVisible(False)
            self.spinBox.setVisible(False)
            self.frame_7.setVisible(False)
            self.frame_5.setVisible(False)
            self.frame_6.setVisible(False)
            self.frame_10.setVisible(False)
            self.frame_8.setVisible(False)
            self.frame_9.setVisible(False)
            self.frame_11.setVisible(False)
            self.frame_12.setVisible(False)
            self.frame_14.setVisible(False)
            self.label_48.setVisible(False)
            self.emisivita12_lineEdit.setVisible(False)
            self.label_50.setVisible(False)
            value = self.spinBox3.value()
            if value == 1:
                # Obrazek
                priklad1_stit_3 = QPixmap("obr/priklad1_emisivita1_stit_1.png")
                self.priklad1_label.setPixmap(priklad1_stit_3)
                self.priklad1_label.setScaledContents(True)
            elif value == 2:
                priklad1_stit_4_2 = QPixmap("obr/priklad1_emisivita1_stit_2.png")
                self.priklad1_label.setPixmap(priklad1_stit_4_2)
                self.priklad1_label.setScaledContents(True)
            elif value == 3:
                priklad1_stit_4_3 = QPixmap("obr/priklad1_emisivita1_stit_3.png")
                self.priklad1_label.setPixmap(priklad1_stit_4_3)
                self.priklad1_label.setScaledContents(True)
            else:
                priklad1_stit_4_4 = QPixmap("obr/priklad1_emisivita1_stit_4.png")
                self.priklad1_label.setPixmap(priklad1_stit_4_4)
                self.priklad1_label.setScaledContents(True)

    def clear_1(self):
        self.emisivita11_lineEdit.clear()
        self.emisivita12_lineEdit.clear()
        self.teplota11_lineEdit.clear()
        self.teplota12_lineEdit.clear()
        self.obsah1_lineEdit.clear()
        self.vyslednytok1_lineEdit.clear()
        self.vyslednytok2_lineEdit.clear()
        self.vyslednytok1_lineEdit_2.clear()
        self.vyslednytok2_lineEdit_2.clear()
        self.emisivita301_lineEdit.clear()
        self.emisivita302_lineEdit.clear()
        self.emisivita401_lineEdit.clear()
        self.emisivita402_lineEdit.clear()
        self.emisivita501_lineEdit.clear()
        self.emisivita502_lineEdit.clear()
        self.emisivita601_lineEdit.clear()
        self.emisivita602_lineEdit.clear()
        self.emisivita701_lineEdit.clear()
        self.emisivita702_lineEdit.clear()
        self.emisivita801_lineEdit.clear()
        self.emisivita802_lineEdit.clear()
        self.emisivita901_lineEdit.clear()
        self.emisivita902_lineEdit.clear()
        self.emisivita01_lineEdit.clear()
        self.emisivita02_lineEdit.clear()
        self.emisivita101_lineEdit.clear()
        self.emisivita102_lineEdit.clear()
        self.emisivitaN_lineEdit.clear()

    def radiacni_stit(self):
        index = self.comboBox.currentIndex()
        self.comboBox.setCurrentIndex(0)
        self.spinBox.setValue(1)
        self.spinBox2.setValue(1)
        self.spinBox3.setValue(1)
        if index == 0:
            current_visibility = self.frame.isVisible()
            self.frame.setVisible(not current_visibility)  # Kolonka pro stit
            current_visibility_2 = self.label_18.isVisible()
            self.label_18.setVisible(not current_visibility_2)  # Tok stit
            current_visibility_3 = self.gridWidget_7.isVisible()
            self.gridWidget_7.setVisible(not current_visibility_3) # Tok stit
        elif index == 1:  #
            value = self.spinBox2.value()
            if value == 1:
                current_visibility = self.frame.isVisible()
                self.frame.setVisible(not current_visibility)
                current_visibility_2 = self.label_18.isVisible()
                self.label_18.setVisible(not current_visibility_2)
                current_visibility_3 = self.gridWidget_7.isVisible()
                self.gridWidget_7.setVisible(not current_visibility_3)
            elif value == 2:
                current_visibility = self.frame.isVisible()
                self.frame.setVisible(not current_visibility)
                current_visibility_2 = self.label_18.isVisible()
                self.label_18.setVisible(not current_visibility_2)
                current_visibility_3 = self.gridWidget_7.isVisible()
                self.gridWidget_7.setVisible(not current_visibility_3)
            elif value == 3:
                current_visibility = self.frame.isVisible()
                self.frame.setVisible(not current_visibility)
                current_visibility_2 = self.label_18.isVisible()
                self.label_18.setVisible(not current_visibility_2)
                current_visibility_3 = self.gridWidget_7.isVisible()
                self.gridWidget_7.setVisible(not current_visibility_3)
            else:
                current_visibility = self.frame.isVisible()
                self.frame.setVisible(not current_visibility)
                current_visibility_2 = self.label_18.isVisible()
                self.label_18.setVisible(not current_visibility_2)
                current_visibility_3 = self.gridWidget_7.isVisible()
                self.gridWidget_7.setVisible(not current_visibility_3)
        elif index == 2:
            value = self.spinBox.value()
            if value == 1:
                current_visibility = self.frame.isVisible()
                self.frame.setVisible(not current_visibility)
                current_visibility_2 = self.label_18.isVisible()
                self.label_18.setVisible(not current_visibility_2)
                current_visibility_3 = self.gridWidget_7.isVisible()
                self.gridWidget_7.setVisible(not current_visibility_3)
            elif value == 2:
                current_visibility = self.frame.isVisible()
                self.frame.setVisible(not current_visibility)
                current_visibility_2 = self.label_18.isVisible()
                self.label_18.setVisible(not current_visibility_2)
                current_visibility_3 = self.gridWidget_7.isVisible()
                self.gridWidget_7.setVisible(not current_visibility_3)
            else:
                current_visibility = self.frame.isVisible()
                self.frame.setVisible(not current_visibility)
                current_visibility_2 = self.label_18.isVisible()
                self.label_18.setVisible(not current_visibility_2)
                current_visibility_3 = self.gridWidget_7.isVisible()
                self.gridWidget_7.setVisible(not current_visibility_3)
        elif index == 3:
            value = self.spinBox3.value()
            if value == 1:
                current_visibility = self.frame.isVisible()
                self.frame.setVisible(not current_visibility)
                current_visibility_2 = self.label_18.isVisible()
                self.label_18.setVisible(not current_visibility_2)
                current_visibility_3 = self.gridWidget_7.isVisible()
                self.gridWidget_7.setVisible(not current_visibility_3)
            elif value == 2:
                current_visibility = self.frame.isVisible()
                self.frame.setVisible(not current_visibility)
                current_visibility_2 = self.label_18.isVisible()
                self.label_18.setVisible(not current_visibility_2)
                current_visibility_3 = self.gridWidget_7.isVisible()
                self.gridWidget_7.setVisible(not current_visibility_3)
            elif value == 3:
                current_visibility = self.frame.isVisible()
                self.frame.setVisible(not current_visibility)
                current_visibility_2 = self.label_18.isVisible()
                self.label_18.setVisible(not current_visibility_2)
                current_visibility_3 = self.gridWidget_7.isVisible()
                self.gridWidget_7.setVisible(not current_visibility_3)
            else:
                current_visibility = self.frame.isVisible()
                self.frame.setVisible(not current_visibility)
                current_visibility_2 = self.label_18.isVisible()
                self.label_18.setVisible(not current_visibility_2)
                current_visibility_3 = self.gridWidget_7.isVisible()
                self.gridWidget_7.setVisible(not current_visibility_3)

    def radiacni_stit_2(self):
        index = self.comboBox_2.currentIndex()
        self.comboBox_3.setCurrentIndex(0)
        self.spinBox3_2.setValue(1)
        if index == 1:
            current_visibility = self.emisivita_stit_3.isVisible()
            self.emisivita_stit_3.setVisible(not current_visibility)  # Kolonka pro stit
            current_visibility_2 = self.label_46.isVisible()
            self.label_46.setVisible(not current_visibility_2)  # Tok stit
            current_visibility_3 = self.gridWidget_9.isVisible()
            self.gridWidget_9.setVisible(not current_visibility_3)  # Tok stit
        elif index == 2:  #
            value = self.spinBox2.value()
            current_visibility = self.emisivita_stit_3.isVisible()
            self.emisivita_stit_3.setVisible(not current_visibility)  # Kolonka pro stit
            current_visibility_2 = self.label_46.isVisible()
            self.label_46.setVisible(not current_visibility_2)  # Tok stit
            current_visibility_3 = self.gridWidget_9.isVisible()
            self.gridWidget_9.setVisible(not current_visibility_3)  # Tok stit

    def vypocet_tepelneho_toku_stit_1(self):

        combo_value = self.comboBox.currentIndex()
        value = self.spinBox.value()

        if combo_value == 2:
            # Emisivita 31
            emisivita1_str = self.emisivita11_lineEdit.text()
            emisivita2_str = self.emisivita12_lineEdit.text()
            teplota1_str = self.teplota11_lineEdit.text()
            teplota2_str = self.teplota12_lineEdit.text()
            obsah1_str = self.obsah1_lineEdit.text()

            try:
                emisivita1 = float(emisivita1_str.replace(",", "."))
                emisivita2 = float(emisivita2_str.replace(",", "."))
                teplota1 = float(teplota1_str.replace(",", "."))
                teplota2 = float(teplota2_str.replace(",", "."))
                obsah1 = float(obsah1_str.replace(",", "."))
            except ValueError:
                # Chybějící hlaseni pokud je spatne zadano
                QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                return

            if value == 1:
                # Stit
                e31_str = self.emisivita301_lineEdit.text()
                e32_str = self.emisivita302_lineEdit.text()
                try:
                    # stit
                    em_31 = float(e31_str.replace(",", "."))
                    em_32 = float(e32_str.replace(",", "."))
                except ValueError:
                    # Chybějící hlaseni pokud je spatne zadano
                    QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                    return

                # Tepelny tok pro stit s 1 stitem
                emisivita_stit_11 = 1 / (((1 / emisivita1) + (1 / emisivita2) - 1) + ((1 / em_31) + (1 / em_32) - 1))

            elif value == 2:
                # Stit
                e31_str = self.emisivita301_lineEdit.text()
                e32_str = self.emisivita302_lineEdit.text()
                e41_str = self.emisivita401_lineEdit.text()
                e42_str = self.emisivita402_lineEdit.text()
                try:
                    # stit
                    em_31 = float(e31_str.replace(",", "."))
                    em_32 = float(e32_str.replace(",", "."))
                    em_41 = float(e41_str.replace(",", "."))
                    em_42 = float(e42_str.replace(",", "."))
                except ValueError:
                    # Chybějící hlaseni pokud je spatne zadano
                    QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                    return

                # Tepelny tok pro stit s 1 stitem
                emisivita_stit_11 = 1 / (((1 / emisivita1) + (1 / emisivita2) - 1) + ((1 / em_31) + (1 / em_32) - 1) + (
                            (1 / em_41) + (1 / em_42) - 1))

            elif value == 3:
                # Stit
                e31_str = self.emisivita301_lineEdit.text()
                e32_str = self.emisivita302_lineEdit.text()
                e41_str = self.emisivita401_lineEdit.text()
                e42_str = self.emisivita402_lineEdit.text()
                e51_str = self.emisivita501_lineEdit.text()
                e52_str = self.emisivita502_lineEdit.text()
                try:
                    # stit
                    em_31 = float(e31_str.replace(",", "."))
                    em_32 = float(e32_str.replace(",", "."))
                    em_41 = float(e41_str.replace(",", "."))
                    em_42 = float(e42_str.replace(",", "."))
                    em_51 = float(e51_str.replace(",", "."))
                    em_52 = float(e52_str.replace(",", "."))
                except ValueError:
                    # Chybějící hlaseni pokud je spatne zadano
                    QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                    return

                # Tepelny tok pro stit s 1 stitem
                emisivita_stit_11 = 1 / (((1 / emisivita1) + (1 / emisivita2) - 1) + ((1 / em_31) + (1 / em_32) - 1) + (
                        (1 / em_41) + (1 / em_42) - 1) + ((1 / em_51) + (1 / em_52) - 1))

            elif value == 4:
                # Stit
                e31_str = self.emisivita301_lineEdit.text()
                e32_str = self.emisivita302_lineEdit.text()
                e41_str = self.emisivita401_lineEdit.text()
                e42_str = self.emisivita402_lineEdit.text()
                e51_str = self.emisivita501_lineEdit.text()
                e52_str = self.emisivita502_lineEdit.text()
                e61_str = self.emisivita601_lineEdit.text()
                e62_str = self.emisivita602_lineEdit.text()
                try:
                    # stit
                    em_31 = float(e31_str.replace(",", "."))
                    em_32 = float(e32_str.replace(",", "."))
                    em_41 = float(e41_str.replace(",", "."))
                    em_42 = float(e42_str.replace(",", "."))
                    em_51 = float(e51_str.replace(",", "."))
                    em_52 = float(e52_str.replace(",", "."))
                    em_61 = float(e61_str.replace(",", "."))
                    em_62 = float(e62_str.replace(",", "."))
                except ValueError:
                    # Chybějící hlaseni pokud je spatne zadano
                    QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                    return

                # Tepelny tok pro stit s 1 stitem
                emisivita_stit_11 = 1 / (((1 / emisivita1) + (1 / emisivita2) - 1) + ((1 / em_31) + (1 / em_32) - 1) + (
                        (1 / em_41) + (1 / em_42) - 1) + ((1 / em_51) + (1 / em_52) - 1) + ((1 / em_61) + (1 / em_62) - 1))

            elif value == 5:
                # Stit
                e31_str = self.emisivita301_lineEdit.text()
                e32_str = self.emisivita302_lineEdit.text()
                e41_str = self.emisivita401_lineEdit.text()
                e42_str = self.emisivita402_lineEdit.text()
                e51_str = self.emisivita501_lineEdit.text()
                e52_str = self.emisivita502_lineEdit.text()
                e61_str = self.emisivita601_lineEdit.text()
                e62_str = self.emisivita602_lineEdit.text()
                e71_str = self.emisivita701_lineEdit.text()
                e72_str = self.emisivita702_lineEdit.text()
                try:
                    # stit
                    em_31 = float(e31_str.replace(",", "."))
                    em_32 = float(e32_str.replace(",", "."))
                    em_41 = float(e41_str.replace(",", "."))
                    em_42 = float(e42_str.replace(",", "."))
                    em_51 = float(e51_str.replace(",", "."))
                    em_52 = float(e52_str.replace(",", "."))
                    em_61 = float(e61_str.replace(",", "."))
                    em_62 = float(e62_str.replace(",", "."))
                    em_71 = float(e71_str.replace(",", "."))
                    em_72 = float(e72_str.replace(",", "."))
                except ValueError:
                    # Chybějící hlaseni pokud je spatne zadano
                    QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                    return

                # Tepelny tok pro stit s 1 stitem
                emisivita_stit_11 = 1 / (((1 / emisivita1) + (1 / emisivita2) - 1) + ((1 / em_31) + (1 / em_32) - 1) + (
                        (1 / em_41) + (1 / em_42) - 1) + ((1 / em_51) + (1 / em_52) - 1) + (
                                                     (1 / em_61) + (1 / em_62) - 1) + ((1 / em_71) + (1 / em_72) - 1))

            elif value == 6:
                # Stit
                e31_str = self.emisivita301_lineEdit.text()
                e32_str = self.emisivita302_lineEdit.text()
                e41_str = self.emisivita401_lineEdit.text()
                e42_str = self.emisivita402_lineEdit.text()
                e51_str = self.emisivita501_lineEdit.text()
                e52_str = self.emisivita502_lineEdit.text()
                e61_str = self.emisivita601_lineEdit.text()
                e62_str = self.emisivita602_lineEdit.text()
                e71_str = self.emisivita701_lineEdit.text()
                e72_str = self.emisivita702_lineEdit.text()
                e81_str = self.emisivita801_lineEdit.text()
                e82_str = self.emisivita802_lineEdit.text()
                try:
                    # stit
                    em_31 = float(e31_str.replace(",", "."))
                    em_32 = float(e32_str.replace(",", "."))
                    em_41 = float(e41_str.replace(",", "."))
                    em_42 = float(e42_str.replace(",", "."))
                    em_51 = float(e51_str.replace(",", "."))
                    em_52 = float(e52_str.replace(",", "."))
                    em_61 = float(e61_str.replace(",", "."))
                    em_62 = float(e62_str.replace(",", "."))
                    em_71 = float(e71_str.replace(",", "."))
                    em_72 = float(e72_str.replace(",", "."))
                    em_81 = float(e81_str.replace(",", "."))
                    em_82 = float(e82_str.replace(",", "."))
                except ValueError:
                    # Chybějící hlaseni pokud je spatne zadano
                    QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                    return

                # Tepelny tok pro stit s 1 stitem
                emisivita_stit_11 = 1 / (((1 / emisivita1) + (1 / emisivita2) - 1) + ((1 / em_31) + (1 / em_32) - 1) + (
                        (1 / em_41) + (1 / em_42) - 1) + ((1 / em_51) + (1 / em_52) - 1) + (
                                                     (1 / em_61) + (1 / em_62) - 1) + (
                                                 (1 / em_71) + (1 / em_72) - 1) + ((1 / em_81) + (1 / em_82) - 1))

            elif value == 7:
                # Stit
                e31_str = self.emisivita301_lineEdit.text()
                e32_str = self.emisivita302_lineEdit.text()
                e41_str = self.emisivita401_lineEdit.text()
                e42_str = self.emisivita402_lineEdit.text()
                e51_str = self.emisivita501_lineEdit.text()
                e52_str = self.emisivita502_lineEdit.text()
                e61_str = self.emisivita601_lineEdit.text()
                e62_str = self.emisivita602_lineEdit.text()
                e71_str = self.emisivita701_lineEdit.text()
                e72_str = self.emisivita702_lineEdit.text()
                e81_str = self.emisivita801_lineEdit.text()
                e82_str = self.emisivita802_lineEdit.text()
                e91_str = self.emisivita901_lineEdit.text()
                e92_str = self.emisivita902_lineEdit.text()
                try:
                    # stit
                    em_31 = float(e31_str.replace(",", "."))
                    em_32 = float(e32_str.replace(",", "."))
                    em_41 = float(e41_str.replace(",", "."))
                    em_42 = float(e42_str.replace(",", "."))
                    em_51 = float(e51_str.replace(",", "."))
                    em_52 = float(e52_str.replace(",", "."))
                    em_61 = float(e61_str.replace(",", "."))
                    em_62 = float(e62_str.replace(",", "."))
                    em_71 = float(e71_str.replace(",", "."))
                    em_72 = float(e72_str.replace(",", "."))
                    em_81 = float(e81_str.replace(",", "."))
                    em_82 = float(e82_str.replace(",", "."))
                    em_91 = float(e91_str.replace(",", "."))
                    em_92 = float(e92_str.replace(",", "."))
                except ValueError:
                    # Chybějící hlaseni pokud je spatne zadano
                    QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                    return

                # Tepelny tok pro stit s 1 stitem
                emisivita_stit_11 = 1 / (((1 / emisivita1) + (1 / emisivita2) - 1) + ((1 / em_31) + (1 / em_32) - 1) + (
                        (1 / em_41) + (1 / em_42) - 1) + ((1 / em_51) + (1 / em_52) - 1) + (
                                                     (1 / em_61) + (1 / em_62) - 1) + (
                                                 (1 / em_71) + (1 / em_72) - 1) + ((1 / em_81) + (1 / em_82) - 1) + (
                                                 (1 / em_91) + (1 / em_92) - 1))

            elif value == 8:
                # Stit
                e31_str = self.emisivita301_lineEdit.text()
                e32_str = self.emisivita302_lineEdit.text()
                e41_str = self.emisivita401_lineEdit.text()
                e42_str = self.emisivita402_lineEdit.text()
                e51_str = self.emisivita501_lineEdit.text()
                e52_str = self.emisivita502_lineEdit.text()
                e61_str = self.emisivita601_lineEdit.text()
                e62_str = self.emisivita602_lineEdit.text()
                e71_str = self.emisivita701_lineEdit.text()
                e72_str = self.emisivita702_lineEdit.text()
                e81_str = self.emisivita801_lineEdit.text()
                e82_str = self.emisivita802_lineEdit.text()
                e91_str = self.emisivita901_lineEdit.text()
                e92_str = self.emisivita902_lineEdit.text()
                e10_str = self.emisivita01_lineEdit.text()
                e11_str = self.emisivita02_lineEdit.text()
                try:
                    # stit
                    em_31 = float(e31_str.replace(",", "."))
                    em_32 = float(e32_str.replace(",", "."))
                    em_41 = float(e41_str.replace(",", "."))
                    em_42 = float(e42_str.replace(",", "."))
                    em_51 = float(e51_str.replace(",", "."))
                    em_52 = float(e52_str.replace(",", "."))
                    em_61 = float(e61_str.replace(",", "."))
                    em_62 = float(e62_str.replace(",", "."))
                    em_71 = float(e71_str.replace(",", "."))
                    em_72 = float(e72_str.replace(",", "."))
                    em_81 = float(e81_str.replace(",", "."))
                    em_82 = float(e82_str.replace(",", "."))
                    em_91 = float(e91_str.replace(",", "."))
                    em_92 = float(e92_str.replace(",", "."))
                    em_10 = float(e10_str.replace(",", "."))
                    em_11 = float(e11_str.replace(",", "."))
                except ValueError:
                    # Chybějící hlaseni pokud je spatne zadano
                    QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                    return

                # Tepelny tok pro stit s 1 stitem
                emisivita_stit_11 = 1 / (((1 / emisivita1) + (1 / emisivita2) - 1) + ((1 / em_31) + (1 / em_32) - 1) + (
                        (1 / em_41) + (1 / em_42) - 1) + ((1 / em_51) + (1 / em_52) - 1) + (
                                                     (1 / em_61) + (1 / em_62) - 1) + (
                                                 (1 / em_71) + (1 / em_72) - 1) + ((1 / em_81) + (1 / em_82) - 1) + (
                                                 (1 / em_91) + (1 / em_92) - 1) + ((1 / em_10) + (1 / em_11) - 1))

            elif value == 9:
                # Stit
                e31_str = self.emisivita301_lineEdit.text()
                e32_str = self.emisivita302_lineEdit.text()
                e41_str = self.emisivita401_lineEdit.text()
                e42_str = self.emisivita402_lineEdit.text()
                e51_str = self.emisivita501_lineEdit.text()
                e52_str = self.emisivita502_lineEdit.text()
                e61_str = self.emisivita601_lineEdit.text()
                e62_str = self.emisivita602_lineEdit.text()
                e71_str = self.emisivita701_lineEdit.text()
                e72_str = self.emisivita702_lineEdit.text()
                e81_str = self.emisivita801_lineEdit.text()
                e82_str = self.emisivita802_lineEdit.text()
                e91_str = self.emisivita901_lineEdit.text()
                e92_str = self.emisivita902_lineEdit.text()
                e10_str = self.emisivita01_lineEdit.text()
                e11_str = self.emisivita02_lineEdit.text()
                e01_str = self.emisivita101_lineEdit.text()
                e02_str = self.emisivita102_lineEdit.text()
                try:
                    # stit
                    em_31 = float(e31_str.replace(",", "."))
                    em_32 = float(e32_str.replace(",", "."))
                    em_41 = float(e41_str.replace(",", "."))
                    em_42 = float(e42_str.replace(",", "."))
                    em_51 = float(e51_str.replace(",", "."))
                    em_52 = float(e52_str.replace(",", "."))
                    em_61 = float(e61_str.replace(",", "."))
                    em_62 = float(e62_str.replace(",", "."))
                    em_71 = float(e71_str.replace(",", "."))
                    em_72 = float(e72_str.replace(",", "."))
                    em_81 = float(e81_str.replace(",", "."))
                    em_82 = float(e82_str.replace(",", "."))
                    em_91 = float(e91_str.replace(",", "."))
                    em_92 = float(e92_str.replace(",", "."))
                    em_10 = float(e10_str.replace(",", "."))
                    em_11 = float(e11_str.replace(",", "."))
                    em_01 = float(e01_str.replace(",", "."))
                    em_02 = float(e02_str.replace(",", "."))
                except ValueError:
                    # Chybějící hlaseni pokud je spatne zadano
                    QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                    return

                # Tepelny tok pro stit s 1 stitem
                emisivita_stit_11 = 1 / (((1 / emisivita1) + (1 / emisivita2) - 1) + ((1 / em_31) + (1 / em_32) - 1) + (
                        (1 / em_41) + (1 / em_42) - 1) + ((1 / em_51) + (1 / em_52) - 1) + (
                                                     (1 / em_61) + (1 / em_62) - 1) + (
                                                 (1 / em_71) + (1 / em_72) - 1) + ((1 / em_81) + (1 / em_82) - 1) + (
                                                 (1 / em_91) + (1 / em_92) - 1) + ((1 / em_10) + (1 / em_11) - 1) + (
                                                     (1 / em_01) + (1 / em_02) - 1))

            combo_value_t1 = self.comboBox_CK_1.currentIndex()
            if combo_value_t1 == 0:  # °C
                T1 = teplota1 + 273.15
                T2 = teplota2 + 273.15
            elif combo_value_t1 == 1:  # K
                T1 = teplota1
                T2 = teplota2
            q_stit = emisivita_stit_11 * sigma * (T1 ** 4 - T2 ** 4)
            Q_stit = emisivita_stit_11 * sigma * obsah1 * (T1 ** 4 - T2 ** 4)

            emisivita = 1 / ((1 / emisivita1) + (1 / emisivita2) - 1)
            q_bezstitu = emisivita * sigma * (T1 ** 4 - T2 ** 4)
            Q_bezstitu = emisivita * sigma * obsah1 * (T1 ** 4 - T2 ** 4)

            # Vypocet bez stitu
            self.vyslednytok1_lineEdit_2.setText('{:.3f}'.format(q_stit))
            self.vyslednytok2_lineEdit_2.setText('{:.3f}'.format(Q_stit))
            self.vyslednytok1_lineEdit.setText('{:.3f}'.format(q_bezstitu))
            self.vyslednytok2_lineEdit.setText('{:.3f}'.format(Q_bezstitu))

        elif combo_value == 1:
            # Emisivita 31
            spinbox2_value = self.spinBox2.value()
            emisivita1_str = self.emisivita11_lineEdit.text()
            emisivita2_str = self.emisivita12_lineEdit.text()
            teplota1_str = self.teplota11_lineEdit.text()
            teplota2_str = self.teplota12_lineEdit.text()
            obsah1_str = self.obsah1_lineEdit.text()
            emisivitan_str = self.emisivitaN_lineEdit.text()

            try:
                emisivita1 = float(emisivita1_str.replace(",", "."))
                emisivita2 = float(emisivita2_str.replace(",", "."))
                emisivitan = float(emisivitan_str.replace(",", "."))
                teplota1 = float(teplota1_str.replace(",", "."))
                teplota2 = float(teplota2_str.replace(",", "."))
                obsah1 = float(obsah1_str.replace(",", "."))
            except ValueError:
                # Chybějící hlaseni pokud je spatne zadano
                QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                return


            combo_value_t2 = self.comboBox_CK_1.currentIndex()
            if combo_value_t2 == 0:  # °C
                T1 = teplota1 + 273.15
                T2 = teplota2 + 273.15
            elif combo_value_t2 == 1:  # K
                T1 = teplota1
                T2 = teplota2

            emisivita_stit_n = 1 / ((((1 / emisivita1) + (1 / emisivita2)) - 1) + spinbox2_value * ((1 / emisivitan) + (1 / emisivitan) - 1))
            q_stit = emisivita_stit_n * sigma * (T1 ** 4 - T2 ** 4)
            Q_stit = emisivita_stit_n * sigma * obsah1 * (T1 ** 4 - T2 ** 4)
            self.vyslednytok1_lineEdit_2.setText('{:.3f}'.format(q_stit))
            self.vyslednytok2_lineEdit_2.setText('{:.3f}'.format(Q_stit))
            # Bez stitu
            emisivita = 1 / ((1 / emisivita1) + (1 / emisivita2) - 1)
            q_bezstitu = emisivita * sigma * (T1 ** 4 - T2 ** 4)
            Q_bezstitu = emisivita * sigma * obsah1 * (T1 ** 4 - T2 ** 4)
            self.vyslednytok1_lineEdit.setText('{:.3f}'.format(q_bezstitu))
            self.vyslednytok2_lineEdit.setText('{:.3f}'.format(Q_bezstitu))

        elif combo_value == 3:
            # Emisivita 31
            spinbox3_value = self.spinBox3.value()
            emisivita1_str = self.emisivita11_lineEdit.text()
            emisivita2_str = self.emisivita12_lineEdit.text()
            teplota1_str = self.teplota11_lineEdit.text()
            teplota2_str = self.teplota12_lineEdit.text()
            obsah1_str = self.obsah1_lineEdit.text()

            try:
                emisivita1 = float(emisivita1_str.replace(",", "."))
                emisivita2 = float(emisivita2_str.replace(",", "."))
                teplota1 = float(teplota1_str.replace(",", "."))
                teplota2 = float(teplota2_str.replace(",", "."))
                obsah1 = float(obsah1_str.replace(",", "."))
            except ValueError:
                # Chybějící hlaseni pokud je spatne zadano
                QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                return

            combo_value_t3 = self.comboBox_CK_1.currentIndex()
            if combo_value_t3 == 0:  # °C
                T1 = teplota1 + 273.15
                T2 = teplota2 + 273.15
            elif combo_value_t3 == 1:  # K
                T1 = teplota1
                T2 = teplota2

            emisivita_stit2 = 1 / (((1 / emisivita1) + (1 / emisivita1) - 1) * (spinbox3_value + 1))
            q_stit = emisivita_stit2 * sigma * (T1 ** 4 - T2 ** 4)
            Q_stit = emisivita_stit2 * sigma * obsah1 * (T1 ** 4 - T2 ** 4)
            self.vyslednytok1_lineEdit_2.setText('{:.3f}'.format(q_stit))
            self.vyslednytok2_lineEdit_2.setText('{:.3f}'.format(Q_stit))

            emisivita = 1 / ((1 / emisivita1) + (1 / emisivita2) - 1)
            q_bezstitu = emisivita * sigma * (T1 ** 4 - T2 ** 4)
            Q_bezstitu = emisivita * sigma * obsah1 * (T1 ** 4 - T2 ** 4)
            self.vyslednytok1_lineEdit.setText('{:.3f}'.format(q_bezstitu))
            self.vyslednytok2_lineEdit.setText('{:.3f}'.format(Q_bezstitu))

        elif combo_value == 0:
            emisivita1_str = self.emisivita11_lineEdit.text()
            emisivita2_str = self.emisivita12_lineEdit.text()
            teplota1_str = self.teplota11_lineEdit.text()
            teplota2_str = self.teplota12_lineEdit.text()
            obsah1_str = self.obsah1_lineEdit.text()

            try:
                emisivita1 = float(emisivita1_str.replace(",", "."))
                emisivita2 = float(emisivita2_str.replace(",", "."))
                teplota1 = float(teplota1_str.replace(",", "."))
                teplota2 = float(teplota2_str.replace(",", "."))
                obsah1 = float(obsah1_str.replace(",", "."))

            except ValueError:
                # Chybějící hlaseni pokud je spatne zadano
                QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                return

            # Calculate radiation heat transfer
            emisivita = 1 / ((1 / emisivita1) + (1 / emisivita2) - 1)
            combo_value_t4 = self.comboBox_CK_1.currentIndex()
            if combo_value_t4 == 0:  # °C
                T1 = teplota1 + 273.15
                T2 = teplota2 + 273.15
            elif combo_value_t4 == 1:  # K
                T1 = teplota1
                T2 = teplota2
            q = emisivita * sigma * (T1 ** 4 - T2 ** 4)
            Q = emisivita * sigma * obsah1 * (T1 ** 4 - T2 ** 4)
            self.vyslednytok1_lineEdit.setText('{:.3f}'.format(q))
            self.vyslednytok2_lineEdit.setText('{:.3f}'.format(Q))

    def help_window(self):
        if self.hidden:
            self.edit.show()
            self.hidden = False
        else:
            self.edit.hide()
            self.hidden = True

    def priklad1_dosad(self):
        self.emisivita11_lineEdit.setText("0.61")
        self.emisivita12_lineEdit.setText("0.93")
        self.teplota11_lineEdit.setText("105")
        self.teplota12_lineEdit.setText("22")
        self.obsah1_lineEdit.setText("1.8")

    def clear_2(self):
        self.emisivita21_lineEdit.clear()
        self.emisivita22_lineEdit.clear()
        self.teplota21_lineEdit.clear()
        self.teplota22_lineEdit.clear()
        self.obsah21_lineEdit.clear()
        self.obsah22_lineEdit.clear()
        self.vyslednytok21_lineEdit.clear()
        self.vyslednytok22_lineEdit.clear()
        self.emisivita21_lineEdit_2.clear()
        self.emisivita22_lineEdit_2.clear()
        self.teplota21_lineEdit_2.clear()
        self.teplota22_lineEdit_2.clear()
        self.polomer21_lineEdit_2.clear()
        self.polomer22_lineEdit_2.clear()
        self.emisivita21_lineEdit_4.clear()
        self.emisivita22_lineEdit_4.clear()
        self.teplota21_lineEdit_4.clear()
        self.teplota22_lineEdit_4.clear()
        self.polomer21_lineEdit_4.clear()
        self.polomer22_lineEdit_4.clear()
        self.L21_lineEdit_4.clear()

    def comboBox2_zmena(self):
        index = self.comboBox_2.currentIndex()
        index_2 = self.comboBox_3.currentIndex()
        if index == 0:
            self.gridWidget_8.setVisible(True)
            self.gridFrame_10.setVisible(False)
            self.gridFrame_11.setVisible(False)
            self.stit_pushButton_2.setVisible(False)
            obecne = QPixmap("obr/obecnytest.png")
            self.priklad3_label.setPixmap(obecne)
            self.priklad3_label.setScaledContents(True)
            self.emisivita32.setVisible(False)
            self.emisivita42.setVisible(False)
            self.emisivita52.setVisible(False)
            self.emisivita_stit_3.setVisible(False)
            self.label_46.setVisible(False)
            self.gridWidget_9.setVisible(False)

        elif index == 1:
            if index_2 == 0:
                self.gridFrame_10.setVisible(True)
                self.stit_pushButton_2.setVisible(True)
                self.gridWidget_8.setVisible(False)
                self.gridFrame_11.setVisible(False)
                self.emisivita32.setVisible(False)
                self.emisivita42.setVisible(False)
                self.emisivita52.setVisible(False)
                koule = QPixmap("obr/koulevkouliv2.png")
                self.priklad3_label.setPixmap(koule)
                self.priklad3_label.setScaledContents(True)
            else:
                value = self.spinBox3_2.value()
                if value == 1:  # koule
                    priklad3_stit_1 = QPixmap("obr/koulevkouli1v2.png")
                    self.priklad3_label.setPixmap(priklad3_stit_1)
                    self.priklad3_label.setScaledContents(True)
                    self.emisivita32.setVisible(True)
                    self.emisivita42.setVisible(False)
                    self.emisivita52.setVisible(False)
                elif value == 2:
                    priklad3_stit_2 = QPixmap("obr/koulevkouli2v2.png")
                    self.priklad3_label.setPixmap(priklad3_stit_2)
                    self.priklad3_label.setScaledContents(True)
                    self.emisivita32.setVisible(True)
                    self.emisivita42.setVisible(True)
                    self.emisivita52.setVisible(False)
                elif value == 3:
                    priklad3_stit_3 = QPixmap("obr/koulevkouli3v3.png")
                    self.priklad3_label.setPixmap(priklad3_stit_3)
                    self.priklad3_label.setScaledContents(True)
                    self.emisivita32.setVisible(True)
                    self.emisivita42.setVisible(True)
                    self.emisivita52.setVisible(True)

        elif index == 2:
            if index_2 == 0:
                self.gridFrame_11.setVisible(True)
                self.stit_pushButton_2.setVisible(True)
                self.gridFrame_10.setVisible(False)
                self.gridWidget_8.setVisible(False)
                valec = QPixmap("obr/valecv2.png")
                self.priklad3_label.setPixmap(valec)
                self.priklad3_label.setScaledContents(True)
                self.emisivita32.setVisible(False)
                self.emisivita42.setVisible(False)
                self.emisivita52.setVisible(False)
            else:
                value = self.spinBox3_2.value()
                if value == 1:
                    priklad3_stit_11 = QPixmap("obr/valec_stit_1v2.png")
                    self.priklad3_label.setPixmap(priklad3_stit_11)
                    self.priklad3_label.setScaledContents(True)
                    self.emisivita32.setVisible(True)
                    self.emisivita42.setVisible(False)
                    self.emisivita52.setVisible(False)
                elif value == 2:
                    priklad3_stit_22 = QPixmap("obr/valec_stit_2v2.png")
                    self.priklad3_label.setPixmap(priklad3_stit_22)
                    self.priklad3_label.setScaledContents(True)
                    self.emisivita32.setVisible(True)
                    self.emisivita42.setVisible(True)
                    self.emisivita52.setVisible(False)
                elif value == 3:
                    priklad3_stit_33 = QPixmap("obr/valec_stit_3v2.png")
                    self.priklad3_label.setPixmap(priklad3_stit_33)
                    self.priklad3_label.setScaledContents(True)
                    self.emisivita32.setVisible(True)
                    self.emisivita42.setVisible(True)
                    self.emisivita52.setVisible(True)

    def vypocet_tepelneho_toku_2(self):
        combo_value_2 = self.comboBox_2.currentIndex()
        combo_value_3 = self.comboBox_3.currentIndex()
        value = self.spinBox3_2.value()

        if combo_value_2 == 0:  # Obecny
            emisivita21_str = self.emisivita21_lineEdit.text()
            emisivita22_str = self.emisivita22_lineEdit.text()
            teplota21_str = self.teplota21_lineEdit.text()
            teplota22_str = self.teplota22_lineEdit.text()
            obsah21_str = self.obsah21_lineEdit.text()
            obsah22_str = self.obsah22_lineEdit.text()

            try:
                emisivita21 = float(emisivita21_str.replace(",", "."))
                emisivita22 = float(emisivita22_str.replace(",", "."))
                teplota21 = float(teplota21_str.replace(",", "."))
                teplota22 = float(teplota22_str.replace(",", "."))
                obsah21 = float(obsah21_str.replace(",", "."))
                obsah22 = float(obsah22_str.replace(",", "."))
            except ValueError:
                # Chybějící hlaseni pokud je spatne zadano
                QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                return


            # Calculate radiation heat transfer
            emisivita2 = 1 / ((1 / emisivita21) + (obsah21 / obsah22) * ((1 / emisivita22) - 1))
            combo_value_31 = self.comboBox_CK_21.currentIndex()
            if combo_value_31 == 0:  # °C
                T2_1 = teplota21 + 273.15
                T2_2 = teplota22 + 273.15
            elif combo_value_31 == 1:  # K
                T2_1 = teplota21
                T2_2 = teplota22
            q2 = emisivita2 * sigma * (T2_1 ** 4 - T2_2 ** 4)
            Q2 = emisivita2 * sigma * obsah21 * (T2_1 ** 4 - T2_2 ** 4)
            self.vyslednytok21_lineEdit.setText('{:.3f}'.format(q2))
            self.vyslednytok22_lineEdit.setText('{:.3f}'.format(Q2))

        elif combo_value_2 == 1:   # Koule
            emisivita21_str = self.emisivita21_lineEdit_2.text()
            emisivita22_str = self.emisivita22_lineEdit_2.text()
            teplota21_str = self.teplota21_lineEdit_2.text()
            teplota22_str = self.teplota22_lineEdit_2.text()
            r21_str = self.polomer21_lineEdit_2.text()
            r22_str = self.polomer22_lineEdit_2.text()

            try:
                emisivita21 = float(emisivita21_str.replace(",", "."))
                emisivita22 = float(emisivita22_str.replace(",", "."))
                teplota21 = float(teplota21_str.replace(",", "."))
                teplota22 = float(teplota22_str.replace(",", "."))
                r21 = float(r21_str.replace(",", "."))
                r22 = float(r22_str.replace(",", "."))
            except ValueError:
                # Chybějící hlaseni pokud je spatne zadano
                QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                return

            if combo_value_3 == 2:
                if value == 1:
                    # Stit
                    e31_str = self.emisivita301_lineEdit_2.text()
                    e32_str = self.emisivita302_lineEdit_2.text()
                    r31_str = self.polomer3_lineEdit.text()
                    try:
                        # stit
                        em_31 = float(e31_str.replace(",", "."))
                        em_32 = float(e32_str.replace(",", "."))
                        r_33 = float(r31_str.replace(",", "."))
                    except ValueError:
                        # Chybějící hlaseni pokud je spatne zadano
                        QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                        return

                    # Tepelny tok pro stit s 1 stitem
                    s1 = 4 * pi * (r21 ** 2)
                    s2 = 4 * pi * (r22 ** 2)
                    s3 = 4 * pi * (r_33 ** 2)
                    emisivita2_stit = 1 / (((1 - emisivita21) / (s1 * emisivita21)) + (1 / s1) +
                                           ((1 - em_31) / (s3 * em_31)) + ((1 - em_32) / (s3 * em_32)) + (1 / s3) +
                                           ((1 - emisivita22) / (s2 * emisivita22)))

                elif value == 2:
                    # Stit
                    e31_str = self.emisivita301_lineEdit_2.text()
                    e32_str = self.emisivita302_lineEdit_2.text()
                    e41_str = self.emisivita401_lineEdit_2.text()
                    e42_str = self.emisivita402_lineEdit_2.text()
                    r31_str = self.polomer3_lineEdit.text()
                    r44_str = self.polomer4_lineEdit.text()
                    try:
                        # stit
                        em_31 = float(e31_str.replace(",", "."))
                        em_32 = float(e32_str.replace(",", "."))
                        em_41 = float(e41_str.replace(",", "."))
                        em_42 = float(e42_str.replace(",", "."))
                        r_33 = float(r31_str.replace(",", "."))
                        r_44 = float(r44_str.replace(",", "."))
                    except ValueError:
                        # Chybějící hlaseni pokud je spatne zadano
                        QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                        return

                    # Tepelny tok pro stit s 1 stitem
                    s1 = 4 * pi * (r21 ** 2)
                    s2 = 4 * pi * (r22 ** 2)
                    s3 = 4 * pi * (r_33 ** 2)
                    s4 = 4 * pi * (r_44 ** 2)
                    emisivita2_stit = 1 / (((1 - emisivita21) / (s1 * emisivita21)) + (1 / s1) +
                                           ((1 - em_31) / (s3 * em_31)) + ((1 - em_32) / s3 * em_32) + (1 / s3) +
                                           ((1 - em_41) / (s4 * em_41)) + ((1 - em_42) / (s4 * em_42)) + (1 / s4) +
                                           ((1 - emisivita22) / (s2 * emisivita22)))

                elif value == 3:
                    # Stit
                    e31_str = self.emisivita301_lineEdit_2.text()
                    e32_str = self.emisivita302_lineEdit_2.text()
                    e41_str = self.emisivita401_lineEdit_2.text()
                    e42_str = self.emisivita402_lineEdit_2.text()
                    e51_str = self.emisivita501_lineEdit_2.text()
                    e52_str = self.emisivita502_lineEdit_2.text()
                    r33_str = self.polomer3_lineEdit.text()
                    r44_str = self.polomer4_lineEdit.text()
                    r55_str = self.polomer5_lineEdit.text()
                    try:
                        # stit
                        em_31 = float(e31_str.replace(",", "."))
                        em_32 = float(e32_str.replace(",", "."))
                        em_41 = float(e41_str.replace(",", "."))
                        em_42 = float(e42_str.replace(",", "."))
                        em_51 = float(e51_str.replace(",", "."))
                        em_52 = float(e52_str.replace(",", "."))
                        r_33 = float(r33_str.replace(",", "."))
                        r_44 = float(r44_str.replace(",", "."))
                        r_55 = float(r55_str.replace(",", "."))
                    except ValueError:
                        # Chybějící hlaseni pokud je spatne zadano
                        QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                        return

                    # Tepelny tok pro stit s 1 stitem
                    s1 = 4 * pi * (r21 ** 2)
                    s2 = 4 * pi * (r22 ** 2)
                    s3 = 4 * pi * (r_33 ** 2)
                    s4 = 4 * pi * (r_44 ** 2)
                    s5 = 4 * pi * (r_55 ** 2)
                    emisivita2_stit = 1 / (((1 - emisivita21) / (s1 * emisivita22)) + (1 / s1) +
                                           ((1 - em_31) / (s3 * em_31)) + ((1 - em_32) / (s3 * em_32)) + (1 / s3) +
                                           ((1 - em_41) / (s4 * em_41)) + ((1 - em_42) / (s4 * em_42)) + (1 / s4) +
                                           ((1 - em_51) / (s5 * em_51)) + ((1 - em_52) / (s5 * em_52)) + (1 / s5) +
                                           ((1 - emisivita22) / (s2 * emisivita22)))

                # Calculate radiation heat transfer
                emisivita2 = 1 / ((1 / emisivita21) + (((1 - emisivita22) / emisivita22) * ((r21 / r22) ** 2)))
                combo_value_32 = self.comboBox_CK_22.currentIndex()
                if combo_value_32 == 0:  # °C
                    T2_1 = teplota21 + 273.15
                    T2_2 = teplota22 + 273.15
                elif combo_value_32 == 1:  # K
                    T2_1 = teplota21
                    T2_2 = teplota22

                obsah21 = 4 * pi * (r21 ** 2)

                q2 = emisivita2 * sigma * (T2_1 ** 4 - T2_2 ** 4)
                Q2 = emisivita2 * sigma * obsah21 * (T2_1 ** 4 - T2_2 ** 4)

                q2_stit = emisivita2_stit * sigma * (T2_1 ** 4 - T2_2 ** 4)
                Q2_stit = emisivita2_stit * sigma * obsah21 * (T2_1 ** 4 - T2_2 ** 4)


                self.vyslednytok21_lineEdit.setText('{:.3f}'.format(q2))
                self.vyslednytok22_lineEdit.setText('{:.3f}'.format(Q2))
                self.vyslednytok1_lineEdit_3.setText('{:.3f}'.format(q2_stit))
                self.vyslednytok2_lineEdit_3.setText('{:.3f}'.format(Q2_stit))

            elif combo_value_3 == 0:
                # Calculate radiation heat transfer
                emisivita2 = 1 / ((1 / emisivita21) + (((1 - emisivita22) / emisivita22) * ((r21 / r22) ** 2)))
                combo_value_32 = self.comboBox_CK_22.currentIndex()
                if combo_value_32 == 0:  # °C
                    T2_1 = teplota21 + 273.15
                    T2_2 = teplota22 + 273.15
                elif combo_value_32 == 1:  # K
                    T2_1 = teplota21
                    T2_2 = teplota22

                obsah21 = 4 * pi * (r21 ** 2)

                q2 = emisivita2 * sigma * (T2_1 ** 4 - T2_2 ** 4)
                Q2 = emisivita2 * sigma * obsah21 * (T2_1 ** 4 - T2_2 ** 4)

                self.vyslednytok21_lineEdit.setText('{:.3f}'.format(q2))
                self.vyslednytok22_lineEdit.setText('{:.3f}'.format(Q2))

        elif combo_value_2 == 2:  # Valec
            emisivita21_str = self.emisivita21_lineEdit_4.text()
            emisivita22_str = self.emisivita22_lineEdit_4.text()
            teplota21_str = self.teplota21_lineEdit_4.text()
            teplota22_str = self.teplota22_lineEdit_4.text()
            r21_str = self.polomer21_lineEdit_4.text()
            r22_str = self.polomer22_lineEdit_4.text()
            l21_str = self.L21_lineEdit_4.text()

            try:
                emisivita21 = float(emisivita21_str.replace(",", "."))
                emisivita22 = float(emisivita22_str.replace(",", "."))
                teplota21 = float(teplota21_str.replace(",", "."))
                teplota22 = float(teplota22_str.replace(",", "."))
                l21 = float(l21_str.replace(",", "."))
                r21 = float(r21_str.replace(",", "."))
                r22 = float(r22_str.replace(",", "."))
            except ValueError:
                # Chybějící hlaseni pokud je spatne zadano
                QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                return

            if combo_value_3 == 2:
                if value == 1:
                    # Stit
                    e31_str = self.emisivita301_lineEdit_2.text()
                    e32_str = self.emisivita302_lineEdit_2.text()
                    r31_str = self.polomer3_lineEdit.text()
                    try:
                        # stit
                        em_31 = float(e31_str.replace(",", "."))
                        em_32 = float(e32_str.replace(",", "."))
                        r33 = float(r31_str.replace(",", "."))
                    except ValueError:
                        # Chybějící hlaseni pokud je spatne zadano
                        QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                        return

                    # Tepelny tok pro stit s 1 stitem
                    s1 = 2 * pi * r21 * l21
                    s2 = 2 * pi * r22 * l21
                    s3 = 2 * pi * r33 * l21
                    emisivita2_stit = 1 / (((1 - emisivita21) / (s1 * emisivita21)) + (1 / s1) +
                                           ((1 - em_31) / (s3 * em_31)) + ((1 - em_32) / (s3 * em_32)) + (1 / s3) +
                                           ((1 - emisivita22) / (s2 * emisivita22)))

                elif value == 2:
                    # Stit
                    e31_str = self.emisivita301_lineEdit_2.text()
                    e32_str = self.emisivita302_lineEdit_2.text()
                    e41_str = self.emisivita401_lineEdit_2.text()
                    e42_str = self.emisivita402_lineEdit_2.text()
                    r31_str = self.polomer3_lineEdit.text()
                    r44_str = self.polomer4_lineEdit.text()
                    try:
                        # stit
                        em_31 = float(e31_str.replace(",", "."))
                        em_32 = float(e32_str.replace(",", "."))
                        em_41 = float(e41_str.replace(",", "."))
                        em_42 = float(e42_str.replace(",", "."))
                        r_33 = float(r31_str.replace(",", "."))
                        r_44 = float(r44_str.replace(",", "."))
                    except ValueError:
                        # Chybějící hlaseni pokud je spatne zadano
                        QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                        return

                    # Tepelny tok pro stit s 1 stitem
                    s1 = 2 * pi * r21 * l21
                    s2 = 2 * pi * r22 * l21
                    s3 = 2 * pi * r_33 * l21
                    s4 = 2 * pi * r_44 * l21
                    emisivita2_stit = 1 / (((1 - emisivita21) / (s1 * emisivita21)) + (1 / s1) +
                                           ((1 - em_31) / (s3 * em_31)) + ((1 - em_32) / (s3 * em_32)) + (1 / s3) +
                                           ((1 - em_41) / (s4 * em_41)) + ((1 - em_42) / (s4 * em_42)) + (1 / s4) +
                                           ((1 - emisivita22) / (s2 * emisivita22)))

                elif value == 3:
                    # Stit
                    e31_str = self.emisivita301_lineEdit_2.text()
                    e32_str = self.emisivita302_lineEdit_2.text()
                    e41_str = self.emisivita401_lineEdit_2.text()
                    e42_str = self.emisivita402_lineEdit_2.text()
                    e51_str = self.emisivita501_lineEdit_2.text()
                    e52_str = self.emisivita502_lineEdit_2.text()
                    r33_str = self.polomer3_lineEdit.text()
                    r44_str = self.polomer4_lineEdit.text()
                    r55_str = self.polomer5_lineEdit.text()
                    try:
                        # stit
                        em_31 = float(e31_str.replace(",", "."))
                        em_32 = float(e32_str.replace(",", "."))
                        em_41 = float(e41_str.replace(",", "."))
                        em_42 = float(e42_str.replace(",", "."))
                        em_51 = float(e51_str.replace(",", "."))
                        em_52 = float(e52_str.replace(",", "."))
                        r_33 = float(r33_str.replace(",", "."))
                        r_44 = float(r44_str.replace(",", "."))
                        r_55 = float(r55_str.replace(",", "."))
                    except ValueError:
                        # Chybějící hlaseni pokud je spatne zadano
                        QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
                        return

                    # Tepelny tok pro stit s 1 stitem
                    s1 = 2 * pi * r21 * l21
                    s2 = 2 * pi * r22 * l21
                    s3 = 2 * pi * r_33 * l21
                    s4 = 2 * pi * r_44 * l21
                    s5 = 2 * pi * r_55 * l21
                    emisivita2_stit = 1 / (((1 - emisivita21) / (s1 * emisivita21)) + (1 / s1) +
                                           ((1 - em_31) / (s3 * em_31)) + (1 - em_32) / (s3 * em_32) + (1 / s3) +
                                           ((1 - em_41) / (s4 * em_41)) + (1 - em_42) / (s4 * em_42) + (1 / s4) +
                                           ((1 - em_51) / (s5 * em_51)) + (1 - em_52) / (s5 * em_52) + (1 / s5) +
                                           ((1 - emisivita22) / (s2 * emisivita22)))

                # Calculate radiation heat transfer
                emisivita2 = 1 / ((1 / emisivita21) + (((1 - emisivita22) / emisivita22) * (r21 / r22)))
                combo_value_33 = self.comboBox_CK_23.currentIndex()
                if combo_value_33 == 0:  # °C
                    T2_1 = teplota21 + 273.15
                    T2_2 = teplota22 + 273.15
                elif combo_value_33 == 1:  # K
                    T2_1 = teplota21
                    T2_2 = teplota22
                obsahplaste12 = 2 * pi * r21 * l21
                q2 = emisivita2 * sigma * (T2_1 ** 4 - T2_2 ** 4)
                Q2 = emisivita2 * sigma * obsahplaste12 * (T2_1 ** 4 - T2_2 ** 4)
                self.vyslednytok21_lineEdit.setText('{:.3f}'.format(q2))
                self.vyslednytok22_lineEdit.setText('{:.3f}'.format(Q2))

                q2_stit = emisivita2_stit * sigma * (T2_1 ** 4 - T2_2 ** 4)
                Q2_stit = emisivita2_stit * sigma * obsahplaste12 * (T2_1 ** 4 - T2_2 ** 4)

                self.vyslednytok1_lineEdit_3.setText('{:.3f}'.format(q2_stit))
                self.vyslednytok2_lineEdit_3.setText('{:.3f}'.format(Q2_stit))

            elif combo_value_3 == 0:
                # Calculate radiation heat transfer
                emisivita2 = 1 / ((1 / emisivita21) + (((1 - emisivita22) / emisivita22) * (r21 / r22)))
                combo_value_33 = self.comboBox_CK_23.currentIndex()
                if combo_value_33 == 0:  # °C
                    T2_1 = teplota21 + 273.15
                    T2_2 = teplota22 + 273.15
                elif combo_value_33 == 1:  # K
                    T2_1 = teplota21
                    T2_2 = teplota22
                obsahplaste12 = 2 * pi * r21 * l21
                q2 = emisivita2 * sigma * (T2_1 ** 4 - T2_2 ** 4)
                Q2 = emisivita2 * sigma * obsahplaste12 * (T2_1 ** 4 - T2_2 ** 4)
                self.vyslednytok21_lineEdit.setText('{:.3f}'.format(q2))
                self.vyslednytok22_lineEdit.setText('{:.3f}'.format(Q2))

    def help_window_2(self):
        if self.hidden:
            self.edit_2.show()
            self.hidden = False
        else:
            self.edit_2.hide()
            self.hidden = True

    def priklad2_dosad(self):
        index = self.comboBox_2.currentIndex()
        if index == 0:
            self.emisivita21_lineEdit.setText("0.5")
            self.emisivita22_lineEdit.setText("0.9")
            self.teplota21_lineEdit.setText("150")
            self.teplota22_lineEdit.setText("15")
            self.obsah21_lineEdit.setText("3.08")
            self.obsah22_lineEdit.setText("70")
        elif index == 1:
            self.emisivita21_lineEdit_2.setText("0.5")
            self.emisivita22_lineEdit_2.setText("0.9")
            self.teplota21_lineEdit_2.setText("150")
            self.teplota22_lineEdit_2.setText("15")
            self.polomer21_lineEdit_2.setText("3")
            self.polomer22_lineEdit_2.setText("10")
        elif index == 2:
            self.emisivita21_lineEdit_4.setText("0.5")
            self.emisivita22_lineEdit_4.setText("0.9")
            self.teplota21_lineEdit_4.setText("150")
            self.teplota22_lineEdit_4.setText("15")
            self.polomer21_lineEdit_4.setText("3")
            self.polomer22_lineEdit_4.setText("10")
            self.L21_lineEdit_4.setText("70")

    def clear_4(self):
        self.emisivita41_lineEdit.clear()
        self.teplota41_lineEdit.clear()
        self.teplota42_lineEdit.clear()
        self.obsah4_lineEdit.clear()
        self.vyslednytok41_lineEdit.clear()
        self.vyslednytok42_lineEdit.clear()

    def vypocet_tepelneho_toku_4(self):
        emisivita4_str = self.emisivita41_lineEdit.text()
        teplota41_str = self.teplota41_lineEdit.text()
        teplota42_str = self.teplota42_lineEdit.text()
        obsah4_str = self.obsah4_lineEdit.text()

        try:
            emisivita4 = float(emisivita4_str.replace(",", "."))
            teplota41 = float(teplota41_str.replace(",", "."))
            teplota42 = float(teplota42_str.replace(",", "."))
            obsah4 = float(obsah4_str.replace(",", "."))

        except ValueError:
            # Chybějící hlaseni pokud je spatne zadano
            QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
            return

        # Calculate radiation heat transfer
        combo_value_4 = self.comboBox_CK_3.currentIndex()
        if combo_value_4 == 0:  # °C
            T4_1 = teplota41 + 273.15
            T4_2 = teplota42 + 273.15
        elif combo_value_4 == 1:  # K
            T4_1 = teplota41
            T4_2 = teplota42
        q4 = emisivita4 * sigma * (T4_1**4 - T4_2**4)
        Q4 = emisivita4 * sigma * obsah4 * (T4_1**4 - T4_2**4)
        self.vyslednytok41_lineEdit.setText('{:.3f}'.format(q4))
        self.vyslednytok42_lineEdit.setText('{:.3f}'.format(Q4))

    def help_window_3(self):
        if self.hidden:
            self.edit_3.show()
            self.hidden = False
        else:
            self.edit_3.hide()
            self.hidden = True

    def priklad3_dosad(self):
        self.emisivita41_lineEdit.setText("0.875")
        self.teplota41_lineEdit.setText("5")
        self.teplota42_lineEdit.setText("24")
        self.obsah4_lineEdit.setText("6.36")

    def clear_5(self):
        self.emisivita51_lineEdit.clear()
        self.emisivita52_lineEdit.clear()
        self.teplota51_lineEdit.clear()
        self.teplota52_lineEdit.clear()
        self.obsah51_lineEdit.clear()
        self.obsah52_lineEdit.clear()
        self.uhlovyfaktor_lineEdit.clear()
        self.vyslednytok51_lineEdit.clear()

    def vypocet_tepelneho_toku_5(self):
        emisivita51_str = self.emisivita51_lineEdit.text()
        emisivita52_str = self.emisivita52_lineEdit.text()
        teplota51_str = self.teplota51_lineEdit.text()
        teplota52_str = self.teplota52_lineEdit.text()
        obsah51_str = self.obsah51_lineEdit.text()
        obsah52_str = self.obsah52_lineEdit.text()
        uhlovyfaktor_str = self.uhlovyfaktor_lineEdit.text()

        try:
            emisivita51 = float(emisivita51_str.replace(",", "."))
            emisivita52 = float(emisivita52_str.replace(",", "."))
            teplota51 = float(teplota51_str.replace(",", "."))
            teplota52 = float(teplota52_str.replace(",", "."))
            obsah51 = float(obsah51_str.replace(",", "."))
            obsah52 = float(obsah52_str.replace(",", "."))
            uhlovyfaktor = float(uhlovyfaktor_str.replace(",", "."))
        except ValueError:
            # Chybějící hlaseni pokud je spatne zadano
            QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
            return

        combo_value_5 = self.comboBox_CK_4.currentIndex()
        if combo_value_5 == 0:  # °C
            T5_1 = teplota51 + 273.15
            T5_2 = teplota52 + 273.15
        elif combo_value_5 == 1:  # K
            T5_1 = teplota51
            T5_2 = teplota52



        Q5 = (sigma * (T5_1**4 - T5_2**4))/(((1 - emisivita51)/(emisivita51 * obsah51)) + (1 / (obsah51*uhlovyfaktor)) +
                                            ((1 - emisivita52)/(emisivita52*obsah52)))

        q5 = (sigma * (T5_1**4 - T5_2**4))/(((1 - emisivita51)/(emisivita51 * obsah51)) + (1 / (obsah51*uhlovyfaktor)) +
                                            ((1 - emisivita52)/(emisivita52*obsah52))) / obsah51

        self.vyslednytok51_lineEdit.setText('{:.3f}'.format(Q5))
        self.vyslednytok51_lineEdit_2.setText('{:.3f}'.format(q5))

    def help_window_4(self):
        if self.hidden:
            self.edit_4.show()
            self.hidden = False
        else:
            self.edit_4.hide()
            self.hidden = True

    def priklad4_dosad(self):
        self.emisivita51_lineEdit.setText("0.7")
        self.emisivita52_lineEdit.setText("0.9")
        self.teplota51_lineEdit.setText("500")
        self.teplota52_lineEdit.setText("30")
        self.obsah51_lineEdit.setText("2.5")
        self.obsah52_lineEdit.setText("3")
        self.uhlovyfaktor_lineEdit.setText("0.9")

    def teploty_1(self):
        combo_value_teplota1 = self.comboBox_CK_1.currentIndex()
        if combo_value_teplota1 == 0:  # °C
            self.label_K_1.setVisible(False)
            self.label_C_1.setVisible(True)
        elif combo_value_teplota1 == 1:  # K
            self.label_K_1.setVisible(True)
            self.label_C_1.setVisible(False)

    def teploty_2(self):
        combo_value_teplota21 = self.comboBox_CK_21.currentIndex()
        if combo_value_teplota21 == 0:  # °C
            self.label_K_21.setVisible(False)
            self.label_C_21.setVisible(True)
        elif combo_value_teplota21 == 1:  # K
            self.label_K_21.setVisible(True)
            self.label_C_21.setVisible(False)
        combo_value_teplota22 = self.comboBox_CK_22.currentIndex()
        if combo_value_teplota22 == 0:  # °C
            self.label_K_22.setVisible(False)
            self.label_C_22.setVisible(True)
        elif combo_value_teplota22 == 1:  # K
            self.label_K_22.setVisible(True)
            self.label_C_22.setVisible(False)
        combo_value_teplota23 = self.comboBox_CK_23.currentIndex()
        if combo_value_teplota23 == 0:  # °C
            self.label_K_23.setVisible(False)
            self.label_C_23.setVisible(True)
        elif combo_value_teplota23 == 1:  # K
            self.label_K_23.setVisible(True)
            self.label_C_23.setVisible(False)

    def teploty_3(self):
        combo_value_teplota3 = self.comboBox_CK_3.currentIndex()
        if combo_value_teplota3 == 0:  # °C
            self.label_K_3.setVisible(False)
            self.label_C_3.setVisible(True)
        elif combo_value_teplota3 == 1:  # K
            self.label_K_3.setVisible(True)
            self.label_C_3.setVisible(False)

    def teploty_4(self):
        combo_value_teplota4 = self.comboBox_CK_4.currentIndex()
        if combo_value_teplota4 == 0:  # °C
            self.label_K_5.setVisible(False)
            self.label_C_5.setVisible(True)
        elif combo_value_teplota4 == 1:  # K
            self.label_K_5.setVisible(True)
            self.label_C_5.setVisible(False)

    def Stefan_Boltzmann(self):
        teplota_str = self.teplota_G_lineEdit.text()
        try:
            teplota = float(teplota_str.replace(",", "."))

        except ValueError:
            # Chybějící hlaseni pokud je spatne zadano
            QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
            return

        e_boltz = sigma * (teplota ** 4)

        self.Boltz_lineEdit.setText('{:.3f}'.format(e_boltz))

    def clear_6(self):
        self.Boltz_lineEdit.clear()
        self.Wien_lineEdit.clear()
        self.teplota_G_lineEdit.clear()

    def Wien(self):
        teplota_str = self.teplota_G_lineEdit.text()
        try:
            teplota = float(teplota_str.replace(",", "."))

        except ValueError:
            # Chybějící hlaseni pokud je spatne zadano
            QMessageBox.warning(self, "Chybové hlášení", "Chybějící nebo špatně zadané hodnoty")
            return

        c_3 = 2897.8  # um

        l_max = c_3 / teplota  # um

        self.Wien_lineEdit.setText('{:.3f}'.format(l_max))


if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = MyWindow()
    window.show()
    app.exec_()
