diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | assignment-list.py | 11 | ||||
-rw-r--r-- | config.py | 24 | ||||
-rw-r--r-- | db_sqlite.py | 3 | ||||
-rw-r--r-- | entry.py | 4 |
5 files changed, 31 insertions, 12 deletions
@@ -1,2 +1,3 @@ __pycache__ test.db +dummy* diff --git a/assignment-list.py b/assignment-list.py index daac800..71e0ae7 100755 --- a/assignment-list.py +++ b/assignment-list.py @@ -5,6 +5,7 @@ from PyQt5.QtWidgets import QAction, QApplication, QGridLayout, QHBoxLayout, QLa from PyQt5.QtGui import QCursor, QFont from PyQt5.QtCore import QDate, Qt from config import Config +from preferences_dialog import PreferencesDialog from add_group_form import addGroupForm from edit_group_form import editGroupForm from add_entry_form import addEntryForm @@ -34,6 +35,16 @@ class AssignmentList(QMainWindow): edit_menu = menu_bar.addMenu("Edit") help_menu = menu_bar.addMenu("Help") + self.preferences_act = QAction("Preferences", self) + self.preferences_act.setShortcut("Alt+Return") + self.preferences_act.triggered.connect(PreferencesDialog) + file_menu.addAction(self.preferences_act) + # TODO implement reload of DB that works + self.reload_act = QAction("Reload", self) + self.reload_act.setShortcut("F5") + #self.reload_act.triggered.connect(self.reload) + file_menu.addAction(self.reload_act) + file_menu.addSeparator() exit_act = QAction("Exit", self) exit_act.setShortcut("Ctrl+Q") exit_act.triggered.connect(self.close) @@ -23,20 +23,20 @@ class Config(): self.loadConfig() def loadConfig(self): - config = configparser.ConfigParser() + self.config = configparser.ConfigParser() try: - config.read(self.config_path) + self.config.read(self.config_path) except: print("Could not parse config file '{}'".format(self.config_path)) - if "paths" in config: - if config["paths"]["db_path"]: - Globals.db_path = config["paths"]["db_path"] + if "paths" in self.config: + if self.config["paths"]["db_path"]: + Globals.db_path = self.config["paths"]["db_path"] def createConfig(self): - config = configparser.ConfigParser() - config["paths"] = { + self.config = configparser.ConfigParser() + self.config["paths"] = { "db_path": os.path.join( os.path.expanduser("~"), ".local", @@ -46,6 +46,12 @@ class Config(): ) } + self.updateConfig() + + def updateConfig(self): + """ + Update the configuration file with values from self.config + """ # Attempt to create directory if necessary if not os.path.exists(os.path.dirname(self.config_path)): try: @@ -54,10 +60,10 @@ class Config(): print("Error: Could not create config directory '{}'".format(os.path.dirname(self.config_path))) sys.exit(1) - # Attempt to create file + # Attempt to write to file try: with open(self.config_path, 'w') as configfile: - config.write(configfile) + self.config.write(configfile) except: print("Error: Could not open config file '{}'".format(self.config_path)) sys.exit(1) diff --git a/db_sqlite.py b/db_sqlite.py index 189ac57..af7f185 100644 --- a/db_sqlite.py +++ b/db_sqlite.py @@ -11,7 +11,7 @@ def initDB(): """ Check for existing database. If it doesn't exist, build it """ - if not os.path.exists(Globals.db_path): + if not os.path.exists(Globals.db_path) or not os.stat(Globals.db_path).st_size: createTables() loadFromTables() @@ -20,6 +20,7 @@ def createTables(): """ Create database at a specified Globals.db_path """ + print(Globals.db_path) database = QSqlDatabase.addDatabase("QSQLITE") # SQlite version 3 database.setDatabaseName(Globals.db_path) @@ -42,7 +42,7 @@ class Entry: body.setText("{0}/{1}/{2}: ".format(self.due.month(), self.due.day(), self.due.year())) if self.link: body.setOpenExternalLinks(True) - body.setText(body.text() + "<a href=\"{0}\" style=\"color: default; text-decoration: none;\">".format(self.link)) + body.setText(body.text() + "<a href=\"{0}\" style=\"color: {1}; text-decoration: none;\">".format(self.link, self.color if self.color else "default")) body.setText(body.text() + self.desc) if self.link: body.setText(body.text() + "</a>") @@ -67,7 +67,7 @@ class Entry: color: {0}; background-color: {1}; }}""".format( - self.color if self.color else "black", + self.color if self.color else "default", self.highlight if self.highlight else "none" )) |