...
This commit is contained in:
@@ -2,13 +2,16 @@
|
||||
import scribus
|
||||
import datetime
|
||||
import calendar
|
||||
import re
|
||||
|
||||
class Constants(object):
|
||||
DefaultFont = ""
|
||||
|
||||
class ScribusCalendar(object):
|
||||
def __init__(self, objects, year):
|
||||
self.objects = objects
|
||||
self.year = year
|
||||
|
||||
|
||||
def createStyles(self):
|
||||
existing_styles = scribus.getAllStyles()
|
||||
for obj in self.objects:
|
||||
@@ -39,14 +42,15 @@ class ScribusCalendar(object):
|
||||
class CalendarObject(object):
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
self.noStub = False
|
||||
self.position = (0,0)
|
||||
self.size = (100,100)
|
||||
|
||||
self.paragraphStyle = "DefaultCalenderParagraphStyle"
|
||||
self.charStyle = "DefaultCalenderCharStyle"
|
||||
|
||||
self.layer = "CalendarLayer"
|
||||
self.defaultFontSize = 8
|
||||
self.configParser = None
|
||||
|
||||
self.date = datetime.date.today()
|
||||
|
||||
@@ -63,23 +67,47 @@ class CalendarObject(object):
|
||||
existingLayers.append(self.layer)
|
||||
|
||||
def createStyles(self, existingStyles):
|
||||
if self.charStyle not in existingStyles:
|
||||
scribus.createCharStyle(self.charStyle, "DejaVu Sans", 8)
|
||||
existingStyles.append(self.charStyle)
|
||||
|
||||
if self.paragraphStyle not in existingStyles:
|
||||
scribus.createParagraphStyle(self.paragraphStyle ,1,0,0,0,0,0,0,0,0,0,0,self.charStyle)
|
||||
existingStyles.append(self.paragraphStyle)
|
||||
charStyles = self.charStyle
|
||||
paragraphStyles = self.paragraphStyle
|
||||
defaultFontSizes = self.defaultFontSize
|
||||
|
||||
if not type(self.charStyle) is list:
|
||||
charStyles = [ self.charStyle ]
|
||||
|
||||
if not type(self.paragraphStyle) is list:
|
||||
paragraphStyles = [ self.paragraphStyle ]
|
||||
|
||||
if not type(self.defaultFontSize) is list:
|
||||
defaultFontSizes = [ self.defaultFontSize ]
|
||||
|
||||
|
||||
|
||||
for i in range(0,len(charStyles)):
|
||||
|
||||
if charStyles[i] not in existingStyles:
|
||||
scribus.createCharStyle(charStyles[i], Constants.DefaultFont, defaultFontSizes[i])
|
||||
existingStyles.append(charStyles[i])
|
||||
|
||||
if paragraphStyles[i] not in existingStyles:
|
||||
scribus.createParagraphStyle(paragraphStyles[i] ,1,0,0,0,0,0,0,0,0,0,0,charStyles[i])
|
||||
existingStyles.append(paragraphStyles[i])
|
||||
|
||||
def plotStub(self):
|
||||
if self.noStub == True:
|
||||
return False
|
||||
|
||||
if not scribus.objectExists(self.name):
|
||||
scribus.createText(self.position[0],self.position[1], self.size[0],self.size[1], self.name)
|
||||
scribus.setStyle(self.paragraphStyle, self.name)
|
||||
scribus.insertText(self.name, 0, self.name)
|
||||
scribus.sentToLayer(self.layer, self.name)
|
||||
return True
|
||||
return False
|
||||
|
||||
def readFromStub(self):
|
||||
if self.noStub == True:
|
||||
return
|
||||
|
||||
p = scribus.getPosition(self.name)
|
||||
s = scribus.getSize(self.name)
|
||||
|
||||
@@ -88,10 +116,10 @@ class CalendarObject(object):
|
||||
def plotObject(self):
|
||||
pass
|
||||
|
||||
|
||||
def configure(self, configParser):
|
||||
className = self.__class__.__name__
|
||||
settings = dict()
|
||||
self.configParser = configParser
|
||||
|
||||
try:
|
||||
settings = configParser.modules[className]
|
||||
@@ -108,6 +136,8 @@ class WeekDayNameObject(CalendarObject):
|
||||
def __init__(self, name):
|
||||
CalendarObject.__init__(self,name)
|
||||
self.weekday = datetime.date.today().weekday()
|
||||
self.paragraphStyle = "WeekDayNameParagraphStyle"
|
||||
self.charStyle = "WeekDayNameCharStyle"
|
||||
|
||||
def getName(self):
|
||||
return calendar.day_name[self.date.weekday()]
|
||||
@@ -119,6 +149,8 @@ class WeekNameObject(CalendarObject):
|
||||
def __init__(self, name):
|
||||
CalendarObject.__init__(self,name)
|
||||
self.weeknumber = 1
|
||||
self.paragraphStyle = "WeekNameParagraphStyle"
|
||||
self.charStyle = "WeekNameCharStyle"
|
||||
|
||||
def setDate(self, date):
|
||||
CalendarObject.setDate(self, date)
|
||||
@@ -131,6 +163,48 @@ class WeekNameObject(CalendarObject):
|
||||
def getNameAbbrev(self):
|
||||
return self.getName()
|
||||
|
||||
class MonthNameObject(CalendarObject):
|
||||
def __init__(self, name):
|
||||
CalendarObject.__init__(self, name)
|
||||
self.paragraphStyle = "MonthNameParagraphStyle"
|
||||
self.charStyle = "MonthNameCharStyle"
|
||||
|
||||
def getMonthName(self):
|
||||
return calendar.month_name[self.date.month]
|
||||
|
||||
|
||||
class UserDefinedObjects(CalendarObject):
|
||||
def __init__(self):
|
||||
CalendarObject.__init__(self, "UserDefinedObjects")
|
||||
self.layer = "UserDefinedObjects"
|
||||
self.noStub = True
|
||||
|
||||
def plotObject(self):
|
||||
layers = scribus.getLayers()
|
||||
currentPage = scribus.currentPage()
|
||||
|
||||
scribus.gotoPage(1)
|
||||
objects = scribus.getAllObjects()
|
||||
|
||||
for obj in objects:
|
||||
m = re.match(r'^(.+)__(.+)$', obj)
|
||||
if m is None:
|
||||
continue
|
||||
|
||||
layerName = m.group(1)
|
||||
|
||||
if not layerName in layers:
|
||||
scribus.createLayer(layerName)
|
||||
|
||||
scribus.gotoPage(1)
|
||||
scribus.copyObject(obj)
|
||||
scribus.gotoPage(currentPage)
|
||||
scribus.setActiveLayer(layerName)
|
||||
scribus.pasteObject(obj)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,9 @@ import datetime
|
||||
from .base_objects import ScribusCalendar
|
||||
|
||||
class MonthlyCalendar(ScribusCalendar):
|
||||
def __init__(self, objects, year):
|
||||
def __init__(self, objects, year, numMonths):
|
||||
ScribusCalendar.__init__(self, objects, year)
|
||||
self.numMonths = numMonths
|
||||
|
||||
|
||||
def plotObjects(self):
|
||||
@@ -14,7 +15,7 @@ class MonthlyCalendar(ScribusCalendar):
|
||||
scribus.deletePage(i)
|
||||
|
||||
|
||||
for i in range(1,2):
|
||||
for i in range(1,self.numMonths + 1):
|
||||
scribus.newPage(-1)
|
||||
for obj in self.objects:
|
||||
obj.setDate(datetime.date(self.year, i, 1))
|
||||
|
||||
@@ -5,11 +5,12 @@ class ConfigParser(object):
|
||||
def __init__(self, filename):
|
||||
with open(filename, "r") as f:
|
||||
self.jsonContent = json.load(f)
|
||||
|
||||
self.events = dict()
|
||||
self.settings = dict()
|
||||
|
||||
self.__parseSettings()
|
||||
self.__parseEvents()
|
||||
self.addEvents(self.jsonContent["events"])
|
||||
self.__parseModuleSettings()
|
||||
|
||||
def __parseModuleSettings(self):
|
||||
@@ -33,13 +34,16 @@ class ConfigParser(object):
|
||||
return datetime.date(year=self.settings["year"], month=int(d[0]), day=int(d[1]))
|
||||
|
||||
|
||||
def __parseEvents(self):
|
||||
self.events = self.jsonContent["events"]
|
||||
for key, val in self.events.items():
|
||||
def addEvents(self, jsonContent):
|
||||
for key, val in jsonContent.items():
|
||||
dates = val["dates"]
|
||||
for ev in dates:
|
||||
self.__parseDateRange(ev)
|
||||
|
||||
self.events.update(jsonContent)
|
||||
|
||||
|
||||
|
||||
def printEvents(self):
|
||||
for key, val in self.events.items():
|
||||
dates = val["dates"]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from .base_objects import MonthlyCalendarObject, WeekDayNameObject, DailyCalendarObject, WeekNameObject
|
||||
from .base_objects import MonthlyCalendarObject, WeekDayNameObject, DailyCalendarObject, WeekNameObject, MonthNameObject
|
||||
from .calendar_helpers import MonthCalendarMatrix
|
||||
import calendar
|
||||
import math
|
||||
@@ -13,41 +13,114 @@ def class_from_name(className):
|
||||
class SimpleWeekDayNameObject(WeekDayNameObject):
|
||||
def __init__(self):
|
||||
WeekDayNameObject.__init__(self, "SimpleWeekDayNameObject")
|
||||
self.noStub = True
|
||||
|
||||
def plotObject(self):
|
||||
textBox = scribus.createText(self.position[0],self.position[1], self.size[0],self.size[1])
|
||||
scribus.setStyle(self.paragraphStyle, textBox )
|
||||
scribus.insertText(self.getNameAbbrev(), 0, textBox )
|
||||
scribus.sentToLayer(self.layer, textBox)
|
||||
|
||||
class SimpleMonthNameObject(MonthNameObject):
|
||||
def __init__(self):
|
||||
MonthNameObject.__init__(self, "SimpleMonthNameObject")
|
||||
|
||||
def plotObject(self):
|
||||
textBox = scribus.createText(self.position[0],self.position[1], self.size[0],self.size[1])
|
||||
scribus.setStyle(self.paragraphStyle, textBox )
|
||||
scribus.insertText(self.getMonthName(), 0, textBox )
|
||||
scribus.sentToLayer(self.layer, textBox)
|
||||
|
||||
class SimpleWeekNameObject(WeekNameObject):
|
||||
def __init__(self):
|
||||
WeekNameObject.__init__(self, "SimpleWeekNameObject")
|
||||
self.noStub = True
|
||||
|
||||
def plotObject(self):
|
||||
textBox = scribus.createText(self.position[0],self.position[1], self.size[0],self.size[1])
|
||||
scribus.setStyle(self.paragraphStyle, textBox )
|
||||
scribus.insertText(self.getNameAbbrev(), 0, textBox )
|
||||
scribus.sentToLayer(self.layer, textBox)
|
||||
|
||||
|
||||
class FormattedDayObject(DailyCalendarObject):
|
||||
def __init__(self):
|
||||
DailyCalendarObject.__init__(self,"FormattedDayObject")
|
||||
self.noStub = True
|
||||
|
||||
self.paragraphStyle = "S"
|
||||
self.paragraphStyle = [
|
||||
'DayLetterParagraphStyle',
|
||||
'DayLetterHighlightParagraphStyle',
|
||||
'EventParagraphStyle']
|
||||
|
||||
self.charStyle = [
|
||||
'DayLetterCharStyle',
|
||||
'DayLetterHighlightCharStyle',
|
||||
'EventCharStyle']
|
||||
|
||||
self.defaultFontSize = [ 8, 8, 4]
|
||||
|
||||
def plotObject(self):
|
||||
if self.isActive:
|
||||
textBox = scribus.createText(self.position[0],self.position[1], self.size[0],self.size[1])
|
||||
heightEventBox = self.size[1] * self.heightEventbox
|
||||
heightLetterBox = self.size[1] * ( 1 - self.heightEventbox )
|
||||
|
||||
widthHolidaybox = self.size[0] * self.widthHolidaybox
|
||||
widthLetterbox = self.size[0] * ( 1 - self.widthHolidaybox)
|
||||
|
||||
dayLetterBox = [ self.position[0]
|
||||
,self.position[1]
|
||||
,widthLetterbox
|
||||
,heightLetterBox ]
|
||||
|
||||
eventNameBox = [ self.position[0]
|
||||
,self.position[1] + heightLetterBox
|
||||
,self.size[0]
|
||||
,heightEventBox ]
|
||||
|
||||
holidayBox = [ self.position[0] + widthLetterbox
|
||||
,self.position[1]
|
||||
,widthHolidaybox
|
||||
,heightLetterBox ]
|
||||
|
||||
bankHolidayEvent = self.configParser.getEvent(self.date, "bankHolidays")
|
||||
schoolHolidayEvent = self.configParser.getEvent(self.date, "schoolHolidays")
|
||||
|
||||
dayLetterStyle = self.paragraphStyle[0]
|
||||
if bankHolidayEvent is not None:
|
||||
if ( bankHolidayEvent[1]["hint"] == "" ):
|
||||
dayLetterStyle = self.paragraphStyle[1]
|
||||
|
||||
eventNameTextBox = scribus.createText(*eventNameBox)
|
||||
scribus.insertText(bankHolidayEvent[1]["name"], 0, eventNameTextBox )
|
||||
scribus.setStyle(self.paragraphStyle[2], eventNameTextBox)
|
||||
scribus.sentToLayer(self.layer, eventNameTextBox)
|
||||
|
||||
if schoolHolidayEvent is not None:
|
||||
holidayTextbox = scribus.createText(*holidayBox)
|
||||
scribus.insertText("F", 0, holidayTextbox )
|
||||
scribus.setStyle(self.paragraphStyle[2], holidayTextbox)
|
||||
scribus.sentToLayer(self.layer, holidayTextbox)
|
||||
|
||||
textBox = scribus.createText(*dayLetterBox)
|
||||
scribus.setStyle(dayLetterStyle, textBox )
|
||||
scribus.insertText(self.getName(), 0, textBox )
|
||||
scribus.sentToLayer(self.layer, textBox)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class DayGridObject(DailyCalendarObject):
|
||||
def __init__(self):
|
||||
DailyCalendarObject.__init__(self,"DayGridObject")
|
||||
self.noStub = True
|
||||
|
||||
|
||||
def plotObject(self):
|
||||
if self.isActive:
|
||||
textBox = scribus.createText(self.position[0],self.position[1], self.size[0],self.size[1])
|
||||
scribus.setStyle(self.paragraphStyle, textBox )
|
||||
scribus.insertText(self.getName(), 0, textBox )
|
||||
scribus.sentToLayer(self.layer, textBox)
|
||||
|
||||
@@ -66,6 +139,7 @@ class MonthlyGrid(MonthlyCalendarObject):
|
||||
self.calendarWeekClass = None
|
||||
self.weekDayClass = None
|
||||
self.dayClass = None
|
||||
self.monthNameClass = None
|
||||
|
||||
|
||||
self.createdObjects = []
|
||||
@@ -83,6 +157,15 @@ class MonthlyGrid(MonthlyCalendarObject):
|
||||
self.scaleFactor[0] = self.size[0] / unitsX
|
||||
self.scaleFactor[1] = self.size[1] / unitsY
|
||||
|
||||
def createStyles(self, existing_styles):
|
||||
self.initSubObjects()
|
||||
|
||||
MonthlyCalendarObject.createStyles(self, existing_styles)
|
||||
|
||||
self.weekDayClass().createStyles(existing_styles)
|
||||
self.dayClass().createStyles(existing_styles)
|
||||
self.calendarWeekClass().createStyles(existing_styles)
|
||||
|
||||
def setDate(self, date):
|
||||
MonthlyCalendarObject.setDate(self, date)
|
||||
if self.oneLineOnly:
|
||||
@@ -101,11 +184,11 @@ class MonthlyGrid(MonthlyCalendarObject):
|
||||
|
||||
def plotObject(self):
|
||||
self.createObjects()
|
||||
|
||||
for obj in self.createdObjects:
|
||||
obj.plotObject()
|
||||
|
||||
def createObjects(self):
|
||||
|
||||
def initSubObjects(self):
|
||||
if type(self.weekDayClass) == unicode :
|
||||
self.weekDayClass = class_from_name(self.weekDayClass)
|
||||
|
||||
@@ -115,6 +198,10 @@ class MonthlyGrid(MonthlyCalendarObject):
|
||||
if type(self.calendarWeekClass) == unicode:
|
||||
self.calendarWeekClass = class_from_name(self.calendarWeekClass)
|
||||
|
||||
|
||||
def createObjects(self):
|
||||
self.initSubObjects()
|
||||
|
||||
self.createdObjects = []
|
||||
w = self.position[0]
|
||||
h = self.position[1]
|
||||
@@ -147,6 +234,7 @@ class MonthlyGrid(MonthlyCalendarObject):
|
||||
self.createdObjects.append(calendarWeekObj)
|
||||
|
||||
dailyObj = self.dayClass()
|
||||
dailyObj.configure(self.configParser)
|
||||
dailyObj.setDate(i[j])
|
||||
dailyObj.setActive(i[j].month == self.date.month)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user