developing gui
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
|
# Imports
|
||||||
import sys
|
import sys
|
||||||
from PyQt5 import QtWidgets, QtCore
|
from PyQt5 import QtWidgets, QtCore
|
||||||
from data.settings import Settings
|
from data.settings import Settings
|
||||||
|
import pusher
|
||||||
|
import pysher
|
||||||
sys.path.append('gui')
|
sys.path.append('gui')
|
||||||
|
# Importing the main window
|
||||||
try:
|
try:
|
||||||
from gui import Ui_MainWindow
|
from gui import Ui_MainWindow
|
||||||
from functions import *
|
from functions import *
|
||||||
@@ -10,24 +13,61 @@ except ImportError:
|
|||||||
from gui.gui import Ui_MainWindow
|
from gui.gui import Ui_MainWindow
|
||||||
from gui.functions import *
|
from gui.functions import *
|
||||||
|
|
||||||
|
# Getting config
|
||||||
settings = Settings.get_settings()
|
settings = Settings.get_settings()
|
||||||
|
|
||||||
|
# Global variables for annotations
|
||||||
|
client = pusher.Pusher
|
||||||
|
receiver = pysher.Pusher
|
||||||
|
|
||||||
|
# Initializing the main window
|
||||||
app = QtWidgets.QApplication(sys.argv)
|
app = QtWidgets.QApplication(sys.argv)
|
||||||
MainWindow = QtWidgets.QMainWindow()
|
MainWindow = QtWidgets.QMainWindow()
|
||||||
ui = Ui_MainWindow()
|
ui = Ui_MainWindow()
|
||||||
ui.setupUi(MainWindow)
|
ui.setupUi(MainWindow)
|
||||||
ui.pagesWidget.setCurrentIndex(0)
|
ui.pagesWidget.setCurrentIndex(0)
|
||||||
|
|
||||||
|
# Trying to get settings or set default
|
||||||
try:
|
try:
|
||||||
fill_settings(ui)
|
fill_settings(ui)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
Settings.fix()
|
Settings.fix()
|
||||||
|
|
||||||
|
# Creating gui
|
||||||
MainWindow.show()
|
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()
|
width = ui.leftMenu.geometry().width()
|
||||||
Ui_MainWindow.animation = QtCore.QPropertyAnimation(ui.leftMenu, b"minimumWidth")
|
Ui_MainWindow.animation = QtCore.QPropertyAnimation(ui.leftMenu, b"minimumWidth")
|
||||||
Ui_MainWindow.animation.setDuration(Settings.animation()["timing"])
|
Ui_MainWindow.animation.setDuration(Settings.animation()["timing"])
|
||||||
@@ -42,10 +82,15 @@ def openMenu() -> None:
|
|||||||
Ui_MainWindow.animation.start()
|
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:
|
match text:
|
||||||
case "Menu":
|
case "Menu":
|
||||||
openMenu()
|
open_menu()
|
||||||
case "Devices":
|
case "Devices":
|
||||||
ui.pagesWidget.setCurrentIndex(1)
|
ui.pagesWidget.setCurrentIndex(1)
|
||||||
case "Screenshot":
|
case "Screenshot":
|
||||||
@@ -62,7 +107,23 @@ def handleMenuClick(text: str) -> None:
|
|||||||
ui.pagesWidget.setCurrentIndex(7)
|
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))
|
ui.saveSettingsButton.clicked.connect(lambda: update_settings(ui))
|
||||||
|
|
||||||
|
# Handling closing of the window to exit whole program
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|||||||
@@ -1,4 +1,19 @@
|
|||||||
from data.settings import Settings
|
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:
|
def fill_settings(ui) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user