#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
# Written as an example for pypslib by Stefan Schroeder
# (c) GPL
import pslib as ps
import time, calendar
BOX_HEIGHT = 120
BOX_WIDTH = 80
BOX_TITLE_HEIGHT = 20
XSIZE=596
YSIZE=842
LEFT_BORDER = (XSIZE - 7*BOX_WIDTH)/2
TOP_BORDER = 100
TEXT_FONT = "Helvetica"
TITLE_FONT = "Helvetica"
month = int(time.strftime("%m", time.gmtime()))
year = int(time.strftime("%Y", time.gmtime()))
month_s = time.strftime("%B", time.gmtime())
DAY_NAME = []
for i in range(4,4+7): # re-offset to get monday first.
DAY_NAME.append(time.strftime("%A",time. gmtime(i*3600*24)))
def begin_calendar_box(p, number, font):
lly, llx = YSIZE - 2*BOX_HEIGHT - (number)/7*BOX_HEIGHT, LEFT_BORDER + (number%7)*BOX_WIDTH
ps.PS_save(p)
ps.PS_translate(p, llx, lly)
ps.PS_setcolor(p, "stroke", "gray", 0.5, 0.0, 0.0, 0.0)
ps.PS_rect(p, 0, BOX_HEIGHT-BOX_TITLE_HEIGHT,
BOX_WIDTH, BOX_TITLE_HEIGHT)
ps.PS_fill(p)
ps.PS_setcolor(p, "stroke", "gray", 1.0, 0.0, 0.0, 0.0)
ps.PS_setfont(p, font, 11.5)
title = DAY_NAME[number%7]
ps.PS_show_xy(p, title, 10, BOX_HEIGHT-BOX_TITLE_HEIGHT+5)
ps.PS_setcolor(p, "stroke", "gray", 0.1, 0.0, 0.0, 0.0)
ps.PS_setfont(p, font, 20)
title = str(number-weekday_of_first[0]+1)
ps.PS_show_xy(p, title, 10, 10)
ps.PS_setlinewidth(p, 1.0)
ps.PS_setcolor(p, "stroke", "gray", 0.0, 0.0, 0.0, 0.0)
ps.PS_rect(p, 0, 0, BOX_WIDTH, BOX_HEIGHT)
ps.PS_stroke(p)
ps.PS_moveto(p, 0, BOX_HEIGHT-BOX_TITLE_HEIGHT)
ps.PS_lineto(p, BOX_WIDTH, BOX_HEIGHT-BOX_TITLE_HEIGHT)
ps.PS_stroke(p)
def end_calendar_box(p):
ps.PS_restore(p)
#
# main
#
p1=ps.PS_new()
ps.PS_set_info(p1, "Creator", "Python");
ps.PS_set_info(p1, "Author", "Uwe Steinmann & Stefan Schroeder");
ps.PS_set_info(p1, "Title", "Calendar");
ps.PS_open_file(p1, 'calendar.ps')
print "Creating calendar.ps ... ",
ps.PS_begin_page(p1, XSIZE, YSIZE)
# Assemble Title
psfont = ps.PS_findfont(p1, TITLE_FONT, "", 0)
ps.PS_setfont(p1, psfont, 35)
text = month_s + " " + str(year)
textwidth = ps.PS_stringwidth(p1, text, psfont, 35.0)
ps.PS_show_xy2(p1, text, len(text), XSIZE/2-textwidth/2, YSIZE-0.5*BOX_HEIGHT)
# Assemble Table
psfont = ps.PS_findfont(p1, TEXT_FONT, "", 0)
weekday_of_first = calendar.monthrange(year, month)
for i in range(weekday_of_first[0],weekday_of_first[0]+weekday_of_first[1]):
begin_calendar_box(p1, i, psfont)
end_calendar_box(p1)
ps.PS_end_page(p1)
ps.PS_close(p1)
ps.PS_delete(p1)
print "Finished."