# -*- coding: utf-8 -*-
"""
@author: Vaclav Miklas

Nazev: GUI
"""

from PyQt5 import QtCore, QtGui, QtWidgets
import pandas as pd
import numpy as np
from Skripty import fermentace, KGJ, separace, chlazeni, ostatni, MSF
from timeit import default_timer as timer
from xlsxwriter.utility import xl_rowcol_to_cell

class Ui_Main(QtWidgets.QMainWindow):
    def __init__(self):
        super(Ui_Main,self).__init__()
        self.setupUi(self)
        self.show()
        self.modFerm = 1
        self.modTep = 1
        self.modMich = 1
        self.modKGJ = 1
        self.modSep = 1
        self.pocet = 1
        self.MSF_state = 0
        self.i = 0
        self.scheme = [0]*5
    
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(947, 1005)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("GUI/BPS_ico.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.lbHeading = QtWidgets.QLabel(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lbHeading.sizePolicy().hasHeightForWidth())
        self.lbHeading.setSizePolicy(sizePolicy)
        font = QtGui.QFont()
        font.setPointSize(16)
        font.setBold(True)
        font.setWeight(75)
        self.lbHeading.setFont(font)
        self.lbHeading.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.lbHeading.setAlignment(QtCore.Qt.AlignCenter)
        self.lbHeading.setObjectName("lbHeading")
        self.verticalLayout_2.addWidget(self.lbHeading)
        self.lbCopyright = QtWidgets.QLabel(self.centralwidget)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lbCopyright.sizePolicy().hasHeightForWidth())
        self.lbCopyright.setSizePolicy(sizePolicy)
        self.lbCopyright.setAlignment(QtCore.Qt.AlignCenter)
        self.lbCopyright.setObjectName("lbCopyright")
        self.verticalLayout_2.addWidget(self.lbCopyright)
        self.verticalLayout.addLayout(self.verticalLayout_2)
        self.line = QtWidgets.QFrame(self.centralwidget)
        self.line.setFrameShape(QtWidgets.QFrame.HLine)
        self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line.setObjectName("line")
        self.verticalLayout.addWidget(self.line)
        self.gridInput = QtWidgets.QGridLayout()
        self.gridInput.setObjectName("gridInput")
        self.lbInputKName = QtWidgets.QLabel(self.centralwidget)
        self.lbInputKName.setObjectName("lbInputKName")
        self.gridInput.addWidget(self.lbInputKName, 2, 0, 1, 1)
        self.lbInputSName = QtWidgets.QLabel(self.centralwidget)
        self.lbInputSName.setObjectName("lbInputSName")
        self.gridInput.addWidget(self.lbInputSName, 1, 0, 1, 1)
        self.lbInputMain = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.lbInputMain.setFont(font)
        self.lbInputMain.setObjectName("lbInputMain")
        self.gridInput.addWidget(self.lbInputMain, 0, 0, 1, 1)
        self.btnInputK = QtWidgets.QPushButton(self.centralwidget)
        self.btnInputK.setObjectName("btnInputK")
        self.gridInput.addWidget(self.btnInputK, 2, 1, 1, 1)
        self.btnInputS = QtWidgets.QPushButton(self.centralwidget)
        self.btnInputS.setObjectName("btnInputS")
        self.gridInput.addWidget(self.btnInputS, 1, 1, 1, 1)
        self.lblXlsx2 = QtWidgets.QLabel(self.centralwidget)
        self.lblXlsx2.setObjectName("lblXlsx2")
        self.gridInput.addWidget(self.lblXlsx2, 2, 2, 1, 1)
        self.lblXlsx1 = QtWidgets.QLabel(self.centralwidget)
        self.lblXlsx1.setObjectName("lblXlsx1")
        self.gridInput.addWidget(self.lblXlsx1, 1, 2, 1, 1)
        self.btnEditS = QtWidgets.QPushButton(self.centralwidget)
        self.btnEditS.setEnabled(True)
        self.btnEditS.setObjectName("btnEditS")
        self.gridInput.addWidget(self.btnEditS, 1, 3, 1, 1)
        self.gridInput.setColumnStretch(0, 1)
        self.gridInput.setColumnStretch(1, 1)
        self.gridInput.setColumnStretch(2, 1)
        self.gridInput.setColumnStretch(3, 1)
        self.verticalLayout.addLayout(self.gridInput)
        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.verticalLayout.addWidget(self.line_2)
        self.gridFerm = QtWidgets.QGridLayout()
        self.gridFerm.setObjectName("gridFerm")
        self.rdFermTSbef = QtWidgets.QRadioButton(self.centralwidget)
        self.rdFermTSbef.setChecked(True)
        self.rdFermTSbef.setObjectName("rdFermTSbef")
        self.grFermMB = QtWidgets.QButtonGroup(MainWindow)
        self.grFermMB.setObjectName("grFermMB")
        self.grFermMB.addButton(self.rdFermTSbef)
        self.gridFerm.addWidget(self.rdFermTSbef, 2, 0, 1, 1)
        self.txFermTSaf = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermTSaf.setEnabled(False)
        self.txFermTSaf.setObjectName("txFermTSaf")
        self.gridFerm.addWidget(self.txFermTSaf, 3, 1, 1, 1)
        self.rdFermNomix = QtWidgets.QRadioButton(self.centralwidget)
        self.rdFermNomix.setObjectName("rdFermNomix")
        self.grFermMich = QtWidgets.QButtonGroup(MainWindow)
        self.grFermMich.setObjectName("grFermMich")
        self.grFermMich.addButton(self.rdFermNomix)
        self.gridFerm.addWidget(self.rdFermNomix, 4, 4, 1, 1)
        self.rdFermMech = QtWidgets.QRadioButton(self.centralwidget)
        self.rdFermMech.setObjectName("rdFermMech")
        self.grFermMich.addButton(self.rdFermMech)
        self.gridFerm.addWidget(self.rdFermMech, 3, 4, 1, 1)
        self.txFermWat = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermWat.setEnabled(False)
        self.txFermWat.setObjectName("txFermWat")
        self.gridFerm.addWidget(self.txFermWat, 4, 1, 1, 1)
        self.rdFermHyd = QtWidgets.QRadioButton(self.centralwidget)
        self.rdFermHyd.setChecked(True)
        self.rdFermHyd.setObjectName("rdFermHyd")
        self.grFermMich.addButton(self.rdFermHyd)
        self.gridFerm.addWidget(self.rdFermHyd, 2, 4, 1, 1)
        self.rdFermTSaf = QtWidgets.QRadioButton(self.centralwidget)
        self.rdFermTSaf.setObjectName("rdFermTSaf")
        self.grFermMB.addButton(self.rdFermTSaf)
        self.gridFerm.addWidget(self.rdFermTSaf, 3, 0, 1, 1)
        self.lbFermMain = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.lbFermMain.setFont(font)
        self.lbFermMain.setObjectName("lbFermMain")
        self.gridFerm.addWidget(self.lbFermMain, 0, 0, 1, 1)
        self.lbFermUnit3 = QtWidgets.QLabel(self.centralwidget)
        self.lbFermUnit3.setObjectName("lbFermUnit3")
        self.gridFerm.addWidget(self.lbFermUnit3, 4, 2, 1, 1)
        self.txFermArea = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermArea.setObjectName("txFermArea")
        self.gridFerm.addWidget(self.txFermArea, 7, 4, 1, 1)
        self.txFermTSbef = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermTSbef.setObjectName("txFermTSbef")
        self.gridFerm.addWidget(self.txFermTSbef, 2, 1, 1, 1)
        self.lbFermUnit1 = QtWidgets.QLabel(self.centralwidget)
        self.lbFermUnit1.setObjectName("lbFermUnit1")
        self.gridFerm.addWidget(self.lbFermUnit1, 2, 2, 1, 1)
        self.txFermHD = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermHD.setEnabled(False)
        self.txFermHD.setObjectName("txFermHD")
        self.gridFerm.addWidget(self.txFermHD, 9, 4, 1, 1)
        self.lbFermTep = QtWidgets.QLabel(self.centralwidget)
        self.lbFermTep.setObjectName("lbFermTep")
        self.gridFerm.addWidget(self.lbFermTep, 7, 0, 1, 1)
        self.lbFermTin = QtWidgets.QLabel(self.centralwidget)
        self.lbFermTin.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lbFermTin.setObjectName("lbFermTin")
        self.gridFerm.addWidget(self.lbFermTin, 8, 1, 1, 1)
        self.lbFermOHTC = QtWidgets.QLabel(self.centralwidget)
        self.lbFermOHTC.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lbFermOHTC.setObjectName("lbFermOHTC")
        self.gridFerm.addWidget(self.lbFermOHTC, 7, 1, 1, 1)
        self.lbFermUnit2 = QtWidgets.QLabel(self.centralwidget)
        self.lbFermUnit2.setObjectName("lbFermUnit2")
        self.gridFerm.addWidget(self.lbFermUnit2, 3, 2, 1, 1)
        self.rdFermWat = QtWidgets.QRadioButton(self.centralwidget)
        self.rdFermWat.setObjectName("rdFermWat")
        self.grFermMB.addButton(self.rdFermWat)
        self.gridFerm.addWidget(self.rdFermWat, 4, 0, 1, 1)
        self.rdFermTranRT = QtWidgets.QRadioButton(self.centralwidget)
        self.rdFermTranRT.setObjectName("rdFermTranRT")
        self.grFermTep = QtWidgets.QButtonGroup(MainWindow)
        self.grFermTep.setObjectName("grFermTep")
        self.grFermTep.addButton(self.rdFermTranRT)
        self.gridFerm.addWidget(self.rdFermTranRT, 9, 0, 1, 1)
        self.rdFermTepProc = QtWidgets.QRadioButton(self.centralwidget)
        self.rdFermTepProc.setObjectName("rdFermTepProc")
        self.grFermTep.addButton(self.rdFermTepProc)
        self.gridFerm.addWidget(self.rdFermTepProc, 10, 0, 1, 1)
        self.txFermTout = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermTout.setObjectName("txFermTout")
        self.gridFerm.addWidget(self.txFermTout, 9, 2, 1, 1)
        self.lbFermArea = QtWidgets.QLabel(self.centralwidget)
        self.lbFermArea.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lbFermArea.setObjectName("lbFermArea")
        self.gridFerm.addWidget(self.lbFermArea, 7, 3, 1, 1)
        self.txFermResTm = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermResTm.setEnabled(False)
        self.txFermResTm.setObjectName("txFermResTm")
        self.gridFerm.addWidget(self.txFermResTm, 8, 4, 1, 1)
        self.txFermTin = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermTin.setObjectName("txFermTin")
        self.gridFerm.addWidget(self.txFermTin, 8, 2, 1, 1)
        self.rdFermTranA = QtWidgets.QRadioButton(self.centralwidget)
        self.rdFermTranA.setChecked(True)
        self.rdFermTranA.setObjectName("rdFermTranA")
        self.grFermTep.addButton(self.rdFermTranA)
        self.gridFerm.addWidget(self.rdFermTranA, 8, 0, 1, 1)
        self.txFermOHTC = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermOHTC.setObjectName("txFermOHTC")
        self.gridFerm.addWidget(self.txFermOHTC, 7, 2, 1, 1)
        self.lbFermHD = QtWidgets.QLabel(self.centralwidget)
        self.lbFermHD.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lbFermHD.setObjectName("lbFermHD")
        self.gridFerm.addWidget(self.lbFermHD, 9, 3, 1, 1)
        self.lbFermMich = QtWidgets.QLabel(self.centralwidget)
        self.lbFermMich.setObjectName("lbFermMich")
        self.gridFerm.addWidget(self.lbFermMich, 1, 4, 1, 1)
        self.lbFermResTm = QtWidgets.QLabel(self.centralwidget)
        self.lbFermResTm.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lbFermResTm.setObjectName("lbFermResTm")
        self.gridFerm.addWidget(self.lbFermResTm, 8, 3, 1, 1)
        self.lbFermTout = QtWidgets.QLabel(self.centralwidget)
        self.lbFermTout.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lbFermTout.setObjectName("lbFermTout")
        self.gridFerm.addWidget(self.lbFermTout, 9, 1, 1, 1)
        self.txFermTepProc = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermTepProc.setEnabled(False)
        self.txFermTepProc.setObjectName("txFermTepProc")
        self.gridFerm.addWidget(self.txFermTepProc, 10, 2, 1, 1)
        self.lbFermTepProc = QtWidgets.QLabel(self.centralwidget)
        self.lbFermTepProc.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lbFermTepProc.setObjectName("lbFermTepProc")
        self.gridFerm.addWidget(self.lbFermTepProc, 10, 1, 1, 1)
        self.lbFermRec = QtWidgets.QLabel(self.centralwidget)
        self.lbFermRec.setObjectName("lbFermRec")
        self.gridFerm.addWidget(self.lbFermRec, 5, 0, 1, 1)
        self.lbFermUnit1_2 = QtWidgets.QLabel(self.centralwidget)
        self.lbFermUnit1_2.setObjectName("lbFermUnit1_2")
        self.gridFerm.addWidget(self.lbFermUnit1_2, 5, 2, 1, 1)
        self.txFermRec = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermRec.setObjectName("txFermRec")
        self.gridFerm.addWidget(self.txFermRec, 5, 1, 1, 1)
        self.lbFermMB = QtWidgets.QLabel(self.centralwidget)
        self.lbFermMB.setObjectName("lbFermMB")
        self.gridFerm.addWidget(self.lbFermMB, 1, 0, 1, 1)
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.gridFerm.addItem(spacerItem, 6, 0, 1, 1)
        self.lbFermHod = QtWidgets.QLabel(self.centralwidget)
        self.lbFermHod.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lbFermHod.setObjectName("lbFermHod")
        self.gridFerm.addWidget(self.lbFermHod, 5, 3, 1, 1)
        self.txFermHod = QtWidgets.QLineEdit(self.centralwidget)
        self.txFermHod.setObjectName("txFermHod")
        self.gridFerm.addWidget(self.txFermHod, 5, 4, 1, 1)
        self.verticalLayout.addLayout(self.gridFerm)
        self.line_3 = QtWidgets.QFrame(self.centralwidget)
        self.line_3.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_3.setObjectName("line_3")
        self.verticalLayout.addWidget(self.line_3)
        self.gridKG = QtWidgets.QGridLayout()
        self.gridKG.setObjectName("gridKG")
        self.sldKGMaxE = QtWidgets.QSlider(self.centralwidget)
        self.sldKGMaxE.setEnabled(False)
        self.sldKGMaxE.setMinimum(1)
        self.sldKGMaxE.setMaximum(20)
        self.sldKGMaxE.setOrientation(QtCore.Qt.Horizontal)
        self.sldKGMaxE.setObjectName("sldKGMaxE")
        self.gridKG.addWidget(self.sldKGMaxE, 10, 1, 1, 1)
        self.lbKGMain = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.lbKGMain.setFont(font)
        self.lbKGMain.setObjectName("lbKGMain")
        self.gridKG.addWidget(self.lbKGMain, 8, 0, 1, 1)
        self.sldKGNum = QtWidgets.QSlider(self.centralwidget)
        self.sldKGNum.setMinimum(1)
        self.sldKGNum.setMaximum(20)
        self.sldKGNum.setOrientation(QtCore.Qt.Horizontal)
        self.sldKGNum.setObjectName("sldKGNum")
        self.gridKG.addWidget(self.sldKGNum, 9, 1, 1, 1)
        self.lbKGNum = QtWidgets.QLabel(self.centralwidget)
        self.lbKGNum.setObjectName("lbKGNum")
        self.gridKG.addWidget(self.lbKGNum, 9, 2, 1, 1)
        self.sldKGMaxQ = QtWidgets.QSlider(self.centralwidget)
        self.sldKGMaxQ.setEnabled(False)
        self.sldKGMaxQ.setMinimum(1)
        self.sldKGMaxQ.setMaximum(20)
        self.sldKGMaxQ.setOrientation(QtCore.Qt.Horizontal)
        self.sldKGMaxQ.setObjectName("sldKGMaxQ")
        self.gridKG.addWidget(self.sldKGMaxQ, 11, 1, 1, 1)
        self.lbKGMaxE = QtWidgets.QLabel(self.centralwidget)
        self.lbKGMaxE.setObjectName("lbKGMaxE")
        self.gridKG.addWidget(self.lbKGMaxE, 10, 2, 1, 1)
        self.lbKGMaxQ = QtWidgets.QLabel(self.centralwidget)
        self.lbKGMaxQ.setObjectName("lbKGMaxQ")
        self.gridKG.addWidget(self.lbKGMaxQ, 11, 2, 1, 1)
        self.rdKGNum = QtWidgets.QRadioButton(self.centralwidget)
        self.rdKGNum.setChecked(True)
        self.rdKGNum.setObjectName("rdKGNum")
        self.grKG = QtWidgets.QButtonGroup(MainWindow)
        self.grKG.setObjectName("grKG")
        self.grKG.addButton(self.rdKGNum)
        self.gridKG.addWidget(self.rdKGNum, 9, 0, 1, 1)
        self.rdKGMaxE = QtWidgets.QRadioButton(self.centralwidget)
        self.rdKGMaxE.setObjectName("rdKGMaxE")
        self.grKG.addButton(self.rdKGMaxE)
        self.gridKG.addWidget(self.rdKGMaxE, 10, 0, 1, 1)
        self.rdKGMaxQ = QtWidgets.QRadioButton(self.centralwidget)
        self.rdKGMaxQ.setObjectName("rdKGMaxQ")
        self.grKG.addButton(self.rdKGMaxQ)
        self.gridKG.addWidget(self.rdKGMaxQ, 11, 0, 1, 1)
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.gridKG.addItem(spacerItem1, 9, 3, 1, 1)
        self.verticalLayout.addLayout(self.gridKG)
        self.line_4 = QtWidgets.QFrame(self.centralwidget)
        self.line_4.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_4.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_4.setObjectName("line_4")
        self.verticalLayout.addWidget(self.line_4)
        self.gridSep = QtWidgets.QGridLayout()
        self.gridSep.setObjectName("gridSep")
        self.lbSepSepTS = QtWidgets.QLabel(self.centralwidget)
        self.lbSepSepTS.setObjectName("lbSepSepTS")
        self.gridSep.addWidget(self.lbSepSepTS, 1, 1, 1, 1)
        self.rdSepNone = QtWidgets.QRadioButton(self.centralwidget)
        self.rdSepNone.setObjectName("rdSepNone")
        self.grSep = QtWidgets.QButtonGroup(MainWindow)
        self.grSep.setObjectName("grSep")
        self.grSep.addButton(self.rdSepNone)
        self.gridSep.addWidget(self.rdSepNone, 2, 0, 1, 1)
        self.lbSepMain = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.lbSepMain.setFont(font)
        self.lbSepMain.setObjectName("lbSepMain")
        self.gridSep.addWidget(self.lbSepMain, 0, 0, 1, 1)
        self.txSepSepTS = QtWidgets.QLineEdit(self.centralwidget)
        self.txSepSepTS.setObjectName("txSepSepTS")
        self.gridSep.addWidget(self.txSepSepTS, 1, 2, 1, 1)
        self.rdSepConv = QtWidgets.QRadioButton(self.centralwidget)
        self.rdSepConv.setChecked(True)
        self.rdSepConv.setObjectName("rdSepConv")
        self.grSep.addButton(self.rdSepConv)
        self.gridSep.addWidget(self.rdSepConv, 1, 0, 1, 1)
        self.lbSepFugTS = QtWidgets.QLabel(self.centralwidget)
        self.lbSepFugTS.setObjectName("lbSepFugTS")
        self.gridSep.addWidget(self.lbSepFugTS, 2, 1, 1, 1)
        self.txSepFugTS = QtWidgets.QLineEdit(self.centralwidget)
        self.txSepFugTS.setObjectName("txSepFugTS")
        self.gridSep.addWidget(self.txSepFugTS, 2, 2, 1, 1)
        spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.gridSep.addItem(spacerItem2, 2, 3, 1, 1)
        self.verticalLayout.addLayout(self.gridSep)
        self.line_5 = QtWidgets.QFrame(self.centralwidget)
        self.line_5.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_5.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_5.setObjectName("line_5")
        self.verticalLayout.addWidget(self.line_5)
        self.gridCool = QtWidgets.QGridLayout()
        self.gridCool.setObjectName("gridCool")
        self.lbCoolR = QtWidgets.QLabel(self.centralwidget)
        self.lbCoolR.setObjectName("lbCoolR")
        self.gridCool.addWidget(self.lbCoolR, 2, 0, 1, 1)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.txCoolR = QtWidgets.QLineEdit(self.centralwidget)
        self.txCoolR.setObjectName("txCoolR")
        self.horizontalLayout_2.addWidget(self.txCoolR)
        self.gridCool.addLayout(self.horizontalLayout_2, 2, 1, 1, 1)
        self.line_7 = QtWidgets.QFrame(self.centralwidget)
        self.line_7.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_7.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_7.setObjectName("line_7")
        self.gridCool.addWidget(self.line_7, 1, 3, 5, 1)
        self.gridMSF = QtWidgets.QGridLayout()
        self.gridMSF.setObjectName("gridMSF")
        self.chbMSF = QtWidgets.QCheckBox(self.centralwidget)
        self.chbMSF.setObjectName("chbMSF")
        self.gridMSF.addWidget(self.chbMSF, 0, 0, 1, 1)
        self.gridCool.addLayout(self.gridMSF, 2, 4, 1, 1)
        self.lbCoolEff_5 = QtWidgets.QLabel(self.centralwidget)
        self.lbCoolEff_5.setObjectName("lbCoolEff_5")
        self.gridCool.addWidget(self.lbCoolEff_5, 4, 2, 1, 1)
        self.lbCoolEff_4 = QtWidgets.QLabel(self.centralwidget)
        self.lbCoolEff_4.setObjectName("lbCoolEff_4")
        self.gridCool.addWidget(self.lbCoolEff_4, 3, 2, 1, 1)
        self.lbCoolEff_3 = QtWidgets.QLabel(self.centralwidget)
        self.lbCoolEff_3.setObjectName("lbCoolEff_3")
        self.gridCool.addWidget(self.lbCoolEff_3, 2, 2, 1, 1)
        self.lbCoolMain = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.lbCoolMain.setFont(font)
        self.lbCoolMain.setObjectName("lbCoolMain")
        self.gridCool.addWidget(self.lbCoolMain, 1, 0, 1, 1)
        self.lbCoolEff_6 = QtWidgets.QLabel(self.centralwidget)
        self.lbCoolEff_6.setObjectName("lbCoolEff_6")
        self.gridCool.addWidget(self.lbCoolEff_6, 5, 2, 1, 1)
        self.lbCoolEff_2 = QtWidgets.QLabel(self.centralwidget)
        self.lbCoolEff_2.setObjectName("lbCoolEff_2")
        self.gridCool.addWidget(self.lbCoolEff_2, 1, 2, 1, 1)
        self.lbCoolEff = QtWidgets.QLabel(self.centralwidget)
        self.lbCoolEff.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter)
        self.lbCoolEff.setObjectName("lbCoolEff")
        self.gridCool.addWidget(self.lbCoolEff, 1, 1, 1, 1)
        self.btnMSF = QtWidgets.QPushButton(self.centralwidget)
        self.btnMSF.setEnabled(False)
        self.btnMSF.setObjectName("btnMSF")
        self.gridCool.addWidget(self.btnMSF, 5, 4, 1, 1)
        self.lbMSF = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.lbMSF.setFont(font)
        self.lbMSF.setObjectName("lbMSF")
        self.gridCool.addWidget(self.lbMSF, 1, 4, 1, 1)
        self.verticalLayout.addLayout(self.gridCool)
        self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.verticalLayout.addLayout(self.horizontalLayout_3)
        self.line_6 = QtWidgets.QFrame(self.centralwidget)
        self.line_6.setFrameShape(QtWidgets.QFrame.HLine)
        self.line_6.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_6.setObjectName("line_6")
        self.verticalLayout.addWidget(self.line_6)
        self.gridOther = QtWidgets.QGridLayout()
        self.gridOther.setObjectName("gridOther")
        self.txOtherElecSpecT = QtWidgets.QLineEdit(self.centralwidget)
        self.txOtherElecSpecT.setObjectName("txOtherElecSpecT")
        self.gridOther.addWidget(self.txOtherElecSpecT, 1, 3, 1, 1)
        self.lbOtherAbs = QtWidgets.QLabel(self.centralwidget)
        self.lbOtherAbs.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignHCenter)
        self.lbOtherAbs.setObjectName("lbOtherAbs")
        self.gridOther.addWidget(self.lbOtherAbs, 0, 1, 1, 1)
        self.txOtherHeatSpecT = QtWidgets.QLineEdit(self.centralwidget)
        self.txOtherHeatSpecT.setObjectName("txOtherHeatSpecT")
        self.gridOther.addWidget(self.txOtherHeatSpecT, 2, 3, 1, 1)
        self.lbOtherMain = QtWidgets.QLabel(self.centralwidget)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.lbOtherMain.setFont(font)
        self.lbOtherMain.setObjectName("lbOtherMain")
        self.gridOther.addWidget(self.lbOtherMain, 0, 0, 1, 1)
        self.lbOtherHeat = QtWidgets.QLabel(self.centralwidget)
        self.lbOtherHeat.setObjectName("lbOtherHeat")
        self.gridOther.addWidget(self.lbOtherHeat, 2, 0, 1, 1)
        self.lbOtherSpecT = QtWidgets.QLabel(self.centralwidget)
        self.lbOtherSpecT.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignHCenter)
        self.lbOtherSpecT.setObjectName("lbOtherSpecT")
        self.gridOther.addWidget(self.lbOtherSpecT, 0, 3, 1, 1)
        self.lbOtherElec = QtWidgets.QLabel(self.centralwidget)
        self.lbOtherElec.setObjectName("lbOtherElec")
        self.gridOther.addWidget(self.lbOtherElec, 1, 0, 1, 1)
        self.lbOtherSpecE = QtWidgets.QLabel(self.centralwidget)
        self.lbOtherSpecE.setAlignment(QtCore.Qt.AlignBottom|QtCore.Qt.AlignHCenter)
        self.lbOtherSpecE.setObjectName("lbOtherSpecE")
        self.gridOther.addWidget(self.lbOtherSpecE, 0, 2, 1, 1)
        self.txOtherHeatAbs = QtWidgets.QLineEdit(self.centralwidget)
        self.txOtherHeatAbs.setObjectName("txOtherHeatAbs")
        self.gridOther.addWidget(self.txOtherHeatAbs, 2, 1, 1, 1)
        self.txOtherHeatSpecE = QtWidgets.QLineEdit(self.centralwidget)
        self.txOtherHeatSpecE.setObjectName("txOtherHeatSpecE")
        self.gridOther.addWidget(self.txOtherHeatSpecE, 2, 2, 1, 1)
        self.txOtherElecSpecE = QtWidgets.QLineEdit(self.centralwidget)
        self.txOtherElecSpecE.setObjectName("txOtherElecSpecE")
        self.gridOther.addWidget(self.txOtherElecSpecE, 1, 2, 1, 1)
        self.btnExpResults = QtWidgets.QPushButton(self.centralwidget)
        self.btnExpResults.setEnabled(False)
        self.btnExpResults.setObjectName("btnExpResults")
        self.gridOther.addWidget(self.btnExpResults, 4, 3, 1, 1)
        self.btnShowResults = QtWidgets.QPushButton(self.centralwidget)
        self.btnShowResults.setEnabled(False)
        self.btnShowResults.setObjectName("btnShowResults")
        self.gridOther.addWidget(self.btnShowResults, 4, 2, 1, 1)
        spacerItem3 = QtWidgets.QSpacerItem(280, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        self.gridOther.addItem(spacerItem3, 3, 1, 1, 1)
        spacerItem4 = QtWidgets.QSpacerItem(280, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        self.gridOther.addItem(spacerItem4, 3, 2, 1, 1)
        self.txOtherElecAbs = QtWidgets.QLineEdit(self.centralwidget)
        self.txOtherElecAbs.setObjectName("txOtherElecAbs")
        self.gridOther.addWidget(self.txOtherElecAbs, 1, 1, 1, 1)
        spacerItem5 = QtWidgets.QSpacerItem(280, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        self.gridOther.addItem(spacerItem5, 3, 3, 1, 1)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.btnCalculation = QtWidgets.QPushButton(self.centralwidget)
        self.btnCalculation.setObjectName("btnCalculation")
        self.horizontalLayout.addWidget(self.btnCalculation)
        self.gridOther.addLayout(self.horizontalLayout, 4, 1, 1, 1)
        self.verticalLayout.addLayout(self.gridOther)
        self.progressBar = QtWidgets.QProgressBar(self.centralwidget)
        self.progressBar.setEnabled(False)
        self.progressBar.setProperty("value", 0)
        self.progressBar.setObjectName("progressBar")
        self.verticalLayout.addWidget(self.progressBar)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 947, 21))
        self.menubar.setObjectName("menubar")
        self.menuMenu = QtWidgets.QMenu(self.menubar)
        self.menuMenu.setObjectName("menuMenu")
        self.menuV_po_et = QtWidgets.QMenu(self.menubar)
        self.menuV_po_et.setObjectName("menuV_po_et")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.actionExit = QtWidgets.QAction(MainWindow)
        self.actionExit.setObjectName("actionExit")
        self.actionDefault = QtWidgets.QAction(MainWindow)
        self.actionDefault.setObjectName("actionDefault")
        self.actionCalculation = QtWidgets.QAction(MainWindow)
        self.actionCalculation.setObjectName("actionCalculation")
        self.actionShowResults = QtWidgets.QAction(MainWindow)
        self.actionShowResults.setObjectName("actionShowResults")
        self.actionExpResults = QtWidgets.QAction(MainWindow)
        self.actionExpResults.setObjectName("actionExpResults")
        self.menuMenu.addAction(self.actionDefault)
        self.menuMenu.addSeparator()
        self.menuMenu.addAction(self.actionExit)
        self.menuV_po_et.addAction(self.actionCalculation)
        self.menuV_po_et.addAction(self.actionShowResults)
        self.menuV_po_et.addAction(self.actionExpResults)
        self.menubar.addAction(self.menuMenu.menuAction())
        self.menubar.addAction(self.menuV_po_et.menuAction())

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        MainWindow.setTabOrder(self.btnInputS, self.btnInputK)
        MainWindow.setTabOrder(self.btnInputK, self.txFermTSbef)
        MainWindow.setTabOrder(self.txFermTSbef, self.txFermTSaf)
        MainWindow.setTabOrder(self.txFermTSaf, self.txFermWat)
        MainWindow.setTabOrder(self.txFermWat, self.txFermRec)
        MainWindow.setTabOrder(self.txFermRec, self.txFermHod)
        MainWindow.setTabOrder(self.txFermHod, self.txFermOHTC)
        MainWindow.setTabOrder(self.txFermOHTC, self.txFermTin)
        MainWindow.setTabOrder(self.txFermTin, self.txFermTout)
        MainWindow.setTabOrder(self.txFermTout, self.txFermTepProc)
        MainWindow.setTabOrder(self.txFermTepProc, self.txFermArea)
        MainWindow.setTabOrder(self.txFermArea, self.txFermResTm)
        MainWindow.setTabOrder(self.txFermResTm, self.txFermHD)
        MainWindow.setTabOrder(self.txFermHD, self.txSepSepTS)
        MainWindow.setTabOrder(self.txSepSepTS, self.txSepFugTS)
        MainWindow.setTabOrder(self.txSepFugTS, self.txCoolR)
        MainWindow.setTabOrder(self.txCoolR, self.txOtherElecAbs)
        MainWindow.setTabOrder(self.txOtherElecAbs, self.txOtherElecSpecE)
        MainWindow.setTabOrder(self.txOtherElecSpecE, self.txOtherElecSpecT)
        MainWindow.setTabOrder(self.txOtherElecSpecT, self.txOtherHeatAbs)
        MainWindow.setTabOrder(self.txOtherHeatAbs, self.txOtherHeatSpecE)
        MainWindow.setTabOrder(self.txOtherHeatSpecE, self.txOtherHeatSpecT)
        MainWindow.setTabOrder(self.txOtherHeatSpecT, self.btnEditS)
        MainWindow.setTabOrder(self.btnEditS, self.rdFermTSbef)
        MainWindow.setTabOrder(self.rdFermTSbef, self.rdFermTSaf)
        MainWindow.setTabOrder(self.rdFermTSaf, self.rdFermWat)
        MainWindow.setTabOrder(self.rdFermWat, self.rdFermHyd)
        MainWindow.setTabOrder(self.rdFermHyd, self.rdFermMech)
        MainWindow.setTabOrder(self.rdFermMech, self.rdFermNomix)
        MainWindow.setTabOrder(self.rdFermNomix, self.rdFermTranA)
        MainWindow.setTabOrder(self.rdFermTranA, self.rdFermTranRT)
        MainWindow.setTabOrder(self.rdFermTranRT, self.rdFermTepProc)
        MainWindow.setTabOrder(self.rdFermTepProc, self.rdKGNum)
        MainWindow.setTabOrder(self.rdKGNum, self.rdKGMaxE)
        MainWindow.setTabOrder(self.rdKGMaxE, self.rdKGMaxQ)
        MainWindow.setTabOrder(self.rdKGMaxQ, self.sldKGNum)
        MainWindow.setTabOrder(self.sldKGNum, self.sldKGMaxE)
        MainWindow.setTabOrder(self.sldKGMaxE, self.sldKGMaxQ)
        MainWindow.setTabOrder(self.sldKGMaxQ, self.rdSepConv)
        MainWindow.setTabOrder(self.rdSepConv, self.rdSepNone)
        MainWindow.setTabOrder(self.rdSepNone, self.btnCalculation)
        MainWindow.setTabOrder(self.btnCalculation, self.btnShowResults)
        MainWindow.setTabOrder(self.btnShowResults, self.btnExpResults)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Model bioplynové stanice"))
        self.lbHeading.setText(_translate("MainWindow", "Model bioplynové stanice"))
        self.lbCopyright.setText(_translate("MainWindow", "Diplomový projekt, Václav Miklas 2017/2018"))
        self.lbInputKName.setText(_translate("MainWindow", "Soubor s databází KGJ:"))
        self.lbInputSName.setText(_translate("MainWindow", "Soubor s databází substrátů:"))
        self.lbInputMain.setText(_translate("MainWindow", "VSTUP"))
        self.btnInputK.setText(_translate("MainWindow", "Otevřít"))
        self.btnInputS.setText(_translate("MainWindow", "Otevřít"))
        self.lblXlsx2.setText(_translate("MainWindow", "Výchozí: KGJ.xlsx"))
        self.lblXlsx1.setText(_translate("MainWindow", "Výchozí: input.xlsx"))
        self.btnEditS.setText(_translate("MainWindow", "Upravit substrát"))
        self.rdFermTSbef.setText(_translate("MainWindow", "Výpočet pomocí sušiny na vstupu do fermentoru:"))
        self.rdFermNomix.setText(_translate("MainWindow", "Žádné"))
        self.rdFermMech.setText(_translate("MainWindow", "Mechanické"))
        self.rdFermHyd.setText(_translate("MainWindow", "Hydraulické"))
        self.rdFermTSaf.setText(_translate("MainWindow", "Výpočet pomocí sušiny na výstupu z fermentoru:"))
        self.lbFermMain.setText(_translate("MainWindow", "FERMENTACE"))
        self.lbFermUnit3.setText(_translate("MainWindow", "kg/h"))
        self.lbFermUnit1.setText(_translate("MainWindow", "% sušiny"))
        self.lbFermTep.setText(_translate("MainWindow", "Kalkulace tepelné spotřeby:"))
        self.lbFermTin.setText(_translate("MainWindow", "Vnitřní teplota [°C]:"))
        self.lbFermOHTC.setText(_translate("MainWindow", "<html><head/><body><p>Souč. prostupu tepla [W/(m<span style=\" vertical-align:super;\">2</span>·K)]:</p></body></html>"))
        self.lbFermUnit2.setText(_translate("MainWindow", "% sušiny"))
        self.rdFermWat.setText(_translate("MainWindow", "Výpočet pomocí přídavku vody:"))
        self.rdFermTranRT.setText(_translate("MainWindow", "Přenosová rovnice, plocha dle zdržné doby"))
        self.rdFermTepProc.setText(_translate("MainWindow", "Procenta vyrobeného tepla"))
        self.lbFermArea.setText(_translate("MainWindow", "<html><head/><body><p>Plocha fermentoru [m<span style=\" vertical-align:super;\">2</span>]:</p></body></html>"))
        self.rdFermTranA.setText(_translate("MainWindow", "Přenosová rovnice, zadaná plocha"))
        self.lbFermHD.setText(_translate("MainWindow", "Poměr výška/průměr fermentoru [–]:"))
        self.lbFermMich.setText(_translate("MainWindow", "Míchání fermentoru:"))
        self.lbFermResTm.setText(_translate("MainWindow", "Zdržná doba substrátu [den]:"))
        self.lbFermTout.setText(_translate("MainWindow", "Venkovní teplota [°C]:"))
        self.lbFermTepProc.setText(_translate("MainWindow", "Procenta [%]:"))
        self.lbFermRec.setText(_translate("MainWindow", "Recykl:"))
        self.lbFermUnit1_2.setText(_translate("MainWindow", "% digestátu"))
        self.lbFermMB.setText(_translate("MainWindow", "Materiálová bilance:"))
        self.lbFermHod.setText(_translate("MainWindow", "Denně mícháno [hod]:"))
        self.lbKGMain.setText(_translate("MainWindow", "KOGENERAČNÍ JEDNOTKY"))
        self.lbKGNum.setText(_translate("MainWindow", "1"))
        self.lbKGMaxE.setText(_translate("MainWindow", "1"))
        self.lbKGMaxQ.setText(_translate("MainWindow", "1"))
        self.rdKGNum.setText(_translate("MainWindow", "Dle požadovaného počtu jednotek:"))
        self.rdKGMaxE.setText(_translate("MainWindow", "Maximalizace elektrického výkonu při počtu jednotek nejvýše:"))
        self.rdKGMaxQ.setText(_translate("MainWindow", "Maximalizace tepelného výkonu při počtu jednotek nejvýše:"))
        self.lbSepSepTS.setText(_translate("MainWindow", "Obsah sušiny v separátu [%]:"))
        self.rdSepNone.setText(_translate("MainWindow", "Žádná separace"))
        self.lbSepMain.setText(_translate("MainWindow", "SEPARACE"))
        self.rdSepConv.setText(_translate("MainWindow", "Šnekový separátor"))
        self.lbSepFugTS.setText(_translate("MainWindow", "Obsah sušiny ve fugátu [%]:"))
        self.lbCoolR.setText(_translate("MainWindow", "Poměr mařené teplo ku spotřeba elektrické energie R [kWt/kWe]:"))
        self.chbMSF.setText(_translate("MainWindow", "Integrovat do procesu odparku"))
        self.lbCoolEff_5.setText(_translate("MainWindow", "C ... R ∈<69; 109)"))
        self.lbCoolEff_4.setText(_translate("MainWindow", "B ... R ∈<109; 169)"))
        self.lbCoolEff_3.setText(_translate("MainWindow", "A ... R ∈<169; 226)"))
        self.lbCoolMain.setText(_translate("MainWindow", "CHLAZENÍ"))
        self.lbCoolEff_6.setText(_translate("MainWindow", "D ... R ∈<37; 69)"))
        self.lbCoolEff_2.setText(_translate("MainWindow", "A+ ... R ≥ 226"))
        self.lbCoolEff.setText(_translate("MainWindow", "Třídy účinnosti:"))
        self.btnMSF.setText(_translate("MainWindow", "Schéma s výsledky MSF"))
        self.lbMSF.setText(_translate("MainWindow", "VÍCESTUPŇOVÁ MŽIKOVÁ ODPARKA"))
        self.lbOtherAbs.setText(_translate("MainWindow", "Σ Absolutních spotřeb [kW]"))
        self.lbOtherMain.setText(_translate("MainWindow", "OSTATNÍ"))
        self.lbOtherHeat.setText(_translate("MainWindow", "Teplo"))
        self.lbOtherSpecT.setText(_translate("MainWindow", "Σ Měrných spotřeb na denní zprac. kapacitu [kW·d/t]"))
        self.lbOtherElec.setText(_translate("MainWindow", "Elektřina"))
        self.lbOtherSpecE.setText(_translate("MainWindow", "Σ Měrných spotřeb na kW el. výkonu [kW/kWe]"))
        self.btnExpResults.setText(_translate("MainWindow", "Exportovat výsledky"))
        self.btnShowResults.setText(_translate("MainWindow", "Zobrazit schéma s výsledky"))
        self.btnCalculation.setText(_translate("MainWindow", "Výpočet"))
        self.menuMenu.setTitle(_translate("MainWindow", "Aplikace"))
        self.menuV_po_et.setTitle(_translate("MainWindow", "Výpočet"))
        self.actionExit.setText(_translate("MainWindow", "Ukončit"))
        self.actionExit.setStatusTip(_translate("MainWindow", "Ukončí aplikaci."))
        self.actionExit.setShortcut(_translate("MainWindow", "Ctrl+Q"))
        self.actionDefault.setText(_translate("MainWindow", "Obnovit výchozí"))
        self.actionDefault.setStatusTip(_translate("MainWindow", "Obnoví výchozí nastavení."))
        self.actionDefault.setShortcut(_translate("MainWindow", "Ctrl+D"))
        self.actionCalculation.setText(_translate("MainWindow", "Výpočet"))
        self.actionCalculation.setStatusTip(_translate("MainWindow", "Provede kompletní kalkulaci."))
        self.actionCalculation.setShortcut(_translate("MainWindow", "Alt+C"))
        self.actionShowResults.setText(_translate("MainWindow", "Zobrazit schéma s výsledky"))
        self.actionShowResults.setStatusTip(_translate("MainWindow", "V novém okně zobrazí schéma s výsledky."))
        self.actionShowResults.setShortcut(_translate("MainWindow", "Alt+S"))
        self.actionExpResults.setText(_translate("MainWindow", "Exportovat výsledky"))
        self.actionExpResults.setStatusTip(_translate("MainWindow", "Provede export výsledků do zvoleného souboru."))
        self.actionExpResults.setShortcut(_translate("MainWindow", "Alt+E"))
        
        self.btnEditS.clicked.connect(self.EditS)
        self.btnInputS.clicked.connect(self.subs_open)
        self.btnInputK.clicked.connect(self.KGJ_open)
        self.btnCalculation.clicked.connect(self.calculation)
        self.btnShowResults.clicked.connect(self.show_results)
        self.btnExpResults.clicked.connect(self.export_results)
        self.btnMSF.clicked.connect(self.MSF_results)
        
        self.actionDefault.triggered.connect(self.default)
        self.actionExit.triggered.connect(self.close_application)
        self.actionCalculation.triggered.connect(self.calculation)
        self.actionShowResults.triggered.connect(self.show_results)
        self.actionExpResults.triggered.connect(self.export_results)
        
        self.rdFermTSbef.toggled.connect(self.rdFermTSbef_clicked)
        self.rdFermTSaf.toggled.connect(self.rdFermTSaf_clicked)
        self.rdFermWat.toggled.connect(self.rdFermWat_clicked)
                
        self.rdFermTranA.toggled.connect(self.rdFermTranA_clicked)
        self.rdFermTranRT.toggled.connect(self.rdFermTranRT_clicked)
        self.rdFermTepProc.toggled.connect(self.rdFermTepProc_clicked)
        
        self.rdFermHyd.toggled.connect(self.rdFermHyd_clicked)
        self.rdFermMech.toggled.connect(self.rdFermMech_clicked)
        self.rdFermNomix.toggled.connect(self.rdFermNomix_clicked)
        
        self.rdKGNum.toggled.connect(self.rdKGNum_clicked)
        self.rdKGMaxE.toggled.connect(self.rdKGMaxE_clicked)
        self.rdKGMaxQ.toggled.connect(self.rdKGMaxQ_clicked)        
        
        self.sldKGNum.valueChanged.connect(self.sldKGNum_changed)
        self.sldKGMaxE.valueChanged.connect(self.sldKGMaxE_changed)
        self.sldKGMaxQ.valueChanged.connect(self.sldKGMaxQ_changed)
        
        self.rdSepConv.toggled.connect(self.rdSepConv_clicked)
        self.rdSepNone.toggled.connect(self.rdSepNone_clicked)
        
        self.chbMSF.stateChanged.connect(self.chbMSF_changed)
        
    def subs_open(self):
        _translate = QtCore.QCoreApplication.translate
        name, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Zvolte soubor s databází substrátů",
                                                         "/input",
                                                         "Sešity MS Excel (*.xls *.xlsx)")
        try:
            self.df_def = pd.read_excel(name)
            self.df = self.df_def.copy(deep=True)
            self.lblXlsx1.setText(_translate("MainWindow", "Načten soubor "+name))
            self.btnEditS.setEnabled(True)
        except:
            pass
        
    def KGJ_open(self):
        _translate = QtCore.QCoreApplication.translate
        self.name_KGJ, _ = QtWidgets.QFileDialog.getOpenFileName(self, "Zvolte soubor s databází kogeneračních jednotek",
                                                         "/KGJ",
                                                         "Sešity MS Excel (*.xls *.xlsx)")
        if self.name_KGJ != '':
            self.lblXlsx2.setText(_translate("MainWindow", "Načten soubor "+self.name_KGJ))
        else:
            self.name_KGJ = 'KGJ.xlsx'
    
    def EditS(self):
        try:
            self.df
        except:
            name = 'input.xlsx'
            self.df = pd.read_excel(name)
            self.df_def = self.df.copy(deep=True)
        self.edit = Ui_Edit()
        
    def default(self):
        del self
        global main
        main = Ui_Main()
        
    def close_application(self):
        choice = QtWidgets.QMessageBox.question(self, 'Ukončení aplikace',
                                                "Opravdu chcete ukončit aplikaci?",
                                                QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
        if choice == QtWidgets.QMessageBox.Yes:
            sys.exit()
        else:
            pass
        
    def calculation(self):
        start = timer()
        self.progressBar.setEnabled(True)
        self.progressBar.setValue(0)
        try:
            self.MBF()
            self.EBK()
            self.EBF()
            self.MBS()
            self.EBS()
            self.EBO()
            self.MSF()
            self.EBC()
            self.Eprod = self.vysledkyEBK[0]+self.vysledkyEBF[0]+self.vysledkyEBS[0]+self.vysledkyEBC[0]+self.vysledkyEBO[0]+self.vysledkyMSF[-1]
            self.btnShowResults.setEnabled(True)
            self.btnExpResults.setEnabled(True)
            end = timer()
            self.statusbar.showMessage("Kalkulace proběhla za {:.4f} sekundy.".format(end - start))
        except:
            self.statusbar.showMessage("""Chyba v zadání! Prosím, zkontrolujte zadání 
substrátu, vyplňte všechna pole (pouze část Ostatní 
je volitelná) a používejte desetinné tečky.""", msecs = 5000)
            
    def MBF(self):
        try:
            self.df
        except:
            name = 'input.xlsx'
            self.df = pd.read_excel(name)
        self.recykl = float(self.txFermRec.text())
        if self.modFerm == 1:
            zadano = float(self.txFermTSbef.text())            
        elif self.modFerm == 2:
            zadano = float(self.txFermTSaf.text())
        elif self.modFerm == 3:
            zadano = float(self.txFermWat.text())
        self.vysledkyMBF = fermentace.MatBilance(self.df, zadano, self.recykl, mod=self.modFerm)
        self.progressBar.setValue(20)
            
    def EBK(self):
        try: 
            self.name_KGJ
        except:
            self.name_KGJ = 'KGJ.xlsx'
        self.vysledkyEBK = KGJ.EnerBilance(self.vysledkyMBF, self.pocet, self.name_KGJ, mod=self.modKGJ)
        self.progressBar.setValue(40)
        
    def EBF(self):
        hod = float(self.zero(self.txFermHod.text()))
        if self.modTep in (1, 2):
            k = float(self.txFermOHTC.text())
            T_in = float(self.txFermTin.text())
            T_out = float(self.txFermTout.text())
            if self.modTep == 1:
                A = float(self.txFermArea.text())
                self.vysledkyEBF = fermentace.EnerBilance(self.vysledkyMBF, hod, k, A, T_in, T_out, mod=1, mich=self.modMich)
            else:
                strDob = float(self.txFermResTm.text())
                H_D = float(self.txFermHD.text())
                self.vysledkyEBF = fermentace.EnerBilance(self.vysledkyMBF, hod, k, H_D, strDob, T_in, T_out, mod=2, mich=self.modMich)
        else:
            tep_proc = float(self.txFermTepProc.text())
            self.vysledkyEBF = fermentace.EnerBilance(self.vysledkyMBF, hod, self.vysledkyEBK, tep_proc, mod=3, mich=self.modMich)
        self.progressBar.setValue(60)
        
    def MBS(self):
        if self.modSep == 1:
            xS = float(self.txSepSepTS.text())
            xF = float(self.txSepFugTS.text())
            self.vysledkyMBS = separace.MatBilance(self.vysledkyMBF, xS, xF)
        if self.modSep == 2:
            self.vysledkyMBS = (0, self.vysledkyMBF[5], 0, self.vysledkyMBF[-3])
        self.progressBar.setValue(70)
    
    def EBS(self):
        if self.modSep == 1 or self.modSep == 3:
            self.vysledkyEBS = separace.EnerBilance(self.vysledkyMBF)
        if self.modSep == 2:
            self.vysledkyEBS = (0,0)
        self.progressBar.setValue(80)
    
    def EBO(self):
        args=[]
        args.append(float(self.zero(self.txOtherElecAbs.text())))
        args.append(float(self.zero(self.txOtherHeatAbs.text())))
        args.append(float(self.zero(self.txOtherElecSpecE.text())))
        args.append(float(self.zero(self.txOtherHeatSpecE.text())))
        args.append(float(self.zero(self.txOtherElecSpecT.text())))
        args.append(float(self.zero(self.txOtherHeatSpecT.text())))
        self.vysledkyEBO = ostatni.EnerBilance(self.vysledkyMBF, self.vysledkyEBK, *args)
        self.progressBar.setValue(90)
        
    def MSF(self):
        self.R = float(self.txCoolR.text())
        if self.MSF_state == 1:
            self.statusbar.showMessage("Probíhá integrace odparky do procesu...")
            self.vysledkyMSF = MSF.MSF((self.vysledkyEBF[1]+self.vysledkyEBK[1]+self.vysledkyEBO[1]),self.vysledkyMBS,self.R)
            self.btnMSF.setEnabled(True)
            self.btnMSF.setText(QtCore.QCoreApplication.translate("MainWindow", "Schéma s výsledky MSF"))
        if self.MSF_state == 0:
            self.vysledkyMSF = [0]*13
            self.vysledkyMSF[0] = 1
            self.btnMSF.setText(QtCore.QCoreApplication.translate("MainWindow", "Schéma s výsledky MSF"))
        if self.vysledkyMSF[0] == 0:
            self.btnMSF.setEnabled(False)
            self.btnMSF.setText(QtCore.QCoreApplication.translate("MainWindow", "Odparku nebylo možné integrovat"))
            

    def EBC(self):
        self.vysledkyEBC = chlazeni.EnerBilance(self.vysledkyEBF, self.vysledkyEBK, self.vysledkyEBO, self.vysledkyMSF, self.R)
        self.progressBar.setValue(100)
        
    def zero(self,string):
        if not string:
            return 0
        else:
            return string       
            
    def show_results(self):
        self.scheme[self.i] = Ui_Scheme()
        if self.i < 4:
            self.i += 1
        else:
            self.i = 0
            
    def export_results(self):
        columns_MB = ["Označení proudu", "Tok", "Jednotka", "Obsah sušiny [hm.%]"]
        nazvy_MB = ["Vstupní substrát", "Přídavek vody", "Substrát do fermentoru",
                    "Bioplyn", "Digestát z fermentoru", "Výstupní digestát",
                    "Recykl digestátu", "Separát", "Fugát"]
        jednotky_MB = ["kg/h"]*9
        jednotky_MB[3] = "Nm3/h"

        a=(np.array([nazvy_MB,
                     [*self.vysledkyMBF[0:3],self.vysledkyMBF[3]/1.2,*self.vysledkyMBF[4:7],*self.vysledkyMBS[0:2]],
                     jednotky_MB,
                     [i*100 for i in self.vysledkyMBF[7:14]]+[i*100 for i in self.vysledkyMBS[2:4]]]))
        df_MB = pd.DataFrame(data=a.transpose(),columns=columns_MB)
        
        columns_EB = ["Zařízení", "Elektřina [kWe]", "Teplo [kWt]"]
        nazvy_EB = ["Fermentor", "KGJ: {:d} × {}".format(*self.vysledkyEBK[2:4]), "Separátor", "Chladiče",
                    "Ostatní", "MSF", "Prodej elektřiny"]
        b = np.array([[nazvy_EB[0],*self.vysledkyEBF],
                      [nazvy_EB[1],*self.vysledkyEBK[0:2]],
                      [nazvy_EB[2],*self.vysledkyEBS],
                      [nazvy_EB[3],*self.vysledkyEBC],
                      [nazvy_EB[4],*self.vysledkyEBO],
                      [nazvy_EB[5],self.vysledkyMSF[-1],self.vysledkyMSF[-5]],
                      [nazvy_EB[6],-self.Eprod,0]])
        df_EB = pd.DataFrame(data=b,columns=columns_EB)
        
        columns_MSF = ["Proud", "Hmotnostní tok [kg/h]", "Obsah sušiny [hm.%]",
                       "Zařízení", "Teplosměnná plocha [m2]", "Spotřeba", "Jednotka"]
        nazvyPr_MSF = ["Fugát/digestát", "Recirkulát", "Koncentrát", "Destilát"]
        nazvyZar_MSF = ["Dohřev recirkulátu", "Kondenzační sekce ({:d} x MJS)".format(self.vysledkyMSF[-2]), "Čerpadla, vývěva, chladiče", ""]
        jednotky_MSF = ["kWt", "kWt", "kWe", ""]
        c = np.array([nazvyPr_MSF,
                      [*self.vysledkyMSF[0:8:2]],
                      [*self.vysledkyMSF[1:9:2]],
                      nazvyZar_MSF,
                      [*self.vysledkyMSF[9:11],"–",""],
                      [self.vysledkyMSF[-5],-self.vysledkyMSF[-5],self.vysledkyMSF[-1],""],
                      jednotky_MSF])
        df_MSF = pd.DataFrame(data=c.transpose(),columns=columns_MSF)
        
        name, _ = QtWidgets.QFileDialog.getSaveFileName(self, "Uložení souboru s výsledky výpočtu",
                                                 "/exported_results",
                                                 "Sešit MS Excel (*.xlsx)")
        writer = pd.ExcelWriter(name, engine='xlsxwriter',options={'strings_to_numbers': True})
        df_MB.to_excel(writer,index=False, sheet_name='Materiálová bilance')
        df_EB.to_excel(writer,index=False, sheet_name='Energetická bilance')
        df_MSF.to_excel(writer,index=False, sheet_name='Vícestupňová mžiková odparka')
        
        workbook = writer.book
        cell_format1 = workbook.add_format()
        cell_format1.set_align('center')
        cell_format1.set_num_format("0.0")
        cell_format2 = workbook.add_format()
        cell_format2.set_align('center')
        cell_format2.set_num_format("0.00")
        total_fmt = workbook.add_format({'align': 'center', 'num_format': '0.00',
                                 'bold': True})
        bold = workbook.add_format({'align': 'left',
                                 'bold': True})

        worksheet1 = writer.sheets['Materiálová bilance']
        worksheet2 = writer.sheets['Energetická bilance']
        worksheet3 = writer.sheets['Vícestupňová mžiková odparka']

        worksheet1.set_column('A:A', 25)
        worksheet1.set_column('B:B', 12, cell_format1)
        worksheet1.set_column('C:C', 8)
        worksheet1.set_column('D:D', 20, cell_format2)


        worksheet2.set_column('A:A', 15)
        worksheet2.set_column('B:B', 15, cell_format1)
        worksheet2.set_column('C:C', 15, cell_format1)

        worksheet3.set_column('A:A', 15, bold)
        worksheet3.set_column('B:B', 20, cell_format1)
        worksheet3.set_column('C:C', 20, cell_format2)
        worksheet3.set_column('D:D', 26, bold)
        worksheet3.set_column('E:E', 23, cell_format1)
        worksheet3.set_column('F:F', 10, cell_format1)
        worksheet3.set_column('G:G', 10)

        for column in range(1, 3):
            cell_location = xl_rowcol_to_cell(len(nazvy_EB)+1, column)
            start_range = xl_rowcol_to_cell(1, column)
            end_range = xl_rowcol_to_cell(len(nazvy_EB), column)
            formula = "=SUM({:s}:{:s})".format(start_range, end_range)
            worksheet2.write_formula(cell_location, formula, total_fmt)
        worksheet2.write_string(len(nazvy_EB)+1, 0, "Kontrola",bold)    

        writer.save()
        
    def MSF_results(self):
        self.MSF_window = Ui_MSF()
        
        
#––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––        
    def rdFermTSbef_clicked(self):
        self.txFermTSbef.setEnabled(True)
        self.txFermTSaf.setEnabled(False)
        self.txFermWat.setEnabled(False)
        self.modFerm = 1
    
    def rdFermTSaf_clicked(self):
        self.txFermTSbef.setEnabled(False)
        self.txFermTSaf.setEnabled(True)
        self.txFermWat.setEnabled(False)
        self.modFerm = 2
    
    def rdFermWat_clicked(self):
        self.txFermTSbef.setEnabled(False)
        self.txFermTSaf.setEnabled(False)
        self.txFermWat.setEnabled(True)
        self.modFerm = 3
#––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––         
    def rdFermHyd_clicked(self):
        self.modMich = 1
        self.txFermHod.setEnabled(True)
    
    def rdFermMech_clicked(self):
        self.modMich = 2
        self.txFermHod.setEnabled(True)
    
    def rdFermNomix_clicked(self):
        self.modMich = 3
        self.txFermHod.setEnabled(False)
#––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––        
    def rdFermTranA_clicked(self):
        self.txFermTin.setEnabled(True)
        self.txFermTout.setEnabled(True)
        self.txFermOHTC.setEnabled(True)
        self.txFermArea.setEnabled(True)
        self.txFermResTm.setEnabled(False)
        self.txFermHD.setEnabled(False)
        self.txFermTepProc.setEnabled(False)
        self.modTep = 1

    def rdFermTranRT_clicked(self):
        self.txFermTin.setEnabled(True)
        self.txFermTout.setEnabled(True)
        self.txFermOHTC.setEnabled(True)
        self.txFermArea.setEnabled(False)
        self.txFermResTm.setEnabled(True)
        self.txFermHD.setEnabled(True)
        self.txFermTepProc.setEnabled(False)
        self.modTep = 2

    def rdFermTepProc_clicked(self):
        self.txFermTin.setEnabled(False)
        self.txFermTout.setEnabled(False)
        self.txFermOHTC.setEnabled(False)
        self.txFermArea.setEnabled(False)
        self.txFermResTm.setEnabled(False)
        self.txFermHD.setEnabled(False)
        self.txFermTepProc.setEnabled(True)
        self.modTep = 3
#––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
    def rdKGNum_clicked(self):
        self.sldKGNum.setEnabled(True)
        self.sldKGMaxE.setEnabled(False)
        self.sldKGMaxQ.setEnabled(False)
        self.modKGJ = 1
        self.pocet = self.sldKGNum.value()
    
    def rdKGMaxE_clicked(self):
        self.sldKGNum.setEnabled(False)
        self.sldKGMaxE.setEnabled(True)
        self.sldKGMaxQ.setEnabled(False)
        self.modKGJ = 2
        self.pocet = self.sldKGMaxE.value()
    
    def rdKGMaxQ_clicked(self):
        self.sldKGNum.setEnabled(False)
        self.sldKGMaxE.setEnabled(False)
        self.sldKGMaxQ.setEnabled(True)
        self.modKGJ = 3
        self.pocet = self.sldKGMaxQ.value()
    
    def sldKGNum_changed(self):
        _translate = QtCore.QCoreApplication.translate
        self.lbKGNum.setText(_translate("MainWindow", str(self.sldKGNum.value())))
        self.pocet = self.sldKGNum.value()
    
    def sldKGMaxE_changed(self):
        _translate = QtCore.QCoreApplication.translate
        self.lbKGMaxE.setText(_translate("MainWindow", str(self.sldKGMaxE.value())))
        self.pocet = self.sldKGMaxE.value()
    
    def sldKGMaxQ_changed(self):
        _translate = QtCore.QCoreApplication.translate
        self.lbKGMaxQ.setText(_translate("MainWindow", str(self.sldKGMaxQ.value())))
        self.pocet = self.sldKGMaxQ.value()
#––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
    def rdSepConv_clicked(self):
        self.modSep = 1
        self.txSepFugTS.setEnabled(True)
        self.txSepSepTS.setEnabled(True)
        
    def rdSepNone_clicked(self):
        self.modSep = 2
        self.txSepFugTS.setEnabled(False)
        self.txSepSepTS.setEnabled(False)
        
#––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––            
    def chbMSF_changed(self, int):
        if self.chbMSF.isChecked():
            self.MSF_state = 1
        else:
            self.MSF_state = 0
"""
===============================================================================
"""
class Ui_Edit(QtWidgets.QMainWindow):
    def __init__(self):
        super(Ui_Edit,self).__init__()
        self.df = main.df.copy(deep=True)
        self.setupUi(self)
        self.fill()
        self.show()
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setEnabled(True)
        MainWindow.resize(1100, 700)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("GUI/BPS_ico.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        MainWindow.setWindowIcon(icon)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
        self.verticalLayout.setObjectName("verticalLayout")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout()
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setObjectName("label")
        self.verticalLayout_2.addWidget(self.label)
        self.treeWidget = QtWidgets.QTreeWidget(self.centralwidget)
        self.treeWidget.setEnabled(True)
        self.treeWidget.setSizeAdjustPolicy(QtWidgets.QAbstractScrollArea.AdjustIgnored)
        self.treeWidget.setDragDropOverwriteMode(False)
        self.treeWidget.setAlternatingRowColors(False)
        self.treeWidget.setColumnCount(3)
        self.treeWidget.setObjectName("treeWidget")
        self.treeWidget.header
        self.treeWidget.header().setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
        self.treeWidget.header().setStretchLastSection(False)
        self.verticalLayout_2.addWidget(self.treeWidget)
        self.verticalLayout.addLayout(self.verticalLayout_2)
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.btnOK = QtWidgets.QPushButton(self.centralwidget)
        self.btnOK.setObjectName("btnOK")
        self.horizontalLayout.addWidget(self.btnOK)
        self.btnCancel = QtWidgets.QPushButton(self.centralwidget)
        self.btnCancel.setObjectName("btnCancel")
        self.horizontalLayout.addWidget(self.btnCancel)
        self.btnDefault = QtWidgets.QPushButton(self.centralwidget)
        self.btnDefault.setObjectName("btnDefault")
        self.horizontalLayout.addWidget(self.btnDefault)
        self.btnExpDf = QtWidgets.QPushButton(self.centralwidget)
        self.btnExpDf.setObjectName("btnExpDf")
        self.horizontalLayout.addWidget(self.btnExpDf)
        spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem1)
        self.verticalLayout.addLayout(self.horizontalLayout)
        MainWindow.setCentralWidget(self.centralwidget)

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

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "Úprava substrátu"))
        self.label.setText(_translate("MainWindow", "Zadejte hmotnostní toky jednotlivých složek substrátu, dle potřeby lze upravit také obsah sušiny či výtěžnosti:"))
        __sortingEnabled = self.treeWidget.isSortingEnabled()
        self.treeWidget.setSortingEnabled(False)
        self.treeWidget.setSortingEnabled(__sortingEnabled)
        self.btnOK.setText(_translate("MainWindow", "OK (uložit a zavřít)"))
        self.btnCancel.setText(_translate("MainWindow", "Zrušit změny"))
        self.btnDefault.setText(_translate("MainWindow", "Obnovit výchozí"))
        self.btnExpDf.setText(_translate("MainWindow", "Exportovat databázi"))
        self.btnDefault.clicked.connect(self.Default)
        self.btnCancel.clicked.connect(self.Cancel)
        self.btnOK.clicked.connect(self.OK)
        self.btnExpDf.clicked.connect(self.Export)
        

    def fill(self):
        for i in range(1,self.df.shape[1]-1):
            self.treeWidget.headerItem().setTextAlignment(i, QtCore.Qt.AlignCenter)
        for i in range (len(self.tridy(self.df))):
            item_0 = QtWidgets.QTreeWidgetItem(self.treeWidget)
            for j in range (self.tridy(self.df)[i]):
                item_1 = QtWidgets.QTreeWidgetItem(item_0)
                item_1.setFlags(QtCore.Qt.ItemIsSelectable|QtCore.Qt.ItemIsEditable|QtCore.Qt.ItemIsDragEnabled|QtCore.Qt.ItemIsUserCheckable|QtCore.Qt.ItemIsEnabled)
                for k in range (1,self.df.shape[1]-1):
                    item_1.setTextAlignment(k, QtCore.Qt.AlignHCenter)

        _translate = QtCore.QCoreApplication.translate
        for i in range (1,self.df.shape[1]):
            self.treeWidget.headerItem().setText(i-1, _translate("MainWindow", self.df.axes[1][i]))

        it = 0
        for i in range (len(self.tridy(self.df))):
            self.treeWidget.topLevelItem(i).setText(0, _translate("MainWindow", str(self.df.iat[it, 0])))
            for j in range (self.tridy(self.df)[i]):
                for k in range (self.df.shape[1]-1):
                    self.treeWidget.topLevelItem(i).child(j).setText(k, _translate("MainWindow", str(self.df.iat[it, k+1])))
                it += 1
    
    def Default(self):
        it = 0
        _translate = QtCore.QCoreApplication.translate
        for i in range (len(self.tridy(main.df_def))):
                self.treeWidget.topLevelItem(i).setText(0, _translate("MainWindow", str(main.df_def.iat[it, 0])))  
                for j in range (self.tridy(main.df_def)[i]):
                    for k in range (main.df_def.shape[1]-1):
                        self.treeWidget.topLevelItem(i).child(j).setText(k, _translate("MainWindow", str(main.df_def.iat[it, k+1])))
                    it += 1
    def Cancel(self):
        del main.edit

    def OK (self):
        it = 0
        for i in range (len(self.tridy(self.df))):
                main.df.iat[it, 0] = self.treeWidget.topLevelItem(i).text(0)
                for j in range (self.tridy(self.df)[i]):
                    for k in range (self.df.shape[1]-1):
                        main.df.iat[it, k+1] = self.treeWidget.topLevelItem(i).child(j).text(k)
                    it += 1
        self.close()
        

    def Export(self):
        it = 0
        for i in range (len(self.tridy(self.df))):
                self.df.iat[it, 0] = self.treeWidget.topLevelItem(i).text(0)
                for j in range (self.tridy(self.df)[i]):
                    for k in range (self.df.shape[1]-1):
                        self.df.iat[it, k+1] = self.treeWidget.topLevelItem(i).child(j).text(k)
                    it += 1
        name, _ = QtWidgets.QFileDialog.getSaveFileName(self, "Uložení souboru s databází substrátů",
                                                         "/exported_input",
                                                         "Sešit MS Excel (*.xlsx)")
        sheet_name = 'List1'
        writer = pd.ExcelWriter(name, engine='xlsxwriter')
        self.df.to_excel(writer, index=False,  sheet_name=sheet_name)
        writer.save()
    
    def tridy(self,dataframe):
        item_number = []
        j = 0
        for i in range(dataframe.shape[0], 0, -1):
            if dataframe.isnull().iat[i-1, 0] == False:
                    j = dataframe.shape[0] - i + 1 - sum(item_number)
                    item_number.append(j)
        item_number.reverse()
        return item_number
    
        
