"""@file app.py
@brief GUI for a calculator app
@author Libor Novotny (xnovot2j), Tomas Drdla (xdrdla04), Martin Hemza (xhemza05), Petr Sima (xsimap00)
"""

from mathlib import calc_math as m
import os
import sys
import platform
import subprocess

from PySide6.QtCore import QCoreApplication, QMetaObject, QPoint, QSize, Qt
from PySide6.QtGui import QFont, QFontDatabase, QIcon, QKeySequence
from PySide6.QtWidgets import QApplication, QFrame, QHBoxLayout, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget

class Ui_MainWindow(object):

    """GUI initialization function
    @param MainWindow Application window object
    """
    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(300, 438)
        MainWindow.setMinimumSize(QSize(300, 438))
        MainWindow.setMaximumSize(QSize(300, 438))
        MainWindow.setAcceptDrops(False)
        MainWindow.setWindowFlags(Qt.FramelessWindowHint)
        MainWindow.setAttribute(Qt.WA_TranslucentBackground)
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.centralwidget.setStyleSheet(u"background-color: rgba( 255, 255, 255, 0% );")
        self.verticalLayout = QVBoxLayout(self.centralwidget)
        self.verticalLayout.setSpacing(0)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.top_half_frame = QFrame(self.centralwidget)
        self.top_half_frame.setObjectName(u"top_half_frame")
        self.top_half_frame.setMaximumSize(QSize(16777215, 150))
        self.top_half_frame.setAutoFillBackground(False)
        self.top_half_frame.setStyleSheet(u"background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(89, 177, 223, 255), stop:1 rgba(77, 104, 234, 255));\n"
"border-width: 2px;\n"
"border-top-left-radius: 10px;\n"
"border-top-right-radius: 10px;\n"
"border-color: rgb(128, 204, 255);\n"
"border-style: solid;\n"
"border-bottom-width:0px;")
        self.top_half_frame.setFrameShape(QFrame.StyledPanel)
        self.top_half_frame.setFrameShadow(QFrame.Raised)
        self.verticalLayout_2 = QVBoxLayout(self.top_half_frame)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.title_frame = QFrame(self.top_half_frame)
        self.title_frame.setObjectName(u"title_frame")
        self.title_frame.setMinimumSize(QSize(0, 35))
        self.title_frame.setMaximumSize(QSize(16777215, 35))
        self.title_frame.setStyleSheet(u"background-color: rgba( 255, 255, 255, 0% );border-style:none;")
        self.title_frame.setFrameShape(QFrame.StyledPanel)
        self.title_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout = QHBoxLayout(self.title_frame)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.help_frame = QFrame(self.title_frame)
        self.help_frame.setObjectName(u"help_frame")
        self.help_frame.setStyleSheet(u"background-color: rgba( 255, 255, 255, 0% );")
        self.help_frame.setFrameShape(QFrame.StyledPanel)
        self.help_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_2 = QHBoxLayout(self.help_frame)
        self.horizontalLayout_2.setSpacing(0)
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.horizontalLayout_2.setContentsMargins(1, 1, 1, 1)
        self.help_bttn = QPushButton(self.help_frame)
        self.help_bttn.setObjectName(u"help_bttn")
        self.help_bttn.setStyleSheet(u"background-color: rgba( 255, 255, 255, 0% );")
        icon = QIcon()
        if getattr(sys, 'frozen', False):
            icon.addFile(os.path.join(sys._MEIPASS, "resources/filter-left.svg"), QSize(), QIcon.Normal, QIcon.Off)
        else:
            icon.addFile(u"resources/filter-left.svg", QSize(), QIcon.Normal, QIcon.Off)
        self.help_bttn.setIcon(icon)
        self.help_bttn.setIconSize(QSize(30, 30))

        self.horizontalLayout_2.addWidget(self.help_bttn, 0, Qt.AlignLeft|Qt.AlignTop)


        self.horizontalLayout.addWidget(self.help_frame, 0, Qt.AlignTop)

        self.app_name_frame = QFrame(self.title_frame)
        self.app_name_frame.setObjectName(u"app_name_frame")
        self.app_name_frame.setStyleSheet(u"background-color: rgba( 255, 255, 255, 0% );")
        self.app_name_frame.setFrameShape(QFrame.StyledPanel)
        self.app_name_frame.setFrameShadow(QFrame.Raised)

        self.horizontalLayout.addWidget(self.app_name_frame, 0, Qt.AlignTop)

        self.win_controls_frame = QFrame(self.title_frame)
        self.win_controls_frame.setObjectName(u"win_controls_frame")
        self.win_controls_frame.setFrameShape(QFrame.StyledPanel)
        self.win_controls_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_3 = QHBoxLayout(self.win_controls_frame)
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.horizontalLayout_3.setContentsMargins(3, 3, 3, 3)
        self.minimize_bttn = QPushButton(self.win_controls_frame)
        self.minimize_bttn.setObjectName(u"minimize_bttn")
        icon1 = QIcon()
        if getattr(sys, 'frozen', False):
            icon1.addFile(os.path.join(sys._MEIPASS, "resources/dash.svg"), QSize(), QIcon.Normal, QIcon.Off)
        else:
            icon1.addFile(u"resources/dash.svg", QSize(), QIcon.Normal, QIcon.Off)
        self.minimize_bttn.setIcon(icon1)
        self.minimize_bttn.setIconSize(QSize(26, 26))

        self.horizontalLayout_3.addWidget(self.minimize_bttn, 0, Qt.AlignRight|Qt.AlignTop)

        self.close_bttn = QPushButton(self.win_controls_frame)
        self.close_bttn.setObjectName(u"close_bttn")
        icon2 = QIcon()
        if getattr(sys, 'frozen', False):
            icon2.addFile(os.path.join(sys._MEIPASS, "resources/x.svg"), QSize(), QIcon.Normal, QIcon.Off)
        else:
            icon2.addFile(u"resources/x.svg", QSize(), QIcon.Normal, QIcon.Off)
        self.close_bttn.setIcon(icon2)
        self.close_bttn.setIconSize(QSize(26, 26))

        self.horizontalLayout_3.addWidget(self.close_bttn, 0, Qt.AlignRight|Qt.AlignTop)


        self.horizontalLayout.addWidget(self.win_controls_frame, 0, Qt.AlignTop)


        self.verticalLayout_2.addWidget(self.title_frame)

        self.num_frame = QFrame(self.top_half_frame)
        self.num_frame.setObjectName(u"num_frame")
        self.num_frame.setMaximumSize(QSize(16777215, 100))
        self.num_frame.setStyleSheet(u"background-color: rgba( 255, 255, 255, 0% );\n"
"border-style:none;")
        self.num_frame.setFrameShape(QFrame.StyledPanel)
        self.num_frame.setFrameShadow(QFrame.Raised)
        self.verticalLayout_3 = QVBoxLayout(self.num_frame)
        self.verticalLayout_3.setSpacing(0)
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.verticalLayout_3.setContentsMargins(8, 8, 8, 8)
        self.last_num = QLabel(self.num_frame)
        self.last_num.setObjectName(u"last_num")
        self.last_num.setMinimumSize(QSize(0, 20))
        font = QFont("Roboto")
        font.setPointSize(17*font_scale)
        self.last_num.setFont(font)
        self.last_num.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)
        self.last_num.setStyleSheet(u"color: white;")

        self.verticalLayout_3.addWidget(self.last_num, 0, Qt.AlignRight)

        self.c_num = QLabel(self.num_frame)
        self.c_num.setObjectName(u"c_num")
        self.c_num.setMinimumSize(QSize(0, 37))
        font1 = QFont("DIN Alternate")
        font1.setPointSize(40*font_scale)
        font1.setBold(True)
        self.c_num.setFont(font1)
        self.c_num.setLayoutDirection(Qt.LeftToRight)
        self.c_num.setScaledContents(False)
        self.c_num.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)
        self.c_num.setWordWrap(False)
        self.c_num.setStyleSheet(u"color: white;")

        self.verticalLayout_3.addWidget(self.c_num, 0, Qt.AlignRight)


        self.verticalLayout_2.addWidget(self.num_frame, 0, Qt.AlignRight)


        self.verticalLayout.addWidget(self.top_half_frame)

        self.bttm_half_frame = QFrame(self.centralwidget)
        self.bttm_half_frame.setObjectName(u"bttm_half_frame")
        font2 = QFont("Roboto")
        font2.setPointSize(18*font_scale)
        font2.setBold(True)
        font2.setItalic(True)
        self.bttm_half_frame.setFont(font2)
        self.bttm_half_frame.setStyleSheet(u"background-color: rgb(249, 248, 250);\n"
"border-bottom-left-radius: 10px;\n"
"border-bottom-right-radius: 10px;\n"
"border-width: 2px;\n"
"border-color: rgb(128, 204, 255);\n"
"border-style: solid;\n"
"border-top-width:0px;\n"
"color: rgb(18, 31, 77);")
        self.bttm_half_frame.setFrameShape(QFrame.StyledPanel)
        self.bttm_half_frame.setFrameShadow(QFrame.Raised)
        self.verticalLayout_4 = QVBoxLayout(self.bttm_half_frame)
        self.verticalLayout_4.setSpacing(0)
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.verticalLayout_4.setContentsMargins(16, 8, 16, 8)
        self.first_row = QFrame(self.bttm_half_frame)
        self.first_row.setObjectName(u"first_row")
        font3 = QFont("Roboto")
        font3.setPointSize(18*font_scale)
        font3.setBold(True)
        self.first_row.setFont(font3)
        self.first_row.setStyleSheet(u"background-color: none; border-radius: 0; border-style: none;")
        self.first_row.setFrameShape(QFrame.StyledPanel)
        self.first_row.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_4 = QHBoxLayout(self.first_row)
        self.horizontalLayout_4.setSpacing(16)
        self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
        self.horizontalLayout_4.setContentsMargins(0, 8, 0, 8)
        self.fn_frame = QFrame(self.first_row)
        self.fn_frame.setObjectName(u"fn_frame")
        self.fn_frame.setFont(font3)
        self.fn_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.fn_frame.setFrameShape(QFrame.StyledPanel)
        self.fn_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_5 = QHBoxLayout(self.fn_frame)
        self.horizontalLayout_5.setSpacing(0)
        self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
        self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
        self.fn_bttn = QPushButton(self.fn_frame)
        self.fn_bttn.setObjectName(u"fn_bttn")
        self.fn_bttn.setMinimumSize(QSize(0, 36))
        self.fn_bttn.setFont(font3)
        self.fn_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_5.addWidget(self.fn_bttn)


        self.horizontalLayout_4.addWidget(self.fn_frame)

        self.polar_frame = QFrame(self.first_row)
        self.polar_frame.setObjectName(u"polar_frame")
        self.polar_frame.setFont(font3)
        self.polar_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.polar_frame.setFrameShape(QFrame.StyledPanel)
        self.polar_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_7 = QHBoxLayout(self.polar_frame)
        self.horizontalLayout_7.setSpacing(0)
        self.horizontalLayout_7.setObjectName(u"horizontalLayout_7")
        self.horizontalLayout_7.setContentsMargins(0, 0, 0, 0)
        self.polar_bttn = QPushButton(self.polar_frame)
        self.polar_bttn.setObjectName(u"polar_bttn")
        self.polar_bttn.setMinimumSize(QSize(0, 36))
        self.polar_bttn.setFont(font3)
        self.polar_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_7.addWidget(self.polar_bttn)


        self.horizontalLayout_4.addWidget(self.polar_frame)

        self.del_frame = QFrame(self.first_row)
        self.del_frame.setObjectName(u"del_frame")
        self.del_frame.setFont(font3)
        self.del_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.del_frame.setFrameShape(QFrame.StyledPanel)
        self.del_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_8 = QHBoxLayout(self.del_frame)
        self.horizontalLayout_8.setSpacing(0)
        self.horizontalLayout_8.setObjectName(u"horizontalLayout_8")
        self.horizontalLayout_8.setContentsMargins(0, 0, 0, 0)
        self.del_bttn = QPushButton(self.del_frame)
        self.del_bttn.setObjectName(u"del_bttn")
        self.del_bttn.setMinimumSize(QSize(0, 36))
        self.del_bttn.setFont(font3)
        self.del_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_8.addWidget(self.del_bttn)


        self.horizontalLayout_4.addWidget(self.del_frame)

        self.div_frame = QFrame(self.first_row)
        self.div_frame.setObjectName(u"div_frame")
        self.div_frame.setFont(font3)
        self.div_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.div_frame.setFrameShape(QFrame.StyledPanel)
        self.div_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_9 = QHBoxLayout(self.div_frame)
        self.horizontalLayout_9.setSpacing(0)
        self.horizontalLayout_9.setObjectName(u"horizontalLayout_9")
        self.horizontalLayout_9.setContentsMargins(0, 0, 0, 0)
        self.div_bttn = QPushButton(self.div_frame)
        self.div_bttn.setObjectName(u"div_bttn")
        self.div_bttn.setMinimumSize(QSize(0, 36))
        self.div_bttn.setFont(font3)
        self.div_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_9.addWidget(self.div_bttn)


        self.horizontalLayout_4.addWidget(self.div_frame)


        self.verticalLayout_4.addWidget(self.first_row)

        self.second_row = QFrame(self.bttm_half_frame)
        self.second_row.setObjectName(u"second_row")
        self.second_row.setFont(font3)
        self.second_row.setStyleSheet(u"background-color: none; border-radius: 0; border-style: none;")
        self.second_row.setFrameShape(QFrame.StyledPanel)
        self.second_row.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_6 = QHBoxLayout(self.second_row)
        self.horizontalLayout_6.setSpacing(16)
        self.horizontalLayout_6.setObjectName(u"horizontalLayout_6")
        self.horizontalLayout_6.setContentsMargins(0, 8, 0, 8)
        self.seven_frame = QFrame(self.second_row)
        self.seven_frame.setObjectName(u"seven_frame")
        self.seven_frame.setFont(font3)
        self.seven_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.seven_frame.setFrameShape(QFrame.StyledPanel)
        self.seven_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_10 = QHBoxLayout(self.seven_frame)
        self.horizontalLayout_10.setSpacing(0)
        self.horizontalLayout_10.setObjectName(u"horizontalLayout_10")
        self.horizontalLayout_10.setContentsMargins(0, 0, 0, 0)
        self.seven_bttn = QPushButton(self.seven_frame)
        self.seven_bttn.setObjectName(u"seven_bttn")
        self.seven_bttn.setMinimumSize(QSize(0, 36))
        self.seven_bttn.setFont(font3)
        self.seven_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_10.addWidget(self.seven_bttn)


        self.horizontalLayout_6.addWidget(self.seven_frame)

        self.eight_frame = QFrame(self.second_row)
        self.eight_frame.setObjectName(u"eight_frame")
        self.eight_frame.setFont(font3)
        self.eight_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.eight_frame.setFrameShape(QFrame.StyledPanel)
        self.eight_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_11 = QHBoxLayout(self.eight_frame)
        self.horizontalLayout_11.setSpacing(0)
        self.horizontalLayout_11.setObjectName(u"horizontalLayout_11")
        self.horizontalLayout_11.setContentsMargins(0, 0, 0, 0)
        self.eight_bttn = QPushButton(self.eight_frame)
        self.eight_bttn.setObjectName(u"eight_bttn")
        self.eight_bttn.setMinimumSize(QSize(0, 36))
        self.eight_bttn.setFont(font3)
        self.eight_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_11.addWidget(self.eight_bttn)


        self.horizontalLayout_6.addWidget(self.eight_frame)

        self.nine_frame = QFrame(self.second_row)
        self.nine_frame.setObjectName(u"nine_frame")
        self.nine_frame.setFont(font3)
        self.nine_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.nine_frame.setFrameShape(QFrame.StyledPanel)
        self.nine_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_12 = QHBoxLayout(self.nine_frame)
        self.horizontalLayout_12.setSpacing(0)
        self.horizontalLayout_12.setObjectName(u"horizontalLayout_12")
        self.horizontalLayout_12.setContentsMargins(0, 0, 0, 0)
        self.nine_bttn = QPushButton(self.nine_frame)
        self.nine_bttn.setObjectName(u"nine_bttn")
        self.nine_bttn.setMinimumSize(QSize(0, 36))
        self.nine_bttn.setFont(font3)
        self.nine_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_12.addWidget(self.nine_bttn)


        self.horizontalLayout_6.addWidget(self.nine_frame)

        self.mul_frame = QFrame(self.second_row)
        self.mul_frame.setObjectName(u"mul_frame")
        self.mul_frame.setFont(font3)
        self.mul_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.mul_frame.setFrameShape(QFrame.StyledPanel)
        self.mul_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_13 = QHBoxLayout(self.mul_frame)
        self.horizontalLayout_13.setSpacing(0)
        self.horizontalLayout_13.setObjectName(u"horizontalLayout_13")
        self.horizontalLayout_13.setContentsMargins(0, 0, 0, 0)
        self.mul_bttn = QPushButton(self.mul_frame)
        self.mul_bttn.setObjectName(u"mul_bttn")
        self.mul_bttn.setMinimumSize(QSize(0, 36))
        self.mul_bttn.setFont(font3)
        self.mul_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_13.addWidget(self.mul_bttn)


        self.horizontalLayout_6.addWidget(self.mul_frame)


        self.verticalLayout_4.addWidget(self.second_row)

        self.third_row = QFrame(self.bttm_half_frame)
        self.third_row.setObjectName(u"third_row")
        self.third_row.setFont(font3)
        self.third_row.setStyleSheet(u"background-color: none; border-radius: 0; border-style: none;")
        self.third_row.setFrameShape(QFrame.StyledPanel)
        self.third_row.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_14 = QHBoxLayout(self.third_row)
        self.horizontalLayout_14.setSpacing(16)
        self.horizontalLayout_14.setObjectName(u"horizontalLayout_14")
        self.horizontalLayout_14.setContentsMargins(0, 8, 0, 8)
        self.four_frame = QFrame(self.third_row)
        self.four_frame.setObjectName(u"four_frame")
        self.four_frame.setFont(font3)
        self.four_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.four_frame.setFrameShape(QFrame.StyledPanel)
        self.four_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_15 = QHBoxLayout(self.four_frame)
        self.horizontalLayout_15.setSpacing(0)
        self.horizontalLayout_15.setObjectName(u"horizontalLayout_15")
        self.horizontalLayout_15.setContentsMargins(0, 0, 0, 0)
        self.four_bttn = QPushButton(self.four_frame)
        self.four_bttn.setObjectName(u"four_bttn")
        self.four_bttn.setMinimumSize(QSize(0, 36))
        self.four_bttn.setFont(font3)
        self.four_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_15.addWidget(self.four_bttn)


        self.horizontalLayout_14.addWidget(self.four_frame)

        self.five_frame = QFrame(self.third_row)
        self.five_frame.setObjectName(u"five_frame")
        self.five_frame.setFont(font3)
        self.five_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.five_frame.setFrameShape(QFrame.StyledPanel)
        self.five_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_16 = QHBoxLayout(self.five_frame)
        self.horizontalLayout_16.setSpacing(0)
        self.horizontalLayout_16.setObjectName(u"horizontalLayout_16")
        self.horizontalLayout_16.setContentsMargins(0, 0, 0, 0)
        self.five_bttn = QPushButton(self.five_frame)
        self.five_bttn.setObjectName(u"five_bttn")
        self.five_bttn.setMinimumSize(QSize(0, 36))
        self.five_bttn.setFont(font3)
        self.five_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_16.addWidget(self.five_bttn)


        self.horizontalLayout_14.addWidget(self.five_frame)

        self.six_frame = QFrame(self.third_row)
        self.six_frame.setObjectName(u"six_frame")
        self.six_frame.setFont(font3)
        self.six_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.six_frame.setFrameShape(QFrame.StyledPanel)
        self.six_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_17 = QHBoxLayout(self.six_frame)
        self.horizontalLayout_17.setSpacing(0)
        self.horizontalLayout_17.setObjectName(u"horizontalLayout_17")
        self.horizontalLayout_17.setContentsMargins(0, 0, 0, 0)
        self.six_bttn = QPushButton(self.six_frame)
        self.six_bttn.setObjectName(u"six_bttn")
        self.six_bttn.setMinimumSize(QSize(0, 36))
        self.six_bttn.setFont(font3)
        self.six_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_17.addWidget(self.six_bttn)


        self.horizontalLayout_14.addWidget(self.six_frame)

        self.min_frame = QFrame(self.third_row)
        self.min_frame.setObjectName(u"min_frame")
        self.min_frame.setFont(font3)
        self.min_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.min_frame.setFrameShape(QFrame.StyledPanel)
        self.min_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_18 = QHBoxLayout(self.min_frame)
        self.horizontalLayout_18.setSpacing(0)
        self.horizontalLayout_18.setObjectName(u"horizontalLayout_18")
        self.horizontalLayout_18.setContentsMargins(0, 0, 0, 0)
        self.min_bttn = QPushButton(self.min_frame)
        self.min_bttn.setObjectName(u"min_bttn")
        self.min_bttn.setMinimumSize(QSize(0, 36))
        self.min_bttn.setFont(font3)
        self.min_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_18.addWidget(self.min_bttn)


        self.horizontalLayout_14.addWidget(self.min_frame)


        self.verticalLayout_4.addWidget(self.third_row)

        self.fourth_row = QFrame(self.bttm_half_frame)
        self.fourth_row.setObjectName(u"fourth_row")
        self.fourth_row.setFont(font3)
        self.fourth_row.setStyleSheet(u"background-color: none; border-radius: 0; border-style: none;")
        self.fourth_row.setFrameShape(QFrame.StyledPanel)
        self.fourth_row.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_19 = QHBoxLayout(self.fourth_row)
        self.horizontalLayout_19.setSpacing(16)
        self.horizontalLayout_19.setObjectName(u"horizontalLayout_19")
        self.horizontalLayout_19.setContentsMargins(0, 8, 0, 8)
        self.one_frame = QFrame(self.fourth_row)
        self.one_frame.setObjectName(u"one_frame")
        self.one_frame.setFont(font3)
        self.one_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.one_frame.setFrameShape(QFrame.StyledPanel)
        self.one_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_20 = QHBoxLayout(self.one_frame)
        self.horizontalLayout_20.setSpacing(0)
        self.horizontalLayout_20.setObjectName(u"horizontalLayout_20")
        self.horizontalLayout_20.setContentsMargins(0, 0, 0, 0)
        self.one_bttn = QPushButton(self.one_frame)
        self.one_bttn.setObjectName(u"one_bttn")
        self.one_bttn.setMinimumSize(QSize(0, 36))
        self.one_bttn.setFont(font3)
        self.one_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_20.addWidget(self.one_bttn)


        self.horizontalLayout_19.addWidget(self.one_frame)

        self.two_frame = QFrame(self.fourth_row)
        self.two_frame.setObjectName(u"two_frame")
        self.two_frame.setFont(font3)
        self.two_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.two_frame.setFrameShape(QFrame.StyledPanel)
        self.two_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_21 = QHBoxLayout(self.two_frame)
        self.horizontalLayout_21.setSpacing(0)
        self.horizontalLayout_21.setObjectName(u"horizontalLayout_21")
        self.horizontalLayout_21.setContentsMargins(0, 0, 0, 0)
        self.two_bttn = QPushButton(self.two_frame)
        self.two_bttn.setObjectName(u"two_bttn")
        self.two_bttn.setMinimumSize(QSize(0, 36))
        self.two_bttn.setFont(font3)
        self.two_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_21.addWidget(self.two_bttn)


        self.horizontalLayout_19.addWidget(self.two_frame)

        self.three_frame = QFrame(self.fourth_row)
        self.three_frame.setObjectName(u"three_frame")
        self.three_frame.setFont(font3)
        self.three_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.three_frame.setFrameShape(QFrame.StyledPanel)
        self.three_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_22 = QHBoxLayout(self.three_frame)
        self.horizontalLayout_22.setSpacing(0)
        self.horizontalLayout_22.setObjectName(u"horizontalLayout_22")
        self.horizontalLayout_22.setContentsMargins(0, 0, 0, 0)
        self.three_bttn = QPushButton(self.three_frame)
        self.three_bttn.setObjectName(u"three_bttn")
        self.three_bttn.setMinimumSize(QSize(0, 36))
        self.three_bttn.setFont(font3)
        self.three_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_22.addWidget(self.three_bttn)


        self.horizontalLayout_19.addWidget(self.three_frame)

        self.add_frame = QFrame(self.fourth_row)
        self.add_frame.setObjectName(u"add_frame")
        self.add_frame.setFont(font3)
        self.add_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.add_frame.setFrameShape(QFrame.StyledPanel)
        self.add_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_23 = QHBoxLayout(self.add_frame)
        self.horizontalLayout_23.setSpacing(0)
        self.horizontalLayout_23.setObjectName(u"horizontalLayout_23")
        self.horizontalLayout_23.setContentsMargins(0, 0, 0, 0)
        self.add_bttn = QPushButton(self.add_frame)
        self.add_bttn.setObjectName(u"add_bttn")
        self.add_bttn.setMinimumSize(QSize(0, 36))
        self.add_bttn.setFont(font3)
        self.add_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_23.addWidget(self.add_bttn)


        self.horizontalLayout_19.addWidget(self.add_frame)


        self.verticalLayout_4.addWidget(self.fourth_row)

        self.fifth_row = QFrame(self.bttm_half_frame)
        self.fifth_row.setObjectName(u"fifth_row")
        self.fifth_row.setFont(font3)
        self.fifth_row.setStyleSheet(u"background-color: none; border-radius: 0; border-style: none;")
        self.fifth_row.setFrameShape(QFrame.StyledPanel)
        self.fifth_row.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_24 = QHBoxLayout(self.fifth_row)
        self.horizontalLayout_24.setSpacing(16)
        self.horizontalLayout_24.setObjectName(u"horizontalLayout_24")
        self.horizontalLayout_24.setContentsMargins(0, 8, 0, 8)
        self.fifth_row_left = QFrame(self.fifth_row)
        self.fifth_row_left.setObjectName(u"fifth_row_left")
        self.fifth_row_left.setFrameShape(QFrame.StyledPanel)
        self.fifth_row_left.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_29 = QHBoxLayout(self.fifth_row_left)
        self.horizontalLayout_29.setObjectName(u"horizontalLayout_29")
        self.horizontalLayout_29.setContentsMargins(0, 0, 0, 0)
        self.zero_frame = QFrame(self.fifth_row_left)
        self.zero_frame.setObjectName(u"zero_frame")
        self.zero_frame.setFont(font3)
        self.zero_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.zero_frame.setFrameShape(QFrame.StyledPanel)
        self.zero_frame.setFrameShadow(QFrame.Raised)
        self.zero_frame.setLineWidth(1)
        self.horizontalLayout_25 = QHBoxLayout(self.zero_frame)
        self.horizontalLayout_25.setSpacing(0)
        self.horizontalLayout_25.setObjectName(u"horizontalLayout_25")
        self.horizontalLayout_25.setContentsMargins(0, 0, 0, 0)
        self.zero_bttn = QPushButton(self.zero_frame)
        self.zero_bttn.setObjectName(u"zero_bttn")
        self.zero_bttn.setMinimumSize(QSize(0, 36))
        self.zero_bttn.setFont(font3)
        self.zero_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_25.addWidget(self.zero_bttn)


        self.horizontalLayout_29.addWidget(self.zero_frame)


        self.horizontalLayout_24.addWidget(self.fifth_row_left)

        self.fifth_row_right = QFrame(self.fifth_row)
        self.fifth_row_right.setObjectName(u"fifth_row_right")
        self.fifth_row_right.setFrameShape(QFrame.StyledPanel)
        self.fifth_row_right.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_26 = QHBoxLayout(self.fifth_row_right)
        self.horizontalLayout_26.setSpacing(16)
        self.horizontalLayout_26.setObjectName(u"horizontalLayout_26")
        self.horizontalLayout_26.setContentsMargins(0, 0, 0, 0)
        self.point_frame = QFrame(self.fifth_row_right)
        self.point_frame.setObjectName(u"point_frame")
        self.point_frame.setFont(font3)
        self.point_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.point_frame.setFrameShape(QFrame.StyledPanel)
        self.point_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_27 = QHBoxLayout(self.point_frame)
        self.horizontalLayout_27.setSpacing(0)
        self.horizontalLayout_27.setObjectName(u"horizontalLayout_27")
        self.horizontalLayout_27.setContentsMargins(0, 0, 0, 0)
        self.point_bttn = QPushButton(self.point_frame)
        self.point_bttn.setObjectName(u"point_bttn")
        self.point_bttn.setMinimumSize(QSize(0, 36))
        self.point_bttn.setFont(font3)
        self.point_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_27.addWidget(self.point_bttn)


        self.horizontalLayout_26.addWidget(self.point_frame)

        self.equal_frame = QFrame(self.fifth_row_right)
        self.equal_frame.setObjectName(u"equal_frame")
        self.equal_frame.setFont(font3)
        self.equal_frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
