173 lines
5.7 KiB
Python
173 lines
5.7 KiB
Python
from .base_objects import MonthlyCalendarObject, WeekDayNameObject, DailyCalendarObject, WeekNameObject
|
|
from .calendar_helpers import MonthCalendarMatrix
|
|
import calendar
|
|
import math
|
|
import copy
|
|
import datetime
|
|
import scribus
|
|
import json
|
|
|
|
def class_from_name(className):
|
|
return globals()[className]
|
|
|
|
class SimpleWeekDayNameObject(WeekDayNameObject):
|
|
def __init__(self):
|
|
WeekDayNameObject.__init__(self, "SimpleWeekDayNameObject")
|
|
|
|
def plotObject(self):
|
|
textBox = scribus.createText(self.position[0],self.position[1], self.size[0],self.size[1])
|
|
scribus.insertText(self.getNameAbbrev(), 0, textBox )
|
|
scribus.sentToLayer(self.layer, textBox)
|
|
|
|
class SimpleWeekNameObject(WeekNameObject):
|
|
def __init__(self):
|
|
WeekNameObject.__init__(self, "SimpleWeekNameObject")
|
|
|
|
def plotObject(self):
|
|
textBox = scribus.createText(self.position[0],self.position[1], self.size[0],self.size[1])
|
|
scribus.insertText(self.getNameAbbrev(), 0, textBox )
|
|
scribus.sentToLayer(self.layer, textBox)
|
|
|
|
class FormattedDayObject(DailyCalendarObject):
|
|
def __init__(self):
|
|
DailyCalendarObject.__init__(self,"FormattedDayObject")
|
|
|
|
self.paragraphStyle = "S"
|
|
|
|
def plotObject(self):
|
|
if self.isActive:
|
|
textBox = scribus.createText(self.position[0],self.position[1], self.size[0],self.size[1])
|
|
scribus.insertText(self.getName(), 0, textBox )
|
|
scribus.sentToLayer(self.layer, textBox)
|
|
|
|
|
|
class DayGridObject(DailyCalendarObject):
|
|
def __init__(self):
|
|
DailyCalendarObject.__init__(self,"DayGridObject")
|
|
|
|
def plotObject(self):
|
|
if self.isActive:
|
|
textBox = scribus.createText(self.position[0],self.position[1], self.size[0],self.size[1])
|
|
scribus.insertText(self.getName(), 0, textBox )
|
|
scribus.sentToLayer(self.layer, textBox)
|
|
|
|
|
|
class MonthlyGrid(MonthlyCalendarObject):
|
|
def __init__(self):
|
|
MonthlyCalendarObject.__init__(self, "MonthlyGrid")
|
|
self.numberOfWeeksPerLine = 1
|
|
self.oneLineOnly = False
|
|
self.heightColWeekNumber = 0.3
|
|
self.widthRowWeekName = 0.3
|
|
self.sizeCellDay = (1.0, 1.0)
|
|
|
|
self.scaleFactor = [1,1]
|
|
|
|
self.calendarWeekClass = None
|
|
self.weekDayClass = None
|
|
self.dayClass = None
|
|
|
|
|
|
self.createdObjects = []
|
|
self.setDate(datetime.date.today())
|
|
|
|
def setDimension(self, pos, size):
|
|
MonthlyCalendarObject.setDimension(self,pos,size)
|
|
self.computeScaleFactor()
|
|
|
|
def computeScaleFactor(self):
|
|
self.numCols = len(self.calendarMatrix)
|
|
unitsX = 1 * self.widthRowWeekName + len(self.calendarMatrix[0]) * self.sizeCellDay[0]
|
|
unitsY = ( 1 * self.heightColWeekNumber) + ( self.numCols * self.sizeCellDay[1] )
|
|
|
|
self.scaleFactor[0] = self.size[0] / unitsX
|
|
self.scaleFactor[1] = self.size[1] / unitsY
|
|
|
|
def setDate(self, date):
|
|
MonthlyCalendarObject.setDate(self, date)
|
|
if self.oneLineOnly:
|
|
self.calendarMatrix = MonthCalendarMatrix(self.date.year, self.date.month, 1, False).get()
|
|
|
|
t = [[]]
|
|
for i in self.calendarMatrix:
|
|
t[0] += i
|
|
self.calendarMatrix = t
|
|
self.numberOfWeeksPerLine = 1
|
|
|
|
else:
|
|
self.calendarMatrix = MonthCalendarMatrix(self.date.year, self.date.month, self.numberOfWeeksPerLine, True).get()
|
|
|
|
self.computeScaleFactor()
|
|
|
|
def plotObject(self):
|
|
self.createObjects()
|
|
|
|
for obj in self.createdObjects:
|
|
obj.plotObject()
|
|
|
|
def createObjects(self):
|
|
if type(self.weekDayClass) == unicode :
|
|
self.weekDayClass = class_from_name(self.weekDayClass)
|
|
|
|
if type(self.dayClass) == unicode:
|
|
self.dayClass = class_from_name(self.dayClass)
|
|
|
|
if type(self.calendarWeekClass) == unicode:
|
|
self.calendarWeekClass = class_from_name(self.calendarWeekClass)
|
|
|
|
self.createdObjects = []
|
|
w = self.position[0]
|
|
h = self.position[1]
|
|
|
|
for i in range(0, len(self.calendarMatrix[0])):
|
|
if self.calendarMatrix[0][i].weekday() == 0:
|
|
x = self.widthRowWeekName * self.scaleFactor[0]
|
|
w += x
|
|
|
|
weekDayObj = self.weekDayClass()
|
|
weekDayObj.setDate(self.calendarMatrix[0][i])
|
|
self.createdObjects.append(weekDayObj)
|
|
x = self.sizeCellDay[0] * self.scaleFactor[0]
|
|
y = self.heightColWeekNumber * self.scaleFactor[1]
|
|
weekDayObj.setDimension((w,h), (x,y))
|
|
w += x
|
|
|
|
w = self.position[0]
|
|
h += self.heightColWeekNumber * self.scaleFactor[1]
|
|
|
|
for i in self.calendarMatrix:
|
|
for j in range(0,len(i)):
|
|
if i[j].weekday() == 0:
|
|
calendarWeekObj = self.calendarWeekClass()
|
|
calendarWeekObj.setDate(i[j])
|
|
x = self.widthRowWeekName * self.scaleFactor[0]
|
|
y = self.sizeCellDay[1] * self.scaleFactor[1]
|
|
calendarWeekObj.setDimension((w,h), (x, y) )
|
|
w += x
|
|
self.createdObjects.append(calendarWeekObj)
|
|
|
|
dailyObj = self.dayClass()
|
|
dailyObj.setDate(i[j])
|
|
dailyObj.setActive(i[j].month == self.date.month)
|
|
|
|
x = self.sizeCellDay[0] * self.scaleFactor[0]
|
|
y = self.sizeCellDay[1] * self.scaleFactor[1]
|
|
dailyObj.setDimension((w, h), (x, y))
|
|
w += x
|
|
self.createdObjects.append(dailyObj)
|
|
|
|
|
|
h += self.sizeCellDay[1] * self.scaleFactor[1]
|
|
w = self.position[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|