mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 16:14:21 +00:00
Add files for each search type. Extract config on clicking start
- Only allow adding files with appropriate file extension for each search type - e.g .org for org-mode search, directory for image search - Extract file paths added to config and enablement state of each search type - This extracted state will be used to populate the khoj.yml config file
This commit is contained in:
parent
d74134e6cc
commit
daef276fd1
2 changed files with 103 additions and 14 deletions
|
@ -1,5 +1,10 @@
|
|||
# External Packages
|
||||
from PyQt6 import QtWidgets
|
||||
from PyQt6.QtCore import Qt
|
||||
|
||||
# Internal Packages
|
||||
from src.utils.config import SearchType
|
||||
from src.interface.desktop.file_browser import FileBrowser
|
||||
|
||||
|
||||
class ConfigureScreen(QtWidgets.QDialog):
|
||||
|
@ -14,6 +19,7 @@ class ConfigureScreen(QtWidgets.QDialog):
|
|||
super(ConfigureScreen, self).__init__(parent=parent)
|
||||
|
||||
# Initialize Configure Window
|
||||
self.setWindowFlags(Qt.WindowType.WindowStaysOnTopHint)
|
||||
self.setWindowTitle("Khoj - Configure")
|
||||
|
||||
# Initialize Configure Window Layout
|
||||
|
@ -21,27 +27,27 @@ class ConfigureScreen(QtWidgets.QDialog):
|
|||
self.setLayout(layout)
|
||||
|
||||
# Add Settings Panels for each Search Type to Configure Window Layout
|
||||
for search_type in ["Org-Mode", "Markdown", "Beancount", "Image"]:
|
||||
self.add_settings_panel(search_type, layout)
|
||||
self.settings_panels = []
|
||||
for search_type in SearchType:
|
||||
self.settings_panels += [self.add_settings_panel(search_type, layout)]
|
||||
self.add_action_panel(layout)
|
||||
|
||||
def add_settings_panel(self, search_type, parent_layout):
|
||||
def add_settings_panel(self, search_type: SearchType, parent_layout):
|
||||
"Add Settings Panel for specified Search Type. Toggle Editable Search Types"
|
||||
orgmode_settings = QtWidgets.QWidget()
|
||||
orgmode_layout = QtWidgets.QVBoxLayout(orgmode_settings)
|
||||
search_type_settings = QtWidgets.QWidget()
|
||||
search_type_layout = QtWidgets.QVBoxLayout(search_type_settings)
|
||||
|
||||
enable_search_type = QtWidgets.QCheckBox(f"Search {search_type} Notes")
|
||||
input_files_label = QtWidgets.QLabel(f"{search_type} Files")
|
||||
input_files = QtWidgets.QLineEdit()
|
||||
enable_search_type = QtWidgets.QCheckBox(f"Search {search_type.name}")
|
||||
input_files = FileBrowser(f'{search_type.name} Files', search_type)
|
||||
input_files.setEnabled(enable_search_type.isChecked())
|
||||
|
||||
enable_search_type.stateChanged.connect(lambda _: input_files.setEnabled(enable_search_type.isChecked()))
|
||||
|
||||
orgmode_layout.addWidget(enable_search_type)
|
||||
orgmode_layout.addWidget(input_files_label)
|
||||
orgmode_layout.addWidget(input_files)
|
||||
search_type_layout.addWidget(enable_search_type)
|
||||
search_type_layout.addWidget(input_files)
|
||||
|
||||
parent_layout.addWidget(orgmode_settings)
|
||||
parent_layout.addWidget(search_type_settings)
|
||||
return search_type_settings
|
||||
|
||||
def add_action_panel(self, parent_layout):
|
||||
"Add Action Panel"
|
||||
|
@ -54,6 +60,14 @@ class ConfigureScreen(QtWidgets.QDialog):
|
|||
action_bar_layout.addWidget(save_button)
|
||||
parent_layout.addWidget(action_bar)
|
||||
|
||||
def save_settings(self, s):
|
||||
def save_settings(self, _):
|
||||
# Save the settings to khoj.yml
|
||||
pass
|
||||
for settings_panel in self.settings_panels:
|
||||
for child in settings_panel.children():
|
||||
if isinstance(child, QtWidgets.QCheckBox):
|
||||
if child.isChecked():
|
||||
print(f"{child.text()} is enabled")
|
||||
else:
|
||||
print(f"{child.text()} is disabled")
|
||||
elif isinstance(child, FileBrowser):
|
||||
print(f"{child.search_type} files are {child.getPaths()}")
|
||||
|
|
75
src/interface/desktop/file_browser.py
Normal file
75
src/interface/desktop/file_browser.py
Normal file
|
@ -0,0 +1,75 @@
|
|||
# External Packages
|
||||
from PyQt6 import QtWidgets
|
||||
from PyQt6.QtCore import QDir
|
||||
|
||||
# Internal Packages
|
||||
from src.utils.config import SearchType
|
||||
|
||||
class FileBrowser(QtWidgets.QWidget):
|
||||
def __init__(self, title, search_type: SearchType=None):
|
||||
QtWidgets.QWidget.__init__(self)
|
||||
layout = QtWidgets.QHBoxLayout()
|
||||
self.setLayout(layout)
|
||||
self.search_type = search_type
|
||||
|
||||
self.filter_name = self.getFileFilter(search_type)
|
||||
self.dirpath = QDir.homePath()
|
||||
self.filepaths = []
|
||||
|
||||
self.label = QtWidgets.QLabel()
|
||||
self.label.setText(title)
|
||||
self.label.setFixedWidth(95)
|
||||
layout.addWidget(self.label)
|
||||
|
||||
self.lineEdit = QtWidgets.QLineEdit(self)
|
||||
self.lineEdit.setFixedWidth(180)
|
||||
|
||||
layout.addWidget(self.lineEdit)
|
||||
|
||||
self.button = QtWidgets.QPushButton('Add')
|
||||
self.button.clicked.connect(self.getFile)
|
||||
layout.addWidget(self.button)
|
||||
layout.addStretch()
|
||||
|
||||
def setMode(self, search_type):
|
||||
self.search_type = search_type
|
||||
|
||||
def getFileFilter(self, search_type):
|
||||
if search_type == SearchType.Org:
|
||||
return 'Org-Mode Files (*.org)'
|
||||
elif search_type == SearchType.Ledger:
|
||||
return 'Beancount Files (*.bean *.beancount)'
|
||||
elif search_type == SearchType.Markdown:
|
||||
return 'Markdown Files (*.md *.markdown)'
|
||||
elif search_type == SearchType.Music:
|
||||
return 'Org-Music Files (*.org)'
|
||||
elif search_type == SearchType.Image:
|
||||
return 'Images (*.jp[e]g)'
|
||||
|
||||
def setDefaultDir(self, path):
|
||||
self.dirpath = path
|
||||
|
||||
def getFile(self):
|
||||
self.filepaths = []
|
||||
if self.search_type == SearchType.Image:
|
||||
self.filepaths.append(QtWidgets.QFileDialog.getExistingDirectory(self, caption='Choose Directory',
|
||||
directory=self.dirpath))
|
||||
else:
|
||||
self.filepaths.extend(QtWidgets.QFileDialog.getOpenFileNames(self, caption='Choose Files',
|
||||
directory=self.dirpath,
|
||||
filter=self.filter_name)[0])
|
||||
if len(self.filepaths) == 0:
|
||||
return
|
||||
elif len(self.filepaths) == 1:
|
||||
self.lineEdit.setText(self.filepaths[0])
|
||||
else:
|
||||
self.lineEdit.setText(",".join(self.filepaths))
|
||||
|
||||
def setLabelWidth(self, width):
|
||||
self.label.setFixedWidth(width)
|
||||
|
||||
def setlineEditWidth(self, width):
|
||||
self.lineEdit.setFixedWidth(width)
|
||||
|
||||
def getPaths(self):
|
||||
return self.filepaths
|
Loading…
Add table
Reference in a new issue