developing gui

This commit is contained in:
BarsTiger
2022-05-18 16:29:18 +03:00
parent 2a6503c89c
commit 4c775bf4b1
2 changed files with 81 additions and 5 deletions

View File

@@ -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_())

View File

@@ -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: