From 4c775bf4b1df65a88ec4bfb94e012f8026a71386 Mon Sep 17 00:00:00 2001 From: BarsTiger Date: Wed, 18 May 2022 16:29:18 +0300 Subject: [PATCH] developing gui --- admin/daunRat_admin.py | 71 +++++++++++++++++++++++++++++++++++++++--- admin/gui/functions.py | 15 +++++++++ 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/admin/daunRat_admin.py b/admin/daunRat_admin.py index af6e493..e91619e 100644 --- a/admin/daunRat_admin.py +++ b/admin/daunRat_admin.py @@ -1,8 +1,11 @@ +# Imports import sys from PyQt5 import QtWidgets, QtCore from data.settings import Settings +import pusher +import pysher sys.path.append('gui') - +# Importing the main window try: from gui import Ui_MainWindow from functions import * @@ -10,24 +13,61 @@ except ImportError: from gui.gui import Ui_MainWindow from gui.functions import * +# Getting config settings = Settings.get_settings() +# Global variables for annotations +client = pusher.Pusher +receiver = pysher.Pusher + +# Initializing the main window app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) ui.pagesWidget.setCurrentIndex(0) +# Trying to get settings or set default try: fill_settings(ui) except Exception as e: print(e) Settings.fix() +# Creating gui MainWindow.show() -def openMenu() -> None: +def initialize_pusher() -> None: + """ + Registers the pusher client and receiver + :return: + """ + global client + global receiver + client = pusher.Pusher( + app_id=settings["app_id"], + key=settings["key"], + secret=settings["secret"], + cluster=settings["cluster"], + ssl=False + ) + receiver = pysher.Pusher(key=settings["key"], cluster=settings["cluster"]) + receiver.connection.bind('pusher:connection_established', handle_connection_to_server) + try: + receiver.connect() + except Exception as e: + popup("Error", "Could not connect to pusher server\n" + "Do you have valid pusher config in settings tab?\n" + "Check full error message in console") + print(e) + + +def open_menu() -> None: + """ + Animates the menu to open and close, using animation from config + :return: + """ width = ui.leftMenu.geometry().width() Ui_MainWindow.animation = QtCore.QPropertyAnimation(ui.leftMenu, b"minimumWidth") Ui_MainWindow.animation.setDuration(Settings.animation()["timing"]) @@ -42,10 +82,15 @@ def openMenu() -> None: Ui_MainWindow.animation.start() -def handleMenuClick(text: str) -> None: +def handle_menu_click(text: str) -> None: + """ + Handles the click on the menu and changes the page + :param text: + :return: + """ match text: case "Menu": - openMenu() + open_menu() case "Devices": ui.pagesWidget.setCurrentIndex(1) case "Screenshot": @@ -62,7 +107,23 @@ def handleMenuClick(text: str) -> None: ui.pagesWidget.setCurrentIndex(7) -ui.leftMenu.itemClicked.connect(lambda: handleMenuClick(ui.leftMenu.currentItem().text())) +def handle_connection_to_server(connection) -> None: + """ + On pusher connection + :return: + """ + print("Connected to server") + print("Server returned: " + str(connection)) + for client_id_av in list(client.channels_info(prefix_filter='admin-')['channels']): + print("Channel: " + client_id_av) + + +# Trying to connect to pusher +initialize_pusher() + +# Connecting user interface to functions +ui.leftMenu.itemClicked.connect(lambda: handle_menu_click(ui.leftMenu.currentItem().text())) ui.saveSettingsButton.clicked.connect(lambda: update_settings(ui)) +# Handling closing of the window to exit whole program sys.exit(app.exec_()) diff --git a/admin/gui/functions.py b/admin/gui/functions.py index b210256..0c2454a 100644 --- a/admin/gui/functions.py +++ b/admin/gui/functions.py @@ -1,4 +1,19 @@ from data.settings import Settings +import ctypes + + +def popup(title, text, style=0): + """ + Styles: + 0 : OK + 1 : OK | Cancel + 2 : Abort | Retry | Ignore + 3 : Yes | No | Cancel + 4 : Yes | No + 5 : Retry | Cancel + 6 : Cancel | Try Again | Continue + """ + return ctypes.windll.user32.MessageBoxW(0, text, title, style) def fill_settings(ui) -> None: