summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoïc Guégan <loic.guegan@mailbox.org>2024-09-18 18:32:24 +0200
committerLoïc Guégan <loic.guegan@mailbox.org>2024-09-18 18:32:24 +0200
commit76ddf4fe100d7023451eb3b3134de4a11a7ad852 (patch)
tree5df054573ab4c7efc1c45bf1c977e37f94ff40fa
parent171fbd28a33bd71a2b17b35c558c2029f4b72a0a (diff)
Minor changes
-rw-r--r--tropical/calstate.py6
-rw-r--r--tropical/env.py3
-rw-r--r--tropical/qt/caldrawer.py42
-rw-r--r--tropical/qt/eventdrawer.py36
-rw-r--r--tropical/qt/mainwindow.py14
-rwxr-xr-xtropical/tropical.py5
6 files changed, 73 insertions, 33 deletions
diff --git a/tropical/calstate.py b/tropical/calstate.py
index 2a760a6..7bf285a 100644
--- a/tropical/calstate.py
+++ b/tropical/calstate.py
@@ -1,6 +1,6 @@
import calendar
-from datetime import date, timedelta
+from datetime import date, timedelta, datetime
class CalState:
@@ -20,6 +20,10 @@ class CalState:
today = date.today()
self.goto(today.year, today.month, today.day)
+ def today(self):
+ t=datetime.today()
+ return (t.year,t.month,t.day,int(t.strftime("%w"))-1)
+
def gotoNextWeek(self):
day=date(self.year,self.month,self.day) + timedelta(weeks=1)
self.goto(day.year,day.month, day.day)
diff --git a/tropical/env.py b/tropical/env.py
index 834f7e2..900c089 100644
--- a/tropical/env.py
+++ b/tropical/env.py
@@ -1,6 +1,7 @@
from pathlib import Path
from db import CalDB
+from calstate import CalState
import configparser
from enum import Enum
from datetime import date, timedelta
@@ -40,6 +41,7 @@ class Env:
# Database
self.dbFile=self.confdir / "sqlite3.db"
self.db=CalDB(str(self.dbFile))
+ self.calState=CalState()
def initConfig(self):
self.config["global"]={"new":True}
@@ -57,4 +59,3 @@ class Env:
events.append(e)
# TODO: Account for repeat
return events
-
diff --git a/tropical/qt/caldrawer.py b/tropical/qt/caldrawer.py
index 39f72a1..b7a7502 100644
--- a/tropical/qt/caldrawer.py
+++ b/tropical/qt/caldrawer.py
@@ -21,7 +21,7 @@ class CalQGraphicsView(QGraphicsView):
class CalDrawerScene(QGraphicsScene):
- def __init__(self, parent, calState):
+ def __init__(self, parent, env):
self.parent=parent
self.gridWidth=2
self.daysLabelBG="#dddddd"
@@ -31,9 +31,11 @@ class CalDrawerScene(QGraphicsScene):
self.daysRect=list()
self.eventsRect=list()
self.mouseOver=-1
- self.calState=calState
+ self.env=env
+ self.calState=env.calState
self.daysNames=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
-
+ self.pullState()
+ self.selection=self.today
def drawForeground(self, painter, rect):
origXF, origYF, widthF, heightF = rect.getRect()
@@ -141,11 +143,12 @@ class CalDrawerScene(QGraphicsScene):
labelH=metric.boundingRect("1234567890").height()
margin=0
offsetY=int(labelH/2)+int(labelH/4)+margin
+ today=self.calState.today()
# Draw labels
for i in range(0,len(self.daysRect)):
r=self.daysRect[i]
d=days[i]
- dayLabel=str(d[2])
+ dayLabel="["+str(d[2])+"]" if d == today else str(d[2])
labelW=metric.boundingRect(dayLabel).width()
offsetX=int(r.width()/2-labelW/2)
painter.setPen(Qt.PenStyle.NoPen)
@@ -175,14 +178,16 @@ class CalDrawerScene(QGraphicsScene):
colMark=5
colMarkPadding=2
offsetY=int(labelH/2)+int(labelH/4)+margin
+ offsetX=colMark+colMarkPadding
# Draw
po=int(self.gridWidth/2) # Pen offset
- for r in self.eventsRect:
- offsetX=colMark+colMarkPadding
- painter.drawText(r.x()+po+offsetX,r.y(),r.width()-offsetX-po*2,r.height(),0,"event testddddddddddddd")
- painter.setPen(Qt.PenStyle.NoPen)
- painter.drawRect(r.x(),r.y(),colMark,labelH) # Remember r is within grid stroke
- painter.setPen(pen)
+ for i in range(0,len(self.eventsRect)):
+ r=self.eventsRect[i]
+ for e in self.events[i]:
+ painter.drawText(r.x()+po+offsetX,r.y(),r.width()-offsetX-po*2,r.height(),0,"event testddddddddddddd")
+ painter.setPen(Qt.PenStyle.NoPen)
+ painter.drawRect(r.x(),r.y(),colMark,labelH) # Remember r is within grid stroke
+ painter.setPen(pen)
def mouseMoveEvent(self, event):
"""
@@ -203,14 +208,23 @@ class CalDrawerScene(QGraphicsScene):
b=event.button()
if self.mouseOver>=0 and b==Qt.MouseButton.LeftButton:
event.accept()
+ self.selection=self.calState.getMonthDays()[self.mouseOver]
event = QEvent(DaySelectedEvent)
QCoreApplication.postEvent(self.parent, event)
+ def pullState(self):
+ self.monthDays=self.calState.getMonthDays()
+ self.today=self.calState.today()
+ self.events=list()
+ for yy, mm, dd, ww in self.monthDays:
+ self.events.append(self.env.listEventsOn(yy,mm,dd))
+
class CalDrawer():
- def __init__(self, parent, layout, calState):
- self.gs=CalDrawerScene(parent, calState)
+ def __init__(self, parent, layout, env):
+ self.env=env
+ self.gs=CalDrawerScene(parent, env)
self.gv=CalQGraphicsView(self.gs)
# Setup propertion
spLeft=QSizePolicy(QSizePolicy.Policy.Preferred,QSizePolicy.Policy.Preferred);
@@ -227,3 +241,7 @@ class CalDrawer():
# self.gv.setSizePolicy(spLeft);
layout.addWidget(self.gv)
+ def getSelectionEvents(self):
+ (yy,mm,dd,ww)=self.gs.selection
+ return self.env.listEventsOn(yy,mm,dd)
+
diff --git a/tropical/qt/eventdrawer.py b/tropical/qt/eventdrawer.py
index 331139f..c1b450f 100644
--- a/tropical/qt/eventdrawer.py
+++ b/tropical/qt/eventdrawer.py
@@ -18,20 +18,22 @@ class EvtQGraphicsView(QGraphicsView):
class EvtDrawerScene(QGraphicsScene):
- def __init__(self, calState, env):
+ def __init__(self, env):
self.gridWidth=2
super().__init__(None)
- self.calState=calState
self.env=env
self.eventsRect=list()
+ self.eventsList=list()
def drawForeground(self, painter, rect):
+ self.eventsList=self.env.listEventsOn(2024,10,1)
+ self.eventsRect.clear()
origXF, origYF, widthF, heightF = rect.getRect()
origXI, origYI, widthI, heightI = (int(origXF),int(origYF),int(widthF),int(heightF))
- self.drawEvents(painter,origXI, origYI, widthI, heightI)
+ self.drawEventsBG(painter,origXI, origYI, widthI, heightI)
+ self.drawEventsText(painter,origXI, origYI, widthI, heightI)
-
- def drawEvents(self,painter,x,y,width,height):
+ def drawEventsBG(self,painter,x,y,width,height):
# Init Pen
pen=QtGui.QPen()
pen.setWidth(self.gridWidth)
@@ -46,14 +48,28 @@ class EvtDrawerScene(QGraphicsScene):
eventHeight=80
colorWidth=20
- for e in self.env.listEventsOn(2024,10,1):
+ for e in self.eventsList:
r=QRect(x+po,y+po,width-po*2,eventHeight-po*2)
+ self.eventsRect.append(r)
painter.drawRect(r)
-
+
+ def drawEventsText(self,painter,x,y,width,height):
+ font=painter.font()
+ metric=QtGui.QFontMetrics(font);
+ labelH=metric.boundingRect("Hello event").height()
+ for i in range(0,len(self.eventsRect)):
+ e=self.eventsList[i]
+ r=self.eventsRect[i]
+ painter.drawText(r.x(),r.y()+labelH,"Hello event")
+
+ def setEvents(self, events):
+ print(events)
+ pass
+
class EvtDrawer():
- def __init__(self, layout, calState, env):
- self.gs=EvtDrawerScene(calState, env)
+ def __init__(self, layout, env):
+ self.gs=EvtDrawerScene(env)
self.gv=EvtQGraphicsView(self.gs)
# Setup propertion
spLeft=QSizePolicy(QSizePolicy.Policy.Preferred,QSizePolicy.Policy.Preferred);
@@ -70,3 +86,5 @@ class EvtDrawer():
# self.gv.setSizePolicy(spLeft);
layout.addWidget(self.gv)
+ def setEvents(self,events):
+ self.gs.setEvents(events)
diff --git a/tropical/qt/mainwindow.py b/tropical/qt/mainwindow.py
index c2662f3..f9f9ac0 100644
--- a/tropical/qt/mainwindow.py
+++ b/tropical/qt/mainwindow.py
@@ -14,24 +14,24 @@ import sys, os
class MainWindow(QMainWindow):
- def __init__(self,uipath, calState, env):
+ def __init__(self,uipath, env):
super(MainWindow,self).__init__()
uic.loadUi(uipath+"/MainWindow.ui",self)
- self.calDrawer=CalDrawer(self, self.calContainer.layout(),calState)
- self.evtDrawer=EvtDrawer(self.calContainer.layout(),calState, env)
- self.calState=calState
+ self.calDrawer=CalDrawer(self, self.calContainer.layout(), env)
+ self.evtDrawer=EvtDrawer(self.calContainer.layout(), env)
self.show()
+ print(self.calDrawer.getSelectionEvents())
def setVersion(self,version):
self.statusbar.showMessage("TropiCal v"+version,0)
def event(self, event):
if event.type() == DaySelectedEvent:
- print("Ho")
+ self.evtDrawer.setEvents(self.calDrawer.getSelectionEvents())
return QWidget.event(self,event) #super().event(event)
-def StartApplication(env,calState):
+def StartApplication(env):
path = os.path.dirname(os.path.abspath(__file__))+"/designer"
# You need one (and only one) QApplication instance per application.
# Pass in sys.argv to allow command line arguments for your app.
@@ -39,7 +39,7 @@ def StartApplication(env,calState):
app = QApplication(sys.argv)
# Create a Qt widget, which will be our window.
- window = MainWindow(path, calState, env)
+ window = MainWindow(path, env)
window.setVersion(env.__VERSION__)
window.show() # IMPORTANT!!!!! Windows are hidden by default.
diff --git a/tropical/tropical.py b/tropical/tropical.py
index 5b81203..a68c93a 100755
--- a/tropical/tropical.py
+++ b/tropical/tropical.py
@@ -14,7 +14,6 @@ from env import Env
if __name__ == '__main__':
env=Env()
- env.listEventsOn(2024,10,1)
- calState=CalState()
- QtCalanus.StartApplication(env,calState)
+# env.listEventsOn(2024,10,1)
+ QtCalanus.StartApplication(env)