diff --git a/src/interface/desktop/configure_screen.py b/src/interface/desktop/configure_screen.py index ff7b86b3..d556d947 100644 --- a/src/interface/desktop/configure_screen.py +++ b/src/interface/desktop/configure_screen.py @@ -8,6 +8,7 @@ from PyQt6.QtCore import Qt # Internal Packages from src.configure import configure_server from src.interface.desktop.file_browser import FileBrowser +from src.interface.desktop.labelled_text_field import LabelledTextField from src.utils import constants, state, yaml as yaml_utils from src.utils.cli import cli from src.utils.config import SearchType, ProcessorType @@ -86,32 +87,26 @@ class ConfigureScreen(QtWidgets.QDialog): def add_processor_panel(self, current_conversation_config: dict, processor_type: ProcessorType, parent_layout: QtWidgets.QLayout): "Add Conversation Processor Panel" + # Get current settings from config for given processor type current_openai_api_key = current_conversation_config.get('openai-api-key', None) + + # Create widgets to display settings for given processor type processor_type_settings = QtWidgets.QWidget() processor_type_layout = QtWidgets.QVBoxLayout(processor_type_settings) - enable_conversation = ProcessorCheckBox(f"Conversation", processor_type) + # Add file browser to set input files for given processor type + input_field = LabelledTextField("OpenAI API Key", processor_type, current_openai_api_key) + + # Set enabled/disabled based on checkbox state enable_conversation.setChecked(current_openai_api_key is not None) - - conversation_settings = QtWidgets.QWidget() - conversation_settings_layout = QtWidgets.QHBoxLayout(conversation_settings) - input_label = QtWidgets.QLabel() - input_label.setText("OpenAI API Key") - input_label.setFixedWidth(95) - - input_field = ProcessorLineEdit(current_openai_api_key, processor_type) - input_field.setFixedWidth(245) - input_field.setEnabled(enable_conversation.isChecked()) enable_conversation.stateChanged.connect(lambda _: input_field.setEnabled(enable_conversation.isChecked())) - conversation_settings_layout.addWidget(input_label) - conversation_settings_layout.addWidget(input_field) - + # Add setting widgets for given processor type to panel processor_type_layout.addWidget(enable_conversation) - processor_type_layout.addWidget(conversation_settings) - + processor_type_layout.addWidget(input_field) parent_layout.addWidget(processor_type_settings) + return processor_type_settings def add_action_panel(self, parent_layout: QtWidgets.QLayout): @@ -165,9 +160,7 @@ class ConfigureScreen(QtWidgets.QDialog): "Update config with conversation settings from UI" for settings_panel in self.processor_settings_panels: for child in settings_panel.children(): - if isinstance(child, QtWidgets.QWidget) and child.findChild(ProcessorLineEdit): - child = child.findChild(ProcessorLineEdit) - elif not isinstance(child, ProcessorCheckBox): + if not isinstance(child, (ProcessorCheckBox, LabelledTextField)): continue if isinstance(child, ProcessorCheckBox): # Processor Type Disabled @@ -178,9 +171,9 @@ class ConfigureScreen(QtWidgets.QDialog): current_processor_config = self.current_config['processor'].get(child.processor_type, {}) default_processor_config = self.get_default_config(processor_type = child.processor_type) self.new_config['processor'][child.processor_type.value] = merge_dicts(current_processor_config, default_processor_config) - elif isinstance(child, ProcessorLineEdit) and child.processor_type in self.new_config['processor']: + elif isinstance(child, LabelledTextField) and child.processor_type in self.new_config['processor']: if child.processor_type == ProcessorType.Conversation: - self.new_config['processor'][child.processor_type.value]['openai-api-key'] = child.text() if child.text() != '' else None + self.new_config['processor'][child.processor_type.value]['openai-api-key'] = child.input_field.text() if child.input_field.text() != '' else None def save_settings_to_file(self) -> bool: # Validate config before writing to file @@ -230,12 +223,3 @@ class ProcessorCheckBox(QtWidgets.QCheckBox): def __init__(self, text, processor_type: ProcessorType, parent=None): self.processor_type = processor_type super(ProcessorCheckBox, self).__init__(text, parent=parent) - - -class ProcessorLineEdit(QtWidgets.QLineEdit): - def __init__(self, text, processor_type: ProcessorType, parent=None): - self.processor_type = processor_type - if text is None: - super(ProcessorLineEdit, self).__init__(parent=parent) - else: - super(ProcessorLineEdit, self).__init__(text, parent=parent) diff --git a/src/interface/desktop/labelled_text_field.py b/src/interface/desktop/labelled_text_field.py new file mode 100644 index 00000000..9bc3b7c6 --- /dev/null +++ b/src/interface/desktop/labelled_text_field.py @@ -0,0 +1,25 @@ +# External Packages +from PyQt6 import QtWidgets + +# Internal Packages +from src.utils.config import ProcessorType + + +class LabelledTextField(QtWidgets.QWidget): + def __init__(self, title, processor_type: ProcessorType=None, default_value: str=None): + QtWidgets.QWidget.__init__(self) + layout = QtWidgets.QHBoxLayout() + self.setLayout(layout) + self.processor_type = processor_type + + self.label = QtWidgets.QLabel() + self.label.setText(title) + self.label.setFixedWidth(95) + layout.addWidget(self.label) + + self.input_field = QtWidgets.QLineEdit(self) + self.input_field.setFixedWidth(250) + self.input_field.setText(default_value) + + layout.addWidget(self.input_field) + layout.addStretch()