Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Calender.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 """ This Script creates a Calendar Sheet for the Current Month """
00005 
00006 import sys
00007 
00008 try:
00009     from scribus import *
00010 except ImportError:
00011     print "This script only runs from within Scribus."
00012     sys.exit(1)
00013 
00014 import calendar
00015 import time
00016 
00017 def main():
00018     Month = time.localtime()[1]
00019     Year = time.localtime()[0]
00020     Objects = []
00021     MonthList = ["January","February","March","April","May","June","July","August","September","October","November","December"]
00022     DaysList = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]
00023     Xcoor = 10
00024     Ycoor = 30
00025     DayC = 0
00026     Calend = calendar.monthcalendar(Year, Month)
00027     ob = createText(10, 10, 245, 20)
00028     Title = MonthList[Month-1] + " " + str(Year)
00029     setText(Title, ob)
00030     Objects.append(ob)
00031     for lx in range(45, 245, 35):
00032         ob = createLine(lx, 30, lx, 20*len(Calend)+50)
00033         Objects.append(ob)
00034     for ly in range(50, 20*len(Calend)+50, 20):
00035         ob = createLine(10, ly, 255, ly)
00036         Objects.append(ob)
00037     ob = createRect(10, 30, 245, 20*len(Calend)+20)
00038     setFillColor("None", ob)
00039     Objects.append(ob)
00040     for day in range(7):
00041         ob = createText(Xcoor, Ycoor, 35, 20)
00042         setTextAlignment(ALIGN_CENTERED, ob)
00043         setFontSize(12, ob)
00044         if day == 6:
00045             setTextColor("Red", ob)
00046         setText(DaysList[day], ob)
00047         Objects.append(ob)
00048         Xcoor = Xcoor + 35
00049     Ycoor = Ycoor + 20
00050     for lines in Calend:
00051         Xcoor = 10
00052         DayC = 0
00053         for rows in lines:
00054             if rows != 0:
00055                 ob = createText(Xcoor, Ycoor, 35, 20)
00056                 setTextAlignment(ALIGN_CENTERED, ob)
00057                 if DayC == 6:
00058                     setTextColor("Red", ob)
00059                 setText(str(rows), ob)
00060                 Objects.append(ob)
00061             Xcoor = Xcoor + 35
00062             DayC = DayC + 1
00063         Ycoor = Ycoor + 20
00064     groupObjects(Objects)
00065 
00066 if __name__ == '__main__':
00067     if haveDoc():
00068         try:
00069             setRedraw(False)
00070             main()
00071         finally:
00072             setRedraw(True)
00073             redrawAll()
00074     else:
00075         messageBox("Calendar Script", "Please run this script with a document open.", ICON_INFORMATION);