From d37f451297932f918b9f7bfda16c53a08c2b2d11 Mon Sep 17 00:00:00 2001 From: ccppi Date: Wed, 7 Aug 2024 09:56:07 +0200 Subject: [PATCH] starring and viewed/new entries coloring --- lib/db.py | 4 ++-- lib/gui.py | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/db.py b/lib/db.py index 7f6a57e..4e5ec20 100644 --- a/lib/db.py +++ b/lib/db.py @@ -12,7 +12,7 @@ def initdb(file): with sqlite3.connect(file) as connection: print("db connection", connection.total_changes) cursor = connection.cursor() - cursor.execute("CREATE TABLE jobs (star TEXT,tag INT ,title TEXT, location TEXT, company TEXT,link TEXT,pubdate TEXT,hash INT,viewed INT)") + cursor.execute("CREATE TABLE jobs (star INT,tag INT ,title TEXT, location TEXT, company TEXT,link TEXT,pubdate TEXT,hash INT,viewed INT)") sys.exit() def rmdb(file,table): with sqlite3.connect(file) as connection: @@ -93,7 +93,7 @@ def writedb(jobs): log("Hash already exist") else: print("NEW_ENTRY") - cursor.execute("INSERT INTO jobs (star,tag,title,company,location,link,pubdate,hash) VALUES (?,?,?,?,?,?,?,?,?)",(job.starred,job.tag,job.title,job.company,job.location,job.link,job.date,hash1,0)) + cursor.execute("INSERT INTO jobs (star,tag,title,company,location,link,pubdate,hash,viewed) VALUES (?,?,?,?,?,?,?,?,?)",(job.starred,job.tag,job.title,job.company,job.location,job.link,job.date,hash1,0)) def viewedEntry(hash1): with sqlite3.connect("../db/sqlite3.db",timeout=10) as connection: diff --git a/lib/gui.py b/lib/gui.py index 224e052..7b312b6 100644 --- a/lib/gui.py +++ b/lib/gui.py @@ -16,14 +16,37 @@ Cantons = ["AG","ZH","BE","SG","SO"] class ColorDelegate(QStyledItemDelegate): currentRow = 0 starred = 0 + + def __init__(self,main): + super().__init__() + print("initialice overload init of ColorDelegate") + self.main = main def initStyleOption(self,option,index): #we have to rewrite this because it depends on viewport but it should depend on the model super().initStyleOption(option,index) data = index.data() column = index.column() + #flag_viewed = self.main.model.index(index.row(),8).data() + #flag_starred = self.main.model.index(index.row(),0).data() + flag_viewed = self.main.sel_model.model().index(index.row(),8).data() + try: + flag_starred = int(self.main.sel_model.model().index(index.row(),0).data()) + except ValueError: + print("probably empty string asign zero") + flag_starred = 0 + print("index:",index) print("column ",column) - print("data:", self.view.index.data()) + print("data:", flag_starred) + if flag_starred == 1: + print("Starred!!!!!") + option.backgroundBrush = QtGui.QColor("red") + elif flag_viewed != 1: + option.backgroundBrush = QtGui.QColor("green") + else: + option.backgroundBrush = QtGui.QColor("white") + + #if column == 0: # try: # value = float(data)