summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2023-09-16 09:36:14 -0400
committerLouie S <louie@example.com>2023-09-16 09:36:14 -0400
commit6e52afa26d8c50d07988376e43a641c70370b9c5 (patch)
tree3b9cc7f01aa8a64fa4dea6ee4547fc50423f6725
parent76a1b6384301a9a8e37b1176f83f55b2827b2d16 (diff)
Create preferences dialog to control config file
-rw-r--r--.gitignore1
-rwxr-xr-xassignment-list.py11
-rw-r--r--config.py24
-rw-r--r--db_sqlite.py3
-rw-r--r--entry.py4
5 files changed, 31 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 597be97..46aa7b9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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)
diff --git a/config.py b/config.py
index 557de0e..da40ed4 100644
--- a/config.py
+++ b/config.py
@@ -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)
diff --git a/entry.py b/entry.py
index 67d290a..0a0b3b1 100644
--- a/entry.py
+++ b/entry.py
@@ -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"
))