if a new database is chosen, create and instantiate the tables in the sqlite file

This commit is contained in:
billypom on debian 2025-03-23 22:31:58 -04:00
parent f371960746
commit f997fa80ed
2 changed files with 13 additions and 23 deletions

View File

@ -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():

19
main.py
View File

@ -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