Minor changes
This commit is contained in:
parent
171fbd28a3
commit
76ddf4fe10
6 changed files with 73 additions and 33 deletions
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
import calendar
|
import calendar
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta, datetime
|
||||||
|
|
||||||
class CalState:
|
class CalState:
|
||||||
|
|
||||||
|
@ -20,6 +20,10 @@ class CalState:
|
||||||
today = date.today()
|
today = date.today()
|
||||||
self.goto(today.year, today.month, today.day)
|
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):
|
def gotoNextWeek(self):
|
||||||
day=date(self.year,self.month,self.day) + timedelta(weeks=1)
|
day=date(self.year,self.month,self.day) + timedelta(weeks=1)
|
||||||
self.goto(day.year,day.month, day.day)
|
self.goto(day.year,day.month, day.day)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from db import CalDB
|
from db import CalDB
|
||||||
|
from calstate import CalState
|
||||||
import configparser
|
import configparser
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
|
@ -40,6 +41,7 @@ class Env:
|
||||||
# Database
|
# Database
|
||||||
self.dbFile=self.confdir / "sqlite3.db"
|
self.dbFile=self.confdir / "sqlite3.db"
|
||||||
self.db=CalDB(str(self.dbFile))
|
self.db=CalDB(str(self.dbFile))
|
||||||
|
self.calState=CalState()
|
||||||
|
|
||||||
def initConfig(self):
|
def initConfig(self):
|
||||||
self.config["global"]={"new":True}
|
self.config["global"]={"new":True}
|
||||||
|
@ -57,4 +59,3 @@ class Env:
|
||||||
events.append(e)
|
events.append(e)
|
||||||
# TODO: Account for repeat
|
# TODO: Account for repeat
|
||||||
return events
|
return events
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ class CalQGraphicsView(QGraphicsView):
|
||||||
|
|
||||||
|
|
||||||
class CalDrawerScene(QGraphicsScene):
|
class CalDrawerScene(QGraphicsScene):
|
||||||
def __init__(self, parent, calState):
|
def __init__(self, parent, env):
|
||||||
self.parent=parent
|
self.parent=parent
|
||||||
self.gridWidth=2
|
self.gridWidth=2
|
||||||
self.daysLabelBG="#dddddd"
|
self.daysLabelBG="#dddddd"
|
||||||
|
@ -31,9 +31,11 @@ class CalDrawerScene(QGraphicsScene):
|
||||||
self.daysRect=list()
|
self.daysRect=list()
|
||||||
self.eventsRect=list()
|
self.eventsRect=list()
|
||||||
self.mouseOver=-1
|
self.mouseOver=-1
|
||||||
self.calState=calState
|
self.env=env
|
||||||
|
self.calState=env.calState
|
||||||
self.daysNames=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
|
self.daysNames=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
|
||||||
|
self.pullState()
|
||||||
|
self.selection=self.today
|
||||||
|
|
||||||
def drawForeground(self, painter, rect):
|
def drawForeground(self, painter, rect):
|
||||||
origXF, origYF, widthF, heightF = rect.getRect()
|
origXF, origYF, widthF, heightF = rect.getRect()
|
||||||
|
@ -141,11 +143,12 @@ class CalDrawerScene(QGraphicsScene):
|
||||||
labelH=metric.boundingRect("1234567890").height()
|
labelH=metric.boundingRect("1234567890").height()
|
||||||
margin=0
|
margin=0
|
||||||
offsetY=int(labelH/2)+int(labelH/4)+margin
|
offsetY=int(labelH/2)+int(labelH/4)+margin
|
||||||
|
today=self.calState.today()
|
||||||
# Draw labels
|
# Draw labels
|
||||||
for i in range(0,len(self.daysRect)):
|
for i in range(0,len(self.daysRect)):
|
||||||
r=self.daysRect[i]
|
r=self.daysRect[i]
|
||||||
d=days[i]
|
d=days[i]
|
||||||
dayLabel=str(d[2])
|
dayLabel="["+str(d[2])+"]" if d == today else str(d[2])
|
||||||
labelW=metric.boundingRect(dayLabel).width()
|
labelW=metric.boundingRect(dayLabel).width()
|
||||||
offsetX=int(r.width()/2-labelW/2)
|
offsetX=int(r.width()/2-labelW/2)
|
||||||
painter.setPen(Qt.PenStyle.NoPen)
|
painter.setPen(Qt.PenStyle.NoPen)
|
||||||
|
@ -175,14 +178,16 @@ class CalDrawerScene(QGraphicsScene):
|
||||||
colMark=5
|
colMark=5
|
||||||
colMarkPadding=2
|
colMarkPadding=2
|
||||||
offsetY=int(labelH/2)+int(labelH/4)+margin
|
offsetY=int(labelH/2)+int(labelH/4)+margin
|
||||||
|
offsetX=colMark+colMarkPadding
|
||||||
# Draw
|
# Draw
|
||||||
po=int(self.gridWidth/2) # Pen offset
|
po=int(self.gridWidth/2) # Pen offset
|
||||||
for r in self.eventsRect:
|
for i in range(0,len(self.eventsRect)):
|
||||||
offsetX=colMark+colMarkPadding
|
r=self.eventsRect[i]
|
||||||
painter.drawText(r.x()+po+offsetX,r.y(),r.width()-offsetX-po*2,r.height(),0,"event testddddddddddddd")
|
for e in self.events[i]:
|
||||||
painter.setPen(Qt.PenStyle.NoPen)
|
painter.drawText(r.x()+po+offsetX,r.y(),r.width()-offsetX-po*2,r.height(),0,"event testddddddddddddd")
|
||||||
painter.drawRect(r.x(),r.y(),colMark,labelH) # Remember r is within grid stroke
|
painter.setPen(Qt.PenStyle.NoPen)
|
||||||
painter.setPen(pen)
|
painter.drawRect(r.x(),r.y(),colMark,labelH) # Remember r is within grid stroke
|
||||||
|
painter.setPen(pen)
|
||||||
|
|
||||||
def mouseMoveEvent(self, event):
|
def mouseMoveEvent(self, event):
|
||||||
"""
|
"""
|
||||||
|
@ -203,14 +208,23 @@ class CalDrawerScene(QGraphicsScene):
|
||||||
b=event.button()
|
b=event.button()
|
||||||
if self.mouseOver>=0 and b==Qt.MouseButton.LeftButton:
|
if self.mouseOver>=0 and b==Qt.MouseButton.LeftButton:
|
||||||
event.accept()
|
event.accept()
|
||||||
|
self.selection=self.calState.getMonthDays()[self.mouseOver]
|
||||||
event = QEvent(DaySelectedEvent)
|
event = QEvent(DaySelectedEvent)
|
||||||
QCoreApplication.postEvent(self.parent, event)
|
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():
|
class CalDrawer():
|
||||||
|
|
||||||
def __init__(self, parent, layout, calState):
|
def __init__(self, parent, layout, env):
|
||||||
self.gs=CalDrawerScene(parent, calState)
|
self.env=env
|
||||||
|
self.gs=CalDrawerScene(parent, env)
|
||||||
self.gv=CalQGraphicsView(self.gs)
|
self.gv=CalQGraphicsView(self.gs)
|
||||||
# Setup propertion
|
# Setup propertion
|
||||||
spLeft=QSizePolicy(QSizePolicy.Policy.Preferred,QSizePolicy.Policy.Preferred);
|
spLeft=QSizePolicy(QSizePolicy.Policy.Preferred,QSizePolicy.Policy.Preferred);
|
||||||
|
@ -227,3 +241,7 @@ class CalDrawer():
|
||||||
# self.gv.setSizePolicy(spLeft);
|
# self.gv.setSizePolicy(spLeft);
|
||||||
layout.addWidget(self.gv)
|
layout.addWidget(self.gv)
|
||||||
|
|
||||||
|
def getSelectionEvents(self):
|
||||||
|
(yy,mm,dd,ww)=self.gs.selection
|
||||||
|
return self.env.listEventsOn(yy,mm,dd)
|
||||||
|
|
||||||
|
|
|
@ -18,20 +18,22 @@ class EvtQGraphicsView(QGraphicsView):
|
||||||
|
|
||||||
|
|
||||||
class EvtDrawerScene(QGraphicsScene):
|
class EvtDrawerScene(QGraphicsScene):
|
||||||
def __init__(self, calState, env):
|
def __init__(self, env):
|
||||||
self.gridWidth=2
|
self.gridWidth=2
|
||||||
super().__init__(None)
|
super().__init__(None)
|
||||||
self.calState=calState
|
|
||||||
self.env=env
|
self.env=env
|
||||||
self.eventsRect=list()
|
self.eventsRect=list()
|
||||||
|
self.eventsList=list()
|
||||||
|
|
||||||
def drawForeground(self, painter, rect):
|
def drawForeground(self, painter, rect):
|
||||||
|
self.eventsList=self.env.listEventsOn(2024,10,1)
|
||||||
|
self.eventsRect.clear()
|
||||||
origXF, origYF, widthF, heightF = rect.getRect()
|
origXF, origYF, widthF, heightF = rect.getRect()
|
||||||
origXI, origYI, widthI, heightI = (int(origXF),int(origYF),int(widthF),int(heightF))
|
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 drawEventsBG(self,painter,x,y,width,height):
|
||||||
def drawEvents(self,painter,x,y,width,height):
|
|
||||||
# Init Pen
|
# Init Pen
|
||||||
pen=QtGui.QPen()
|
pen=QtGui.QPen()
|
||||||
pen.setWidth(self.gridWidth)
|
pen.setWidth(self.gridWidth)
|
||||||
|
@ -46,14 +48,28 @@ class EvtDrawerScene(QGraphicsScene):
|
||||||
|
|
||||||
eventHeight=80
|
eventHeight=80
|
||||||
colorWidth=20
|
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)
|
r=QRect(x+po,y+po,width-po*2,eventHeight-po*2)
|
||||||
|
self.eventsRect.append(r)
|
||||||
painter.drawRect(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():
|
class EvtDrawer():
|
||||||
|
|
||||||
def __init__(self, layout, calState, env):
|
def __init__(self, layout, env):
|
||||||
self.gs=EvtDrawerScene(calState, env)
|
self.gs=EvtDrawerScene(env)
|
||||||
self.gv=EvtQGraphicsView(self.gs)
|
self.gv=EvtQGraphicsView(self.gs)
|
||||||
# Setup propertion
|
# Setup propertion
|
||||||
spLeft=QSizePolicy(QSizePolicy.Policy.Preferred,QSizePolicy.Policy.Preferred);
|
spLeft=QSizePolicy(QSizePolicy.Policy.Preferred,QSizePolicy.Policy.Preferred);
|
||||||
|
@ -70,3 +86,5 @@ class EvtDrawer():
|
||||||
# self.gv.setSizePolicy(spLeft);
|
# self.gv.setSizePolicy(spLeft);
|
||||||
layout.addWidget(self.gv)
|
layout.addWidget(self.gv)
|
||||||
|
|
||||||
|
def setEvents(self,events):
|
||||||
|
self.gs.setEvents(events)
|
||||||
|
|
|
@ -14,24 +14,24 @@ import sys, os
|
||||||
|
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
|
|
||||||
def __init__(self,uipath, calState, env):
|
def __init__(self,uipath, env):
|
||||||
super(MainWindow,self).__init__()
|
super(MainWindow,self).__init__()
|
||||||
uic.loadUi(uipath+"/MainWindow.ui",self)
|
uic.loadUi(uipath+"/MainWindow.ui",self)
|
||||||
self.calDrawer=CalDrawer(self, self.calContainer.layout(),calState)
|
self.calDrawer=CalDrawer(self, self.calContainer.layout(), env)
|
||||||
self.evtDrawer=EvtDrawer(self.calContainer.layout(),calState, env)
|
self.evtDrawer=EvtDrawer(self.calContainer.layout(), env)
|
||||||
self.calState=calState
|
|
||||||
self.show()
|
self.show()
|
||||||
|
print(self.calDrawer.getSelectionEvents())
|
||||||
|
|
||||||
def setVersion(self,version):
|
def setVersion(self,version):
|
||||||
self.statusbar.showMessage("TropiCal v"+version,0)
|
self.statusbar.showMessage("TropiCal v"+version,0)
|
||||||
|
|
||||||
def event(self, event):
|
def event(self, event):
|
||||||
if event.type() == DaySelectedEvent:
|
if event.type() == DaySelectedEvent:
|
||||||
print("Ho")
|
self.evtDrawer.setEvents(self.calDrawer.getSelectionEvents())
|
||||||
return QWidget.event(self,event) #super().event(event)
|
return QWidget.event(self,event) #super().event(event)
|
||||||
|
|
||||||
|
|
||||||
def StartApplication(env,calState):
|
def StartApplication(env):
|
||||||
path = os.path.dirname(os.path.abspath(__file__))+"/designer"
|
path = os.path.dirname(os.path.abspath(__file__))+"/designer"
|
||||||
# You need one (and only one) QApplication instance per application.
|
# You need one (and only one) QApplication instance per application.
|
||||||
# Pass in sys.argv to allow command line arguments for your app.
|
# Pass in sys.argv to allow command line arguments for your app.
|
||||||
|
@ -39,7 +39,7 @@ def StartApplication(env,calState):
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
# Create a Qt widget, which will be our window.
|
# Create a Qt widget, which will be our window.
|
||||||
window = MainWindow(path, calState, env)
|
window = MainWindow(path, env)
|
||||||
window.setVersion(env.__VERSION__)
|
window.setVersion(env.__VERSION__)
|
||||||
window.show() # IMPORTANT!!!!! Windows are hidden by default.
|
window.show() # IMPORTANT!!!!! Windows are hidden by default.
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ from env import Env
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
env=Env()
|
env=Env()
|
||||||
env.listEventsOn(2024,10,1)
|
# env.listEventsOn(2024,10,1)
|
||||||
calState=CalState()
|
QtCalanus.StartApplication(env)
|
||||||
QtCalanus.StartApplication(env,calState)
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue