from PyQt5.QtWidgets import QApplication, QStyleFactory
from PyQt5.QtCore import QFile, QTextStream
from UI.MainWindow import MainWindow
from model.ClientModel.Client import Client

from utils import Globals


import time
import sys

class CommonHelper:
    def __init__(self):
        pass

    @staticmethod
    def readLocalQss(path):
        with open(path,"r") as f:
            return f.read()

    @staticmethod
    def readQrcQss(path):
        stream = QFile(':/' + path)
        stream.open(QFile.ReadOnly | QFile.Text)
        styleSheet = QTextStream(stream).readAll()
        stream.close()
        return styleSheet

if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setStyle(QStyleFactory.create('windowsvisio'))
    from Static.Png import qInitResources
    qInitResources()
    # from Static.QSS import qInitResources
    # qInitResources()
    # app.setStyleSheet(CommonHelper.readQrcQss('static/Main.qss') + CommonHelper.readQrcQss('static/Area.qss'))
    app.setStyleSheet(CommonHelper.readLocalQss('Static/Main.qss') + CommonHelper.readLocalQss('Static/Area.qss'))
    Globals._init()
    Client.initDB()
    window = MainWindow()
    window.showFullScreen()
    Globals.setValue('MainWindow', window)
    # window.show()
    sys.exit(app.exec_())