"border-style: solid;\n"
"border-radius: 8px;\n"
"border-width: 1px;\n"
"background-color: white;")
        self.equal_frame.setFrameShape(QFrame.StyledPanel)
        self.equal_frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_28 = QHBoxLayout(self.equal_frame)
        self.horizontalLayout_28.setSpacing(0)
        self.horizontalLayout_28.setObjectName(u"horizontalLayout_28")
        self.horizontalLayout_28.setContentsMargins(0, 0, 0, 0)
        self.equal_bttn = QPushButton(self.equal_frame)
        self.equal_bttn.setObjectName(u"equal_bttn")
        self.equal_bttn.setMinimumSize(QSize(0, 36))
        self.equal_bttn.setFont(font3)
        self.equal_bttn.setStyleSheet(u"border-style: none;")

        self.horizontalLayout_28.addWidget(self.equal_bttn)


        self.horizontalLayout_26.addWidget(self.equal_frame)


        self.horizontalLayout_24.addWidget(self.fifth_row_right)


        self.verticalLayout_4.addWidget(self.fifth_row)


        self.verticalLayout.addWidget(self.bttm_half_frame)

        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)

        QMetaObject.connectSlotsByName(MainWindow)

    """Set up parameters of elemnts
    @param MainWindow Application window object
    """
    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
        
        self.help_bttn.setText("")
        self.minimize_bttn.setText("")
        self.close_bttn.setText("")

        self.last_num.setText(QCoreApplication.translate("MainWindow", u"", None))
        self.c_num.setText(QCoreApplication.translate("MainWindow", u"0", None))

        for x in    [["one","1"],
                    ["two","2"],
                    ["three","3"],
                    ["four","4"],
                    ["five","5"],
                    ["six","6"],
                    ["seven","7"],
                    ["eight","8"],
                    ["nine","9"],
                    ["zero","0"],
                    ["point",","],
                    ["del","del"],
                    ["polar","+ / -"],
                    ["fn","fn"],
                    ["div","/"],
                    ["mul","*"],
                    ["min","-"],
                    ["add","+"],
                    ["equal","="]]:
            
            exec(f'self.{x[0]}_bttn.setText(QCoreApplication.translate("MainWindow", u"{x[1]}", None))', {"self":self,"QCoreApplication":QCoreApplication})

