Extract Qt GUI code from main.py into separate interface/desktop dir

This commit is contained in:
Debanjum Singh Solanky
2022-08-09 22:12:29 +03:00
parent cd59982c9c
commit 664713b24e
4 changed files with 117 additions and 105 deletions

View File

@@ -0,0 +1,43 @@
# Standard Packages
import webbrowser
# External Packages
from PyQt6 import QtGui, QtWidgets
# Internal Packages
from src.utils import constants
def create_system_tray(gui: QtWidgets.QApplication, window: QtWidgets.QMainWindow):
"""Create System Tray with Menu
Menu Actions should contain
1. option to open search page at localhost:8000/
2. option to open config page at localhost:8000/config
3. to quit
"""
# Create the system tray with icon
icon_path = constants.web_directory / 'assets/icons/favicon-144x144.png'
icon = QtGui.QIcon(f'{icon_path.absolute()}')
tray = QtWidgets.QSystemTrayIcon(icon)
tray.setVisible(True)
# Create the menu and menu actions
menu = QtWidgets.QMenu()
menu_actions = [
('Search', lambda: webbrowser.open('http://localhost:8000/')),
('Configure', window.show),
('Quit', gui.quit),
]
# Add the menu actions to the menu
for action_text, action_function in menu_actions:
menu_action = QtGui.QAction(action_text, menu)
menu_action.triggered.connect(action_function)
menu.addAction(menu_action)
# Add the menu to the system tray
tray.setContextMenu(menu)
return tray