"""
===============================================================================
"""
class Ui_Scheme(QtWidgets.QWidget):
    def __init__(self):
        super(Ui_Scheme,self).__init__()
        self.sch_name = "GUI/schema.svg"
        self.setupUi(self)
        self.show()

    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(1100, 696)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
        Form.setSizePolicy(sizePolicy)
        Form.setMinimumSize(QtCore.QSize(1100, 696))
        Form.setMaximumSize(QtCore.QSize(1100, 696))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("GUI/BPS_ico.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        Form.setWindowIcon(icon)
        Form.setStyleSheet("")
        self.scheme = QtWidgets.QLabel(Form)
        self.scheme.setGeometry(QtCore.QRect(50, 10, 1011, 681))
        self.scheme.setObjectName("scheme")
        self.txm2 = QtWidgets.QLabel(Form)
        self.txm2.setGeometry(QtCore.QRect(110, 290, 161, 41))
        self.txm2.setObjectName("txm2")
        self.txm1 = QtWidgets.QLabel(Form)
        self.txm1.setGeometry(QtCore.QRect(10, 420, 161, 41))
        self.txm1.setObjectName("txm1")
        self.txm7 = QtWidgets.QLabel(Form)
        self.txm7.setGeometry(QtCore.QRect(380, 570, 161, 41))
        self.txm7.setObjectName("txm7")
        self.txm6 = QtWidgets.QLabel(Form)
        self.txm6.setGeometry(QtCore.QRect(840, 460, 161, 41))
        self.txm6.setObjectName("txm6")
        self.txmS = QtWidgets.QLabel(Form)
        self.txmS.setGeometry(QtCore.QRect(930, 510, 161, 41))
        self.txmS.setObjectName("txmS")
        self.txmF = QtWidgets.QLabel(Form)
        self.txmF.setGeometry(QtCore.QRect(880, 630, 161, 41))
        self.txmF.setObjectName("txmF")
        self.txKGJ = QtWidgets.QLabel(Form)
        self.txKGJ.setGeometry(QtCore.QRect(295, 170, 161, 51))
        self.txKGJ.setObjectName("txKGJ")
        self.txCool = QtWidgets.QLabel(Form)
        self.txCool.setGeometry(QtCore.QRect(780, 190, 131, 41))
        self.txCool.setObjectName("txCool")
        self.txLeg = QtWidgets.QLabel(Form)
        self.txLeg.setGeometry(QtCore.QRect(800, 10, 131, 16))
        self.txLeg.setObjectName("txLeg")
        self.txVBP = QtWidgets.QLabel(Form)
        self.txVBP.setGeometry(QtCore.QRect(410, 300, 91, 41))
        self.txVBP.setObjectName("txVBP")
        self.txFerm = QtWidgets.QLabel(Form)
        self.txFerm.setGeometry(QtCore.QRect(510, 330, 161, 41))
        self.txFerm.setObjectName("txFerm")
        self.txElSold = QtWidgets.QLabel(Form)
        self.txElSold.setGeometry(QtCore.QRect(100, 0, 271, 16))
        self.txElSold.setObjectName("txElSold")
        self.txm3 = QtWidgets.QLabel(Form)
        self.txm3.setGeometry(QtCore.QRect(190, 420, 161, 41))
        self.txm3.setObjectName("txm3")
        self.txSep = QtWidgets.QLabel(Form)
        self.txSep.setGeometry(QtCore.QRect(700, 610, 101, 31))
        self.txSep.setObjectName("txSep")
        self.txLeg2 = QtWidgets.QLabel(Form)
        self.txLeg2.setGeometry(QtCore.QRect(920, 26, 131, 16))
        self.txLeg2.setObjectName("txLeg2")
        self.txLeg3 = QtWidgets.QLabel(Form)
        self.txLeg3.setGeometry(QtCore.QRect(920, 43, 131, 16))
        self.txLeg3.setObjectName("txLeg3")
        self.txLeg4 = QtWidgets.QLabel(Form)
        self.txLeg4.setGeometry(QtCore.QRect(920, 60, 131, 16))
        self.txLeg4.setObjectName("txLeg4")
        self.txOther = QtWidgets.QLabel(Form)
        self.txOther.setGeometry(QtCore.QRect(430, 30, 181, 41))
        self.txOther.setObjectName("txOther")
        
        self.btnSave = QtWidgets.QPushButton("",self)
        self.btnSave.setIcon(QtGui.QIcon('GUI/save.png'))
        self.btnSave.clicked.connect(self.PrintScreen)
        self.btnSave.resize(30,30)
        self.btnSave.move(10,10)
        
        if main.vysledkyEBS[0] == 0:
            self.sch_name = "GUI/schema_wo_sep.svg"
            self.scheme.setGeometry(QtCore.QRect(50, 0, 1011, 681))
            self.txSep.setVisible(False)
            self.txmF.setVisible(False)
            self.txmS.setVisible(False)
        

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

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Schéma s výsledky {:d}".format(main.i+1)))
        self.scheme.setText(_translate("Form","<html><head/><body><p><img src=\"%s\"/></p></body></html>" % self.sch_name))
        self.txm2.setText(_translate("Form", """<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">
                                     Přídavek vody<br/></span>Hmotnostní tok: {:.1f} kg/h<br/>Obsah sušiny: {:.2f} hm.%</p></body></html>""".format(main.vysledkyMBF[1],main.vysledkyMBF[8]*100)))
        self.txm1.setText(_translate("Form", """<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">
                                     Vstupní substrát<br/></span>Hmotnostní tok: {:.1f} kg/h<br/>Obsah sušiny: {:.2f} hm.%</p></body></html>""".format(main.vysledkyMBF[0],main.vysledkyMBF[7]*100)))
        self.txm7.setText(_translate("Form", """<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">
                                     Recykl digestátu ({:.0f} %)<br/></span>Hmotnostní tok: {:.1f} kg/h<br/>Obsah sušiny: {:.2f} hm.%</p></body></html>""".format(main.recykl,main.vysledkyMBF[6],main.vysledkyMBF[13]*100)))
        self.txm6.setText(_translate("Form", """<html><head/><body><p><span style=\" font-weight:600;\">
                                     Digestát ({:.0f} %)<br/></span>Hmotnostní tok: {:.1f} kg/h<br/>Obsah sušiny: {:.2f} hm.%</p></body></html>""".format(100-main.recykl,main.vysledkyMBF[5],main.vysledkyMBF[12]*100)))
        self.txmS.setText(_translate("Form", """<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">
                                     Separát<br/></span>Hmotnostní tok: {:.1f} kg/h<br/>Obsah sušiny: {:.2f} hm.%</p></body></html>""".format(main.vysledkyMBS[0],main.vysledkyMBS[2]*100)))
        self.txmF.setText(_translate("Form", """<html><head/><body><p><span style=\" font-weight:600;\">
                                     Fugát<br/></span>Hmotnostní tok: {:.1f} kg/h<br/>Obsah sušiny: {:.2f} hm.%</p></body></html>""".format(main.vysledkyMBS[1],main.vysledkyMBS[3]*100)))
        self.txKGJ.setText(_translate("Form", """<html><head/><body><p><span style=\" font-weight:600;\">
                                      KGJ: {:d} x {}<br/></span>Elektrický výkon: {:.1f} kWe<br/>Tepelný výkon: {:.1f} kWt<br/>Celková účinnost: {:.1f} %</p></body></html>""".format(*main.vysledkyEBK[2:4],*main.vysledkyEBK[0:2],main.vysledkyEBK[4][2])))
        self.txCool.setText(_translate("Form", """<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">
                                       Chladiče<br/></span>Spotřeba: {:.1f} kWe<br/>Mařené teplo: {:.1f} kWt</p></body></html>""".format(-main.vysledkyEBC[0],-main.vysledkyEBC[1])))
        self.txLeg.setText(_translate("Form", """<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">
                                      Legenda:</span></p></body></html>"""))
        self.txVBP.setText(_translate("Form", """<html><head/><body><p><span style=\" font-weight:600;\">
                                      Produkovaný <br/>bioplyn:<br/>{:.1f} Nm</span><span style=\" font-weight:600; vertical-align:super;\">3</span><span style=\" font-weight:600;\">/h</span></p></body></html>""".format(main.vysledkyMBF[3]/1.2)))
        self.txFerm.setText(_translate("Form", """<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">
                                       Fermentor<br/></span>Spotřeba míchání: {:.1f} kWe<br/>Tepelná spotřeba: {:.1f} kWt</p></body></html>""".format(-main.vysledkyEBF[0],-main.vysledkyEBF[1])))
        self.txElSold.setText(_translate("Form", """<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">
                                         Prodávaná elektrická energie: {:.1f} kWe<br/></span><br/></p></body></html>""".format(main.Eprod)))
        self.txm3.setText(_translate("Form", """<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">
                                     Naočkovaný substrát<br/></span>Hmotnostní tok: {:.1f} kg/h<br/>Obsah sušiny: {:.2f} hm.%</p></body></html>""".format(main.vysledkyMBF[2],main.vysledkyMBF[9]*100)))
        self.txSep.setText(_translate("Form", """<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">
                                      Separátor<br/></span>Spotřeba: {:.1f} kWe</p></body></html>""".format(-main.vysledkyEBS[0])))
        self.txLeg2.setText(_translate("Form", "<html><head/><body><p>materiálový tok</p></body></html>"))
        self.txLeg3.setText(_translate("Form", "<html><head/><body><p>elektrický tok</p></body></html>"))
        self.txLeg4.setText(_translate("Form", "<html><head/><body><p>tepelný tok</p></body></html>"))
        self.txOther.setText(_translate("Form", """<html><head/><body><p align=\"right\"><span style=\" font-weight:600;\">
                                        Ostatní/MSF:<br/></span>Elektrická spotřeba: {:.1f}/{:.1f} kWe<br/>Tepelná spotřeba: {:.1f}/{:.1f} kWt</p></body></html>""".format(-main.vysledkyEBO[0],-main.vysledkyMSF[-1],-main.vysledkyEBO[1],-main.vysledkyMSF[-5])))       
        
    def PrintScreen(self):
        self.setStyleSheet("background-color: white;")
        self.btnSave.setVisible(False)
        name, _ = QtWidgets.QFileDialog.getSaveFileName(self, "Uložení schématu",
                                                         "/scheme",
                                                         "PNG (*.png)")
        p = self.grab()
        p.save(name)
        self.setStyleSheet("background-color: palette(window);")
        self.btnSave.setVisible(True)
"""
===============================================================================
"""        
class Ui_MSF(QtWidgets.QWidget):
    def __init__(self):
        super(Ui_MSF,self).__init__()
        self.setupUi(self)
        self.show()
        
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(800, 400)
        sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
        Form.setSizePolicy(sizePolicy)
        Form.setMinimumSize(QtCore.QSize(800, 400))
        Form.setMaximumSize(QtCore.QSize(800, 400))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("GUI/BPS_ico.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        Form.setWindowIcon(icon)
        Form.setStyleSheet("")
        self.scheme = QtWidgets.QLabel(Form)
        self.scheme.setGeometry(QtCore.QRect(100, 0, 600, 400))
        self.scheme.setObjectName("scheme")
        self.lbOhr = QtWidgets.QLabel(Form)
        self.lbOhr.setGeometry(QtCore.QRect(10, 140, 151, 41))
        self.lbOhr.setObjectName("lbOhr")
        self.lbFug = QtWidgets.QLabel(Form)
        self.lbFug.setGeometry(QtCore.QRect(260, 340, 161, 41))
        self.lbFug.setObjectName("lbFug")
        self.lbConc = QtWidgets.QLabel(Form)
        self.lbConc.setGeometry(QtCore.QRect(640, 340, 161, 41))
        self.lbConc.setObjectName("lbConc")
        self.lbRec = QtWidgets.QLabel(Form)
        self.lbRec.setGeometry(QtCore.QRect(80, 300, 161, 41))
        self.lbRec.setObjectName("lbRec")
        self.lbCond = QtWidgets.QLabel(Form)
        self.lbCond.setGeometry(QtCore.QRect(110, 60, 201, 41))
        self.lbCond.setObjectName("lbCond")
        self.lbElec = QtWidgets.QLabel(Form)
        self.lbElec.setGeometry(QtCore.QRect(600, 90, 201, 31))
        self.lbElec.setObjectName("lbElec")
        self.lbDest = QtWidgets.QLabel(Form)
        self.lbDest.setGeometry(QtCore.QRect(640, 150, 161, 41))
        self.lbDest.setObjectName("lbDest")
        self.lbHeading = QtWidgets.QLabel(Form)
        self.lbHeading.setGeometry(QtCore.QRect(270, 0, 301, 41))
        self.lbHeading.setObjectName("lbHeading")
        self.lbCopyright = QtWidgets.QLabel(Form)
        self.lbCopyright.setGeometry(QtCore.QRect(10, 371, 211, 20))
        self.lbCopyright.setObjectName("lbCopyright")
        
        self.btnSave = QtWidgets.QPushButton("",self)
        self.btnSave.setIcon(QtGui.QIcon('GUI/save.png'))
        self.btnSave.clicked.connect(self.PrintScreen)
        self.btnSave.resize(30,30)
        self.btnSave.move(10,10)

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

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Schéma s výsledky MSF"))
        self.scheme.setText(_translate("Form", "<html><head/><body><p><img src=\"GUI/MSF.svg\"/></p></body></html>"))
        self.lbOhr.setText(_translate("Form", """<html><head/><body><p><span style=\" font-weight:600;\">
                                      Dohřev recirkulátu<br/></span>Tepelný výkon: {:.1f} kWt<br/>Teplosměnná plocha: {:.1f} m<span style=\" vertical-align:super;\">2</span></p></body></html>""".format(-main.vysledkyMSF[-5],main.vysledkyMSF[-4])))
        self.lbFug.setText(_translate("Form", """<html><head/><body><p><span style=\" font-weight:600;\">
                                      Fugát/digestát<br/></span>Hmotnostní tok: {:.1f} kg/h<br/>Obsah sušiny: {:.2f} hm.%</p></body></html>""".format(main.vysledkyMSF[0],main.vysledkyMSF[1])))
        self.lbConc.setText(_translate("Form", """<html><head/><body><p><span style=\" font-weight:600;\">
                                       Koncentrát<br/></span>Hmotnostní tok: {:.1f} kg/h<br/>Obsah sušiny: {:.2f} hm.%</p></body></html>""".format(main.vysledkyMSF[4],main.vysledkyMSF[5])))
        self.lbRec.setText(_translate("Form", """<html><head/><body><p><span style=\" font-weight:600;\">
                                      Recirkulát<br/></span>Hmotnostní tok: {:.1f} kg/h<br/>Obsah sušiny: {:.2f} hm.%</p></body></html>""".format(main.vysledkyMSF[2],main.vysledkyMSF[3])))
        self.lbCond.setText(_translate("Form", """<html><head/><body><p><span style=\" font-weight:600;\">
                                       Kondenzační sekce<br/></span>Celková teplosměnná plocha: {:.1f} m<span style=\" vertical-align:super;\">2</span><br/>Počet komor chlazených vodou: {:d}</p></body></html>""".format(main.vysledkyMSF[-3],main.vysledkyMSF[-2])))
        self.lbElec.setText(_translate("Form", """<html><head/><body><p><span style=\" font-weight:600;\">
                                       Čerpadla, vývěva<br/></span>Celková elektrická spotřeba: {:.1f} kWe</p></body></html>""".format(-main.vysledkyMSF[-1])))
        self.lbDest.setText(_translate("Form", """<html><head/><body><p><span style=\" font-weight:600;\">
                                       Destilát<br/></span>Hmotnostní tok: {:.1f} kg/h<br/>Obsah sušiny: {:.2f} hm.%</p></body></html>""".format(main.vysledkyMSF[6],main.vysledkyMSF[7])))
        self.lbHeading.setText(_translate("Form", "<html><head/><body><p><span style=\" font-size:14pt;\">Dvanáctistupňová mžiková odparka</span></p></body></html>"))
        self.lbCopyright.setText(_translate("Form", "<html><head/><body><p><span style=\" color:#888888;\">Obrázek © Mgr. Ing. Marek Vondra, Ph. D.</span></p></body></html>"))
            
    def PrintScreen(self):
        self.setStyleSheet("background-color: white;")
        self.btnSave.setVisible(False)
        name, _ = QtWidgets.QFileDialog.getSaveFileName(self, "Uložení schématu",
                                                         "/schemeMSF",
                                                         "PNG (*.png)")
        p = self.grab()
        p.save(name)
        self.setStyleSheet("background-color: palette(window);")
        self.btnSave.setVisible(True)

if __name__ == "__main__":
    import sys
    if not QtWidgets.QApplication.instance():
        app = QtWidgets.QApplication(sys.argv)
    else:
        app = QtWidgets.QApplication.instance() 
    main = Ui_Main()
    sys.exit(app.exec_())
    