From 0ce1224da8c2007de9bdf7898341142897e0c64f Mon Sep 17 00:00:00 2001 From: Louie S Date: Sat, 16 Sep 2023 09:36:14 -0400 Subject: Implement reloading --- .gitignore | 2 ++ assignment-list | 0 src/db_sqlite.py | 2 ++ src/main.py | 18 +++++++++++++++--- src/preferences_dialog.py | 10 ++++++++++ 5 files changed, 29 insertions(+), 3 deletions(-) mode change 100644 => 100755 assignment-list diff --git a/.gitignore b/.gitignore index 46aa7b9..16e2109 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ __pycache__ test.db dummy* +build +dist diff --git a/assignment-list b/assignment-list old mode 100644 new mode 100755 diff --git a/src/db_sqlite.py b/src/db_sqlite.py index 88a64c2..fd06b5a 100644 --- a/src/db_sqlite.py +++ b/src/db_sqlite.py @@ -82,6 +82,7 @@ def loadFromTables(): query = QSqlQuery() # Load groups + Globals.groups = [] # Reset local groups array query.exec_("SELECT * FROM groups") while query.next(): record = query.record() @@ -94,6 +95,7 @@ def loadFromTables(): record.field("hidden").value())) # Load entries + Globals.entries = [] # Reset local entries array query.exec_("SELECT * FROM entries") while query.next(): record = query.record() diff --git a/src/main.py b/src/main.py index dfdf8a7..1b82204 100644 --- a/src/main.py +++ b/src/main.py @@ -37,12 +37,12 @@ class AssignmentList(QMainWindow): self.preferences_act = QAction("Preferences", self) self.preferences_act.setShortcut("Alt+Return") - self.preferences_act.triggered.connect(PreferencesDialog) + self.preferences_act.triggered.connect(self.preferences) file_menu.addAction(self.preferences_act) # TODO implement reload of DB that works - self.reload_act = QAction("Reload [WIP]", self) + self.reload_act = QAction("Reload", self) self.reload_act.setShortcut("F5") - #self.reload_act.triggered.connect(self.reload) + self.reload_act.triggered.connect(self.reload) file_menu.addAction(self.reload_act) file_menu.addSeparator() exit_act = QAction("Exit", self) @@ -203,6 +203,13 @@ class AssignmentList(QMainWindow): menu.exec_(QCursor.pos()) + def preferences(self): + # TODO not sure if this is working exactly how I think it does, but it works + need_reload = PreferencesDialog() + print(need_reload) + if need_reload: + self.reload() + def cleanHidden(self): """ Permanently delete removed groups and entries from db @@ -284,6 +291,11 @@ class AssignmentList(QMainWindow): return entries_vbox + def reload(self): + Config() + self.setupDB() + self.drawGroups() + def aboutDialog(self): QMessageBox.about(self, "About Assignment List", "Created by Louie S. - 2023") diff --git a/src/preferences_dialog.py b/src/preferences_dialog.py index e8292d6..7f39fb7 100644 --- a/src/preferences_dialog.py +++ b/src/preferences_dialog.py @@ -41,6 +41,10 @@ class PreferencesDialog(QDialog): apply_button = QPushButton("Apply", self) apply_button.clicked.connect(self.apply) buttons_hbox.addWidget(apply_button) + + reload_button = QPushButton("Reload", self) + reload_button.clicked.connect(self.reload) + buttons_hbox.addWidget(reload_button) main_layout.addLayout(buttons_hbox) self.setLayout(main_layout) @@ -86,6 +90,12 @@ class PreferencesDialog(QDialog): self.config.updateConfig() + def reload(self): + """ + Update, reload, and close the window + """ + self.apply() + self.done(1) if __name__ == "__main__": app = QApplication(sys.argv) -- cgit