mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-05 21:29:11 +00:00
Extract Qt GUI code from main.py into separate interface/desktop dir
This commit is contained in:
43
src/interface/desktop/system_tray.py
Normal file
43
src/interface/desktop/system_tray.py
Normal 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
|
||||
|
||||
Reference in New Issue
Block a user