This commit is contained in:
helldh 2025-12-25 21:44:30 +03:00
commit 3c2137da2b
9 changed files with 737 additions and 0 deletions

72
composer.py Normal file
View file

@ -0,0 +1,72 @@
from src.windows import LoginWindow, AdminWindow, ClientWindow
from src.objects import User, Rights
from src.db import DB_AUTH_HARDCODED as config
from PyQt6.QtWidgets import QApplication
from PyQt6.QtCore import QObject, pyqtSlot, pyqtSignal
from PyQt6.QtSql import QSqlDatabase
class Composer(QObject):
render_request = pyqtSignal(User)
def __init__(self):
super().__init__()
self._current = None
self._app = QApplication([])
self._init_db()
self.render_request.connect(self._render)
def _init_db(self):
self._db = QSqlDatabase("QPSQL")
self._db.setDatabaseName(config['dbname'])
self._db.setPort(config['port'])
self._db.setHostName(config['host'])
self._db.setUserName(config['user'])
self._db.setPassword(config['password'])
self._db.open()
@pyqtSlot(User)
def _render(self, user: User):
match user.rights:
case Rights.ADMIN:
self._admin_fabric()
case Rights.MANAGER:
pass
case Rights.CLIENT:
self._client_fabric(user)
def _login_fabric(self):
self.wlogin = LoginWindow(self, self._db)
if self._current:
self._current.close()
self.wlogin.show()
self._current = self.wlogin
def _admin_fabric(self):
self.wadmin = AdminWindow(self, self._db)
if self._current:
self._current.close()
self.wadmin.show()
self._current = self.wadmin
def _client_fabric(self, user: User):
self.wclient = ClientWindow(self, self._db, user)
if self._current:
self._current.close()
self.wclient.show()
self._current = self.wclient
def run(self):
import sys
self._login_fabric()
self._current.show()
sys.exit(self._app.exec())