From d74134e6cc818c1137b6f0b7eea6a267775e0811 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 9 Aug 2022 23:48:32 +0300 Subject: [PATCH] Reuse Single Method to Create Setting Panels for each Search Type --- src/interface/desktop/configure_screen.py | 47 ++++++++--------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/src/interface/desktop/configure_screen.py b/src/interface/desktop/configure_screen.py index 2b80eb29..7de2a113 100644 --- a/src/interface/desktop/configure_screen.py +++ b/src/interface/desktop/configure_screen.py @@ -1,6 +1,5 @@ # External Packages from PyQt6 import QtWidgets -from PyQt6.QtCore import Qt class ConfigureScreen(QtWidgets.QDialog): @@ -21,53 +20,37 @@ class ConfigureScreen(QtWidgets.QDialog): layout = QtWidgets.QVBoxLayout() self.setLayout(layout) - # Add Panels to Configure Window Layout - self.show_orgmode_settings(layout) - self.show_ledger_settings(layout) - self.show_action_bar(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.add_action_panel(layout) - def show_orgmode_settings(self, parent_layout): - "Add Org Mode Settings to the Configure Window" + def add_settings_panel(self, search_type, parent_layout): + "Add Settings Panel for specified Search Type. Toggle Editable Search Types" orgmode_settings = QtWidgets.QWidget() orgmode_layout = QtWidgets.QVBoxLayout(orgmode_settings) - enable_orgmode_search = QtWidgets.QCheckBox("Search Org-Mode Notes") - input_files_label = QtWidgets.QLabel("Org-Mode Files") + enable_search_type = QtWidgets.QCheckBox(f"Search {search_type} Notes") + input_files_label = QtWidgets.QLabel(f"{search_type} Files") input_files = QtWidgets.QLineEdit() - input_files.setEnabled(enable_orgmode_search.isChecked()) + input_files.setEnabled(enable_search_type.isChecked()) - enable_orgmode_search.stateChanged.connect(lambda _: input_files.setEnabled(enable_orgmode_search.isChecked())) + enable_search_type.stateChanged.connect(lambda _: input_files.setEnabled(enable_search_type.isChecked())) - orgmode_layout.addWidget(enable_orgmode_search) + orgmode_layout.addWidget(enable_search_type) orgmode_layout.addWidget(input_files_label) orgmode_layout.addWidget(input_files) parent_layout.addWidget(orgmode_settings) - def show_ledger_settings(self, parent_layout): - "Add Ledger Settings to the Configure Window" - ledger_settings = QtWidgets.QWidget() - ledger_layout = QtWidgets.QVBoxLayout(ledger_settings) - - enable_ledger_search = QtWidgets.QCheckBox("Search Beancount Transactions") - input_files_label = QtWidgets.QLabel("Beancount Files") - input_files = QtWidgets.QLineEdit() - input_files.setEnabled(enable_ledger_search.isChecked()) - - enable_ledger_search.stateChanged.connect(lambda _: input_files.setEnabled(enable_ledger_search.isChecked())) - - ledger_layout.addWidget(enable_ledger_search) - ledger_layout.addWidget(input_files_label) - ledger_layout.addWidget(input_files) - - parent_layout.addWidget(ledger_settings) - - def show_action_bar(self, parent_layout): - "Add Action Bar to the Configure Window" + def add_action_panel(self, parent_layout): + "Add Action Panel" # Button to Save Settings action_bar = QtWidgets.QWidget() action_bar_layout = QtWidgets.QHBoxLayout(action_bar) + save_button = QtWidgets.QPushButton("Start", clicked=self.save_settings) + action_bar_layout.addWidget(save_button) parent_layout.addWidget(action_bar)