mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Open Search from Khoj Configure Screen
- Start evolving configure screen away from just being a configure screen - Update Window Title to just say Khoj - Allow Opening Web Interface to Search from Khoj configure screen - Rename "Start" Button to more accurate "Configure" - Disable Search button on first run and while configuring app
This commit is contained in:
parent
b85a626fc9
commit
c2815c5d09
1 changed files with 17 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
||||||
# Standard Packages
|
# Standard Packages
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
import webbrowser
|
||||||
|
|
||||||
|
|
||||||
# External Packages
|
# External Packages
|
||||||
|
@ -31,14 +32,16 @@ class ConfigureScreen(QtWidgets.QDialog):
|
||||||
|
|
||||||
# Load config from existing config, if exists, else load from default config
|
# Load config from existing config, if exists, else load from default config
|
||||||
if resolve_absolute_path(self.config_file).exists():
|
if resolve_absolute_path(self.config_file).exists():
|
||||||
|
self.first_run = False
|
||||||
self.current_config = yaml_utils.load_config_from_file(self.config_file)
|
self.current_config = yaml_utils.load_config_from_file(self.config_file)
|
||||||
else:
|
else:
|
||||||
|
self.first_run = True
|
||||||
self.current_config = deepcopy(constants.default_config)
|
self.current_config = deepcopy(constants.default_config)
|
||||||
self.new_config = self.current_config
|
self.new_config = self.current_config
|
||||||
|
|
||||||
# Initialize Configure Window
|
# Initialize Configure Window
|
||||||
self.setWindowFlags(Qt.WindowType.WindowStaysOnTopHint)
|
self.setWindowFlags(Qt.WindowType.WindowStaysOnTopHint)
|
||||||
self.setWindowTitle("Configure - Khoj")
|
self.setWindowTitle("Khoj")
|
||||||
self.setFixedWidth(600)
|
self.setFixedWidth(600)
|
||||||
|
|
||||||
# Initialize Configure Window Layout
|
# Initialize Configure Window Layout
|
||||||
|
@ -118,9 +121,12 @@ class ConfigureScreen(QtWidgets.QDialog):
|
||||||
action_bar = QtWidgets.QWidget()
|
action_bar = QtWidgets.QWidget()
|
||||||
action_bar_layout = QtWidgets.QHBoxLayout(action_bar)
|
action_bar_layout = QtWidgets.QHBoxLayout(action_bar)
|
||||||
|
|
||||||
self.save_button = QtWidgets.QPushButton("Start", clicked=self.save_settings)
|
self.configure_button = QtWidgets.QPushButton("Configure", clicked=self.configure_app)
|
||||||
|
self.search_button = QtWidgets.QPushButton("Search", clicked=lambda: webbrowser.open('http://localhost:8000/'))
|
||||||
|
self.search_button.setEnabled(not self.first_run)
|
||||||
|
|
||||||
action_bar_layout.addWidget(self.save_button)
|
action_bar_layout.addWidget(self.configure_button)
|
||||||
|
action_bar_layout.addWidget(self.search_button)
|
||||||
parent_layout.addWidget(action_bar)
|
parent_layout.addWidget(action_bar)
|
||||||
|
|
||||||
def get_default_config(self, search_type:SearchType=None, processor_type:ProcessorType=None):
|
def get_default_config(self, search_type:SearchType=None, processor_type:ProcessorType=None):
|
||||||
|
@ -207,12 +213,12 @@ class ConfigureScreen(QtWidgets.QDialog):
|
||||||
# Configure server with loaded config
|
# Configure server with loaded config
|
||||||
configure_server(args, required=True)
|
configure_server(args, required=True)
|
||||||
|
|
||||||
def save_settings(self):
|
def configure_app(self):
|
||||||
"Save the new settings to khoj.yml. Reload app with updated settings"
|
"Save the new settings to khoj.yml. Reload app with updated settings"
|
||||||
self.update_search_settings()
|
self.update_search_settings()
|
||||||
self.update_processor_settings()
|
self.update_processor_settings()
|
||||||
if self.save_settings_to_file():
|
if self.save_settings_to_file():
|
||||||
# Setup thread
|
# Setup thread to load updated settings in background
|
||||||
self.thread = QThread()
|
self.thread = QThread()
|
||||||
self.settings_loader = SettingsLoader(self.load_updated_settings)
|
self.settings_loader = SettingsLoader(self.load_updated_settings)
|
||||||
self.settings_loader.moveToThread(self.thread)
|
self.settings_loader.moveToThread(self.thread)
|
||||||
|
@ -227,12 +233,14 @@ class ConfigureScreen(QtWidgets.QDialog):
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
# Disable Save Button
|
# Disable Save Button
|
||||||
self.save_button.setEnabled(False)
|
self.search_button.setEnabled(False)
|
||||||
self.save_button.setText("Saving...")
|
self.configure_button.setEnabled(False)
|
||||||
|
self.configure_button.setText("Configuring...")
|
||||||
|
|
||||||
# Reset UI
|
# Reset UI
|
||||||
self.thread.finished.connect(lambda: self.save_button.setText("Start"))
|
self.thread.finished.connect(lambda: self.configure_button.setText("Configure"))
|
||||||
self.thread.finished.connect(lambda: self.save_button.setEnabled(True))
|
self.thread.finished.connect(lambda: self.configure_button.setEnabled(True))
|
||||||
|
self.thread.finished.connect(lambda: self.search_button.setEnabled(True))
|
||||||
|
|
||||||
|
|
||||||
class SettingsLoader(QObject):
|
class SettingsLoader(QObject):
|
||||||
|
|
Loading…
Reference in a new issue