mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Start Creating Native Configure Page using PyQt
This commit is contained in:
58
src/main.py
58
src/main.py
@@ -6,7 +6,8 @@ import webbrowser
|
|||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
from PyQt6 import QtGui, QtWidgets
|
||||||
|
from PyQt6.QtCore import Qt, QThread
|
||||||
|
|
||||||
# Internal Packages
|
# Internal Packages
|
||||||
from src.configure import configure_server
|
from src.configure import configure_server
|
||||||
@@ -28,6 +29,7 @@ def run():
|
|||||||
gui = QtWidgets.QApplication([])
|
gui = QtWidgets.QApplication([])
|
||||||
gui.setQuitOnLastWindowClosed(False)
|
gui.setQuitOnLastWindowClosed(False)
|
||||||
tray = create_system_tray()
|
tray = create_system_tray()
|
||||||
|
window = ConfigureWindow()
|
||||||
|
|
||||||
# Start Application Server
|
# Start Application Server
|
||||||
server = ServerThread(app, host, port, socket)
|
server = ServerThread(app, host, port, socket)
|
||||||
@@ -35,11 +37,12 @@ def run():
|
|||||||
gui.aboutToQuit.connect(server.terminate)
|
gui.aboutToQuit.connect(server.terminate)
|
||||||
|
|
||||||
# Start the GUI
|
# Start the GUI
|
||||||
|
window.show()
|
||||||
tray.show()
|
tray.show()
|
||||||
gui.exec()
|
gui.exec()
|
||||||
|
|
||||||
|
|
||||||
class ServerThread(QtCore.QThread):
|
class ServerThread(QThread):
|
||||||
def __init__(self, app, host=None, port=None, socket=None):
|
def __init__(self, app, host=None, port=None, socket=None):
|
||||||
super(ServerThread, self).__init__()
|
super(ServerThread, self).__init__()
|
||||||
self.app = app
|
self.app = app
|
||||||
@@ -57,6 +60,48 @@ class ServerThread(QtCore.QThread):
|
|||||||
uvicorn.run(app, host=self.host, port=self.port)
|
uvicorn.run(app, host=self.host, port=self.port)
|
||||||
|
|
||||||
|
|
||||||
|
# Subclass QMainWindow to customize your application's main window
|
||||||
|
class ConfigureWindow(QtWidgets.QMainWindow):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.setWindowTitle("Khoj - Configure")
|
||||||
|
|
||||||
|
self.layout = QtWidgets.QVBoxLayout()
|
||||||
|
|
||||||
|
enable_orgmode_search = QtWidgets.QCheckBox("Enable Search on Org-Mode Files")
|
||||||
|
enable_orgmode_search.stateChanged.connect(self.show_orgmode_search_options)
|
||||||
|
self.layout.addWidget(enable_orgmode_search)
|
||||||
|
|
||||||
|
enable_ledger_search = QtWidgets.QCheckBox("Enable Search on Beancount Files")
|
||||||
|
enable_ledger_search.stateChanged.connect(self.show_ledger_search_options)
|
||||||
|
self.layout.addWidget(enable_ledger_search)
|
||||||
|
|
||||||
|
# Set the central widget of the Window. Widget will expand
|
||||||
|
# to take up all the space in the window by default.
|
||||||
|
# Create Widget for Setting Directory with Org-Mode Files
|
||||||
|
self.config_window = QtWidgets.QWidget()
|
||||||
|
self.config_window.setLayout(self.layout)
|
||||||
|
|
||||||
|
self.setCentralWidget(self.config_window)
|
||||||
|
|
||||||
|
def show_orgmode_search_options(self, s):
|
||||||
|
if Qt.CheckState(s) == Qt.CheckState.Checked:
|
||||||
|
self.config_window.layout().addWidget(QtWidgets.QLabel("Search Org-Mode Files"))
|
||||||
|
self.config_window.layout().addWidget(QtWidgets.QLineEdit())
|
||||||
|
else:
|
||||||
|
self.config_window.layout().removeWidget(self.config_window.layout().itemAt(2).widget())
|
||||||
|
self.config_window.layout().removeWidget(self.config_window.layout().itemAt(2).widget())
|
||||||
|
|
||||||
|
def show_ledger_search_options(self, s):
|
||||||
|
if Qt.CheckState(s) == Qt.CheckState.Checked:
|
||||||
|
self.config_window.layout().addWidget(QtWidgets.QLabel("Search Ledger Files"))
|
||||||
|
self.config_window.layout().addWidget(QtWidgets.QLineEdit())
|
||||||
|
else:
|
||||||
|
self.config_window.layout().removeWidget(self.config_window.layout().itemAt(2).widget())
|
||||||
|
self.config_window.layout().removeWidget(self.config_window.layout().itemAt(2).widget())
|
||||||
|
|
||||||
|
|
||||||
def create_system_tray():
|
def create_system_tray():
|
||||||
"""Create System Tray with Menu
|
"""Create System Tray with Menu
|
||||||
Menu Actions should contain
|
Menu Actions should contain
|
||||||
@@ -90,6 +135,15 @@ def create_system_tray():
|
|||||||
|
|
||||||
return tray
|
return tray
|
||||||
|
|
||||||
|
def create_window_to_configure_khoj():
|
||||||
|
"""Create Window to Configure Khoj
|
||||||
|
Allow user to
|
||||||
|
1. Enable/Disable search on 1. org-mode, 2. markdown, 3. beancount or 4. image content types
|
||||||
|
2. Configure the server host and port
|
||||||
|
3. Save the configuration to khoj.yml and start the server
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
run()
|
run()
|
||||||
Reference in New Issue
Block a user