class Calc(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.dragPos = QPoint()
        
        if platform.system() == "Darwin": # detecting platform for platform specific commands
            self.help_bttn.pressed.connect(lambda: subprocess.call(('open', os.path.dirname(__file__) + "/dokumentace.pdf")))
        else:
            if getattr(sys, 'frozen', False):
                self.help_bttn.pressed.connect(lambda: subprocess.call(('xdg-open', os.path.join(sys._MEIPASS, "/dokumentace.pdf"))))
            else:
                self.help_bttn.pressed.connect(lambda: subprocess.call(('xdg-open', os.path.dirname(__file__) + "dokumentace.pdf")))

        self.close_bttn.pressed.connect(self.close)
        self.minimize_bttn.pressed.connect(self.showMinimized)
        
        self.window_movable = True # used to make window immovable if eg. a button is pressed
        self.current_value = "" # stores input from user or output of operations
        self.prev_num = "" # stores left operand
        self.operation = ""
        self.fn = False # used to toggle special functions
        self.result = False # if the value in self.current_value is a result of an operation

        # linking anonymous functions to key press events
        for x in    [["one","1"],
                    ["two","2"],
                    ["three","3"],
                    ["four","4"],
                    ["five","5"],
                    ["six","6"],
                    ["seven","7"],
                    ["eight","8"],
                    ["nine","9"],
                    ["zero","0"],
                    ["point","."],
                    ["del","del"],
                    ["polar","polar"],
                    ["fn","fn"],
                    ["div","/"],
                    ["mul","*"],
                    ["min","-"],
                    ["add","+"],
                    ["equal","equal"]]:
            
            exec(f'self.{x[0]}_bttn.pressed.connect(lambda: self.bttn_pressed(self.{x[0]}_frame))', {"self":self})
            exec(f'self.{x[0]}_bttn.released.connect(lambda: self.bttn_released(self.{x[0]}_frame,"{x[1]}"))', {"self":self})
    
    """Changes color of the button if clicked
    @param frame parent frame inside which the button resides
    """
    def bttn_pressed(self, frame):
        self.window_movable = False
        frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
                             "border-style: solid;\n"
                             "border-radius: 8px;\n"
                             "border-width: 1px;\n"
                             "background-color: rgb(248, 247, 249);")

    """Calls a function from mathlib and displays the result
    """
    def calculate(self):
        for x in    [["/","div",2],
                    ["*","mul",2],
                    ["-","sub",2],
                    ["+","add",2],
                    ["rad","rad",2],
                    ["exp","exp",2],
                    ["log","log",2],
                    ["!","factor",1]]:
            if x[0] == self.operation:
                
                try:
                    exec(f'self.current_value = str(round(m.{x[1]}(float(0 if len(self.prev_num) == 0 else self.prev_num){",float(0 if len(self.current_value) == 0 else self.current_value)" if x[2] > 1 else ""}),5))',{"self":self,"m":m})
                except Exception:
                    self.current_value = "error"
                
                self.result = True
                self.prev_num = ""
                self.operation = ""
                
                if self.current_value[-2:] == ".0": # trim the result if is not a float
                    self.current_value = self.current_value[:-2]
    
    """Handles button press events 
    @param frame frame of the button
    """
    def bttn_released(self, frame, value):
        self.point = "." in self.current_value
        
        # detecting which button was pressed

        # clears the result of an operation after user starts putting in numbers
        if self.current_value == "0" or (self.result and value in ["1","2","3","4","5","6","7","8","9","0","del","."]):
            self.current_value = ""
            self.result = False

        # inserts new digits
        if value in "1234567890" or (value == "." and not self.point and len(self.current_value) > 0):
            self.current_value += value
        
        # deletes digits
        if value == "del":
            self.current_value = self.current_value[0:-1]
            if len(self.current_value) == 0:
                self.fn = False
                self.prev_num = ""
                self.operation = ""
        
        # makes number negative or positive
        if value == "polar" and len(self.current_value) > 0:
            if self.current_value[0] != "-":
                self.current_value = f'-{self.current_value}'
            else:
                self.current_value = self.current_value[1::]
        
        # shows or hides additional functions
        if value == "fn":
            self.fn = not self.fn
        
        # handeling operations
        if value in ["/","*","-","+"]:
            if self.operation != "":
                self.calculate()
            self.prev_num = "0" if self.current_value == "" else self.current_value
            self.current_value = ""
            
            if self.fn: # use different functions if fn is pressed
                if value == "/":
                    self.operation = "rad"
                elif value == "*":
                    self.operation = "exp"
                elif value == "-":
                    self.operation = "log"
                else:
                    self.operation = "!"
            else:
                self.operation = value
        
        # calculate the result
        if value == "equal" or self.operation == "!":
            self.calculate()
        
        # copy to clipboard
        if value == "copy":
            clipboard = QApplication.clipboard()
            clipboard.setText(self.current_value)
        
        # paste from clipboard
        if value == "paste":
            clipboard = QApplication.clipboard()
            try:
                self.current_value = str(float(clipboard.text()))
                if self.current_value[-2:] == ".0":
                    self.current_value = self.current_value[:-2]
            except ValueError:
                pass
        
        # paste from clipboard
        if len(self.current_value) == 0 or self.current_value == "-":
            self.current_value = "0"

        # shows or hides additional functions
        if self.fn:
            self.div_bttn.setText(QCoreApplication.translate("MainWindow", u"rad", None))
            self.mul_bttn.setText(QCoreApplication.translate("MainWindow", u"exp", None))
            self.min_bttn.setText(QCoreApplication.translate("MainWindow", u"log", None))
            self.add_bttn.setText(QCoreApplication.translate("MainWindow", u"fac", None))
        else:
            self.div_bttn.setText(QCoreApplication.translate("MainWindow", u"/", None))
            self.mul_bttn.setText(QCoreApplication.translate("MainWindow", u"*", None))
            self.min_bttn.setText(QCoreApplication.translate("MainWindow", u"-", None))
            self.add_bttn.setText(QCoreApplication.translate("MainWindow", u"+", None))
        
        font1 = QFont("DIN alternate")
        font1.setBold(True)
        
        # calculating font size based on the number of digits
        if len(self.current_value) > 13:
            font1.setPointSize((520/len(self.current_value))*font_scale)
        else:
            font1.setPointSize(40*font_scale)
        self.c_num.setFont(font1)
        
        if len(self.prev_num) > 30:
            font1.setPointSize((240/len(self.prev_num))*font_scale)
        else:
            font1.setPointSize(17*font_scale)
        self.last_num.setFont(font1)

        self.last_num.setText(QCoreApplication.translate("MainWindow", f'{self.prev_num} {self.operation}', None))
        self.c_num.setText(QCoreApplication.translate("MainWindow", self.current_value, None))
        
        # reset frame color
        if frame:
            frame.setStyleSheet(u"border-color: rgb(226, 225, 227);\n"
                                 "border-style: solid;\n"
                                 "border-radius: 8px;\n"
                                 "border-width: 1px;\n"
                                 "background-color: white;")

    """Handles mouse button press event
    @param event
    """
    def mousePressEvent(self, event):
        self.window_movable = True
        self.old_position = event.globalPosition().toPoint()
    
    """Handles mouse button move event
    @param event
    """
    def mouseMoveEvent(self, event):
        if self.window_movable:
            delta = QPoint(event.globalPosition().toPoint() - self.old_position)
            self.move(self.x() + delta.x(), self.y() + delta.y())
            self.old_position = event.globalPosition().toPoint()
    
    """Handles keyboard button press events
    @param e
    """
    def keyPressEvent(self, e):

        for x in    [["1","1"],
                    ["2","2"],
                    ["3","3"],
                    ["4","4"],
                    ["5","5"],
                    ["6","6"],
                    ["7","7"],
                    ["8","8"],
                    ["9","9"],
                    ["0","0"],
                    ["Period","."],
                    ["Backspace","del"],
                    ["Space","polar"],
                    ["F","fn"],
                    ["Slash","/"],
                    ["Asterisk","*"],
                    ["Minus","-"],
                    ["Plus","+"],
                    ["QKeySequence.Copy","copy"],
                    ["QKeySequence.Paste","paste"],
                    ["Return","equal"]]:
            
            exec(f"""{f'if e.matches({x[0]})' if len(x[0]) > 2 and x[0][0:4] == "QKey" else f'if e.key() == Qt.Key_{x[0]}'}:
                self.bttn_released(False,"{x[1]}")
            """)

if __name__ == "__main__":
    import sys
    
    app = QApplication(sys.argv)

    # importing files in different ways according to the platform
    if platform.system() == "Darwin":
        QFontDatabase.addApplicationFont(os.path.dirname(__file__) + "/resources/Roboto-Regular.ttf")
        QFontDatabase.addApplicationFont(os.path.dirname(__file__) + "/resources/DIN alternate.ttf")
        font_scale = 1
    else:
        if getattr(sys, 'frozen', False):
            QFontDatabase.addApplicationFont(os.path.join(sys._MEIPASS, "resources/Roboto-Regular.ttf"))
            QFontDatabase.addApplicationFont(os.path.join(sys._MEIPASS, "resources/DIN alternate.ttf"))
        else:
            QFontDatabase.addApplicationFont(os.path.dirname(__file__) + "resources/Roboto-Regular.ttf")
            QFontDatabase.addApplicationFont(os.path.dirname(__file__) + "resources/DIN alternate.ttf")
        font_scale = 0.75

    Calculator = Calc()
    Calculator.show()
    
    sys.exit(app.exec())

""" End of file app.py """