From f997fa80ed0997eb4a8b2a0d444f82e3eeaded38 Mon Sep 17 00:00:00 2001 From: billypom on debian Date: Sun, 23 Mar 2025 22:31:58 -0400 Subject: [PATCH] if a new database is chosen, create and instantiate the tables in the sqlite file --- components/PreferencesWindow.py | 17 ++--------------- main.py | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/components/PreferencesWindow.py b/components/PreferencesWindow.py index aed4a25..4c94840 100644 --- a/components/PreferencesWindow.py +++ b/components/PreferencesWindow.py @@ -45,26 +45,12 @@ class PreferencesWindow(QDialog): # # Labels & input fields self.input_fields = {} - # for category in self.config.sections(): - # separator = QFrame() - # separator.setFrameShape(QFrame.HLine) - # self.content_layout.addWidget(separator) - # category_label = QLabel(f"{category}") - # category_label.setFont(QFont("Sans", weight=QFont.Bold)) # bold - # category_label.setStyleSheet("text-transform:uppercase;") # uppercase - # self.content_layout.addWidget(category_label) - # for key in self.config[category]: - # label = QLabel(key) - # input_field = QLineEdit(self.config[category][key]) - # self.content_layout.addWidget(label) - # self.content_layout.addWidget(input_field) - # self.input_fields[key] = input_field # Add widgets to the layout main_layout.addWidget(nav_pane) main_layout.addWidget(self.content_area) - # # Set the layout + # Set the layout self.setLayout(main_layout) def on_nav_item_clicked(self, item): @@ -97,6 +83,7 @@ class PreferencesWindow(QDialog): child.widget().deleteLater() def save_preferences(self): + print('im saving') # Upcate the config fields for key in self.input_fields: for category in self.config.sections(): diff --git a/main.py b/main.py index 15a5924..c426a0d 100644 --- a/main.py +++ b/main.py @@ -513,6 +513,7 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): preferences_window = PreferencesWindow(self.config) preferences_window.exec_() # Display the preferences window modally self.reload_config() + self.tableView.load_music_table() # Quick Actions @@ -570,18 +571,20 @@ class ApplicationWindow(QMainWindow, Ui_MainWindow): if __name__ == "__main__": - # First run initialization + # Initialization if not os.path.exists("config.ini"): # Create config file from sample run(["cp", "sample_config.ini", "config.ini"]) config = ConfigParser() config.read("config.ini") - db_name = config.get("db", "database") - db_path = db_name.split("/") - db_path.pop() - db_path_as_string = "/".join(db_path) - if not os.path.exists(db_path_as_string): - os.makedirs(db_path_as_string) + db_filepath: str = config.get("db", "database") + db_path: str = "/".join(db_filepath.split("/").pop()) + # If the db file doesn't exist + if not os.path.exists(db_filepath): + # If the db directory doesn't exist + if not os.path.exists(db_path): + # Make the directory + os.makedirs(db_path) # Create database on first run with DBA.DBAccess() as db: with open("utils/init.sql", "r") as file: @@ -599,7 +602,7 @@ if __name__ == "__main__": format="[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s", handlers=handlers, ) - # Allow for dynamic imports of my custom classes and utilities + # Allow for dynamic imports of my custom classes and utilities? project_root = os.path.abspath(os.path.dirname(__file__)) sys.path.append(project_root) # Start the app