6741d19ec5be2e76369d84bd705bde8767972e00auriumA calendar generator plugin for Inkscape, but also can be used as a standalone
6741d19ec5be2e76369d84bd705bde8767972e00auriumcommand line application.
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpennerCopyright (C) 2008 Aurelio A. Heckert <aurium(a)gmail.com>
e866cf6004410b86765759ca47d88ae2052306bfJazzyNicoWeek number option added by Olav Vitters and Nicolas Dufour (2012)
e866cf6004410b86765759ca47d88ae2052306bfJazzyNicoMore on ISO week number calculation on:
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico(The first week of a year is the week that contains the first Thursday
e866cf6004410b86765759ca47d88ae2052306bfJazzyNicoof the year.)
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpennerThis program is free software; you can redistribute it and/or modify
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpennerit under the terms of the GNU General Public License as published by
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpennerthe Free Software Foundation; either version 2 of the License, or
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpenner(at your option) any later version.
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpennerThis program is distributed in the hope that it will be useful,
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpennerbut WITHOUT ANY WARRANTY; without even the implied warranty of
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpennerMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpennerGNU General Public License for more details.
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpennerYou should have received a copy of the GNU General Public License
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpenneralong with this program; if not, write to the Free Software
107e00c8104649437b9520d0ba298dba659e7cd7JazzyNicoFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
6741d19ec5be2e76369d84bd705bde8767972e00auriumfrom datetime import *
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpenner help="Month to be generated. If 0, then the entry year will be generated.")
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpenner help="Year to be generated. If 0, then the current year will be generated.")
6741d19ec5be2e76369d84bd705bde8767972e00aurium self.OptionParser.add_option("--fill-empty-day-boxes",
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpenner help="Fill empty day boxes with next month days.")
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.OptionParser.add_option("--show-week-number",
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpenner help='Define the weekend days. ("sat+sun" or "sat" or "sun")')
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpenner help='Color for the next month day, in enpty day boxes.')
bad6d1a999834aab8f41efe219e093f4a057545aapenner dest="month_names", default='January February March ' + \
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico 'April May June '+ \
bad6d1a999834aab8f41efe219e093f4a057545aapenner 'July August September ' + \
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico 'October November December',
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpenner dest="day_names", default='Sun Mon Tue Wed Thu Fri Sat',
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico help='The week number column name for localization.')
d04fdb8e3c74ab565590728d96c52b5f3bbedf98aurium #inkex.errormsg( self.options.input_encode )
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico # Convert string names lists in real lists
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico m = re.match('\s*(.*[^\s])\s*', self.options.month_names)
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.options.month_names = re.split('\s+', m.group(1))
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico m = re.match('\s*(.*[^\s])\s*', self.options.day_names)
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.options.day_names = re.split('\s+', m.group(1))
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico # Validate names lists
6741d19ec5be2e76369d84bd705bde8767972e00aurium '" is invalid. Using default.')
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.options.month_names = ['January', 'February', 'March',
6741d19ec5be2e76369d84bd705bde8767972e00aurium '" is invalid. Using default.')
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.options.day_names = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu',
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico # Convert year 0 to current year
6741d19ec5be2e76369d84bd705bde8767972e00aurium if self.options.year == 0: self.options.year = datetime.today().year
52bc35e1956391dd3b08ecbedd022da25e746c9cAurélio A. Heckert (a) # Year 1 starts it's week at monday, obligatorily
52bc35e1956391dd3b08ecbedd022da25e746c9cAurélio A. Heckert (a) if self.options.year == 1: self.options.start_day = 'mon'
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico # Set the calendar start day
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico # Convert string numbers with unit to user space float numbers
3626239912f1d2e7effe313bd1fab54e10364f09Johan B. C. Engelen self.options.month_width = self.unittouu( self.options.month_width )
3626239912f1d2e7effe313bd1fab54e10364f09Johan B. C. Engelen self.options.month_margin = self.unittouu( self.options.month_margin )
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico # initial values
03f0cd31db1136c686a9b7e279766cc171dfae5aaurium #month_margin month_width months_per_line auto_organize
3626239912f1d2e7effe313bd1fab54e10364f09Johan B. C. Engelen self.doc_w = self.unittouu(self.document.getroot().get('width'))
3626239912f1d2e7effe313bd1fab54e10364f09Johan B. C. Engelen self.doc_h = self.unittouu(self.document.getroot().get('height'))
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.months_per_line = self.options.months_per_line
6741d19ec5be2e76369d84bd705bde8767972e00aurium #self.month_w = self.doc_w / self.months_per_line
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.month_w = (self.doc_w * 0.8) / self.months_per_line
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.day_w = self.month_w / (7 + self.cols_before)
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico (self.months_per_line - 1))) / 2) #- self.month_margin
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.year_margin = (self.doc_w - self.month_w) / 2
6741d19ec5be2e76369d84bd705bde8767972e00aurium self.style_weekend['fill'] = self.options.color_weekend
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.style_month['font-size'] = str(self.day_w / 1.5)
6741d19ec5be2e76369d84bd705bde8767972e00aurium self.style_day_name['fill'] = self.options.color_day_name
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.style_day_name['font-size'] = str(self.day_w / 3 )
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.style_year['font-size'] = str(self.day_w * 2)
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.style_weeknr['fill'] = self.options.color_weeknr
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.style_weeknr['font-size'] = str(self.day_w / 3)
6741d19ec5be2e76369d84bd705bde8767972e00aurium # weekend values: "sat+sun" or "sat" or "sun"
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico if self.options.weekend == 'sat+sun' and pos == 0: return True
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico if self.options.weekend == 'sat+sun' and pos == 6: return True
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico if self.options.weekend == 'sat' and pos == 6: return True
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico if self.options.weekend == 'sun' and pos == 0: return True
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico if self.options.weekend == 'sat+sun' and pos == 5: return True
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico if self.options.weekend == 'sat+sun' and pos == 6: return True
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico if self.options.weekend == 'sat' and pos == 5: return True
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico if self.options.weekend == 'sun' and pos == 6: return True
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpenner txt_atts = {'style': simplestyle.formatStyle(self.style_month),
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico inkex.etree.SubElement(g, 'text', txt_atts).text = unicode(
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico inkex.errormsg(_('You must select a correct system encoding.'))
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpenner txt_atts = {'style': simplestyle.formatStyle(self.style_day_name),
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico inkex.etree.SubElement(gw, 'text', txt_atts).text = unicode(
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico inkex.errormsg(_('You must select a correct system encoding.'))
6741d19ec5be2e76369d84bd705bde8767972e00aurium g = inkex.etree.SubElement(self.year_g, 'g', txt_atts)
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.in_line_month(calendar.monthcalendar(self.options.year - 1, 12))
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.in_line_month(calendar.monthcalendar(self.options.year, m - 1))
6741d19ec5be2e76369d84bd705bde8767972e00aurium if m == 12:
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.in_line_month(calendar.monthcalendar(self.options.year + 1, 1))
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico self.in_line_month(calendar.monthcalendar(self.options.year, m + 1))
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico # add a line after the last week
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico # add a line before the first week (Feb 2009)
6741d19ec5be2e76369d84bd705bde8767972e00aurium # How mutch before month days will be showed:
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico ((self.options.start_day == 'mon' and week[0] != 0) or \
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico (self.options.start_day == 'sun' and week[1] != 0))) or \
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico ((self.options.start_day == 'mon' and week[3] > 0) or \
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico (self.options.start_day == 'sun' and week[4] > 0))):
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico # Remove leap week (starting previous year) and empty weeks
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico if self.weeknr != 0 and not (week[0] == 0 and week[6] == 0):
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico txt_atts = {'style': simplestyle.formatStyle(style),
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico inkex.etree.SubElement(gdays, 'text', txt_atts).text = str(self.weeknr)
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico if self.is_weekend(week_x - self.cols_before): style = self.style_weekend
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico txt_atts = {'style': simplestyle.formatStyle(style),
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico pass # draw nothing
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico inkex.etree.SubElement(gdays, 'text', txt_atts).text = str(before_month[-bmd])
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico inkex.etree.SubElement(gdays, 'text', txt_atts).text = str(next_month[bmd])
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico inkex.etree.SubElement(gdays, 'text', txt_atts).text = str(day)
e866cf6004410b86765759ca47d88ae2052306bfJazzyNico txt_atts = {'id': 'year_'+str(self.options.year) }
6741d19ec5be2e76369d84bd705bde8767972e00aurium self.year_g = inkex.etree.SubElement(parent, 'g', txt_atts)
e0cdf8e0ac7cc0bfd89e9166fea83c1b01e8c246alvinpenner txt_atts = {'style': simplestyle.formatStyle(self.style_year),