summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: dac38e3)
raw | patch | inline | side by side (parent: dac38e3)
author | alvinpenner <alvinpenner@users.sourceforge.net> | |
Mon, 26 Jan 2009 00:19:35 +0000 (00:19 +0000) | ||
committer | alvinpenner <alvinpenner@users.sourceforge.net> | |
Mon, 26 Jan 2009 00:19:35 +0000 (00:19 +0000) |
share/extensions/svgcalendar.py | patch | blob | history |
index 7410d3079afdfb151d73f0a162236ecd07a3b1fe..0dca58fc5a409fd4ac4e978f547e9ef144b1cc86 100755 (executable)
#!/usr/bin/env python
-\r
-'''\r
+
+'''
calendar.py
A calendar generator plugin for Inkscape, but also can be used as a standalone
command line application.
-\r
-Copyright (C) 2008 Aurelio A. Heckert <aurium(a)gmail.com>\r
-\r
-This program is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-This program is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with this program; if not, write to the Free Software\r
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
-'''\r
+
+Copyright (C) 2008 Aurelio A. Heckert <aurium(a)gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+'''
__version__ = "0.1"
import inkex, simplestyle, re, calendar
from datetime import *
-\r
-class SVGCalendar (inkex.Effect):\r
- def __init__(self):\r
- inkex.Effect.__init__(self)\r
- self.OptionParser.add_option("--tab",\r
- action="store", type="string",\r
- dest="tab")\r
- self.OptionParser.add_option("--month",\r
- action="store", type="int",\r
- dest="month", default=0,\r
- help="Month to be generated. If 0, then the entry year will be generated.")\r
+class SVGCalendar (inkex.Effect):
+
+ def __init__(self):
+ inkex.Effect.__init__(self)
+ self.OptionParser.add_option("--tab",
+ action="store", type="string",
+ dest="tab")
+ self.OptionParser.add_option("--month",
+ action="store", type="int",
+ dest="month", default=0,
+ help="Month to be generated. If 0, then the entry year will be generated.")
self.OptionParser.add_option("--year",
- action="store", type="int",\r
- dest="year", default=0,\r
- help="Year to be generated. If 0, then the current year will be generated.")\r
+ action="store", type="int",
+ dest="year", default=0,
+ help="Year to be generated. If 0, then the current year will be generated.")
self.OptionParser.add_option("--fill-empty-day-boxes",
- action="store", type="inkbool",\r
- dest="fill_edb", default=True,\r
- help="Fill empty day boxes with next month days.")\r
+ action="store", type="inkbool",
+ dest="fill_edb", default=True,
+ help="Fill empty day boxes with next month days.")
self.OptionParser.add_option("--start-day",
- action="store", type="string",\r
- dest="start_day", default="sun",\r
- help='Week start day. ("sun" or "mon")')\r
+ action="store", type="string",
+ dest="start_day", default="sun",
+ help='Week start day. ("sun" or "mon")')
self.OptionParser.add_option("--weekend",
- action="store", type="string",\r
- dest="weekend", default="sat+sun",\r
- help='Define the weekend days. ("sat+sun" or "sat" or "sun")')\r
+ action="store", type="string",
+ dest="weekend", default="sat+sun",
+ help='Define the weekend days. ("sat+sun" or "sat" or "sun")')
self.OptionParser.add_option("--color-year",
- action="store", type="string",\r
- dest="color_year", default="#888",\r
- help='Color for the year header.')\r
+ action="store", type="string",
+ dest="color_year", default="#888",
+ help='Color for the year header.')
self.OptionParser.add_option("--color-month",
- action="store", type="string",\r
- dest="color_month", default="#666",\r
- help='Color for the month name header.')\r
+ action="store", type="string",
+ dest="color_month", default="#666",
+ help='Color for the month name header.')
self.OptionParser.add_option("--color-day-name",
- action="store", type="string",\r
- dest="color_day_name", default="#999",\r
- help='Color for the week day names header.')\r
+ action="store", type="string",
+ dest="color_day_name", default="#999",
+ help='Color for the week day names header.')
self.OptionParser.add_option("--color-day",
- action="store", type="string",\r
- dest="color_day", default="#000",\r
- help='Color for the common day box.')\r
+ action="store", type="string",
+ dest="color_day", default="#000",
+ help='Color for the common day box.')
self.OptionParser.add_option("--color-weekend",
- action="store", type="string",\r
- dest="color_weekend", default="#777",\r
- help='Color for the weekend days.')\r
+ action="store", type="string",
+ dest="color_weekend", default="#777",
+ help='Color for the weekend days.')
self.OptionParser.add_option("--color-nmd",
- action="store", type="string",\r
- dest="color_nmd", default="#BBB",\r
- help='Color for the next month day, in enpty day boxes.')\r
+ action="store", type="string",
+ dest="color_nmd", default="#BBB",
+ help='Color for the next month day, in enpty day boxes.')
self.OptionParser.add_option("--month-names",
- action="store", type="string",\r
+ action="store", type="string",
dest="month_names", default='January February March April May June '+\
- 'July August September October November December',\r
+ 'July August September October November December',
help='The month names for localization.')
self.OptionParser.add_option("--day-names",
- action="store", type="string",\r
- dest="day_names", default='Sun Mon Tue Wed Thu Fri Sat',\r
- help='The week day names for localization.')\r
+ action="store", type="string",
+ dest="day_names", default='Sun Mon Tue Wed Thu Fri Sat',
+ help='The week day names for localization.')
def validate_options(self):
# Convert string names lists in real lists:
self.options.month_names = re.split( '\s+', m.group(1) )
m = re.match( '\s*(.*[^\s])\s*', self.options.day_names )
self.options.day_names = re.split( '\s+', m.group(1) )
- # Validate names lists:\r
+ # Validate names lists:
if len(self.options.month_names) != 12:
inkex.errormsg('The month name list "'+
str(self.options.month_names)+
self.options.month_names = ['January','February','March',
'April', 'May', 'June',
'July', 'August', 'September',
- 'October','November','December']\r
+ 'October','November','December']
if len(self.options.day_names) != 7:
inkex.errormsg('The day name list "'+
str(self.options.day_names)+
return cal2
def write_month_header(self, g, m):
- txt_atts = {'style': simplestyle.formatStyle(self.style_month),\r
+ txt_atts = {'style': simplestyle.formatStyle(self.style_month),
'x': str( (self.month_w - self.day_w) / 2 ),
'y': str( self.day_h / 5 ) }
- inkex.etree.SubElement(g, 'text', txt_atts).text = self.options.month_names[m-1]
+ inkex.etree.SubElement(g, 'text', txt_atts).text = unicode(self.options.month_names[m-1], "iso-8859-1")
gw = inkex.etree.SubElement(g, 'g')
week_x = 0
if self.options.start_day=='sun':
for wday in self.options.day_names:
- txt_atts = {'style': simplestyle.formatStyle(self.style_day_name),\r
+ txt_atts = {'style': simplestyle.formatStyle(self.style_day_name),
'x': str( self.day_w * week_x ),
'y': str( self.day_h ) }
- inkex.etree.SubElement(gw, 'text', txt_atts).text = wday
+ inkex.etree.SubElement(gw, 'text', txt_atts).text = unicode(wday, "iso-8859-1")
week_x += 1
else:
w2 = self.options.day_names[1:]
w2.append(self.options.day_names[0])
for wday in w2:
- txt_atts = {'style': simplestyle.formatStyle(self.style_day_name),\r
+ txt_atts = {'style': simplestyle.formatStyle(self.style_day_name),
'x': str( self.day_w * week_x ),
'y': str( self.day_h ) }
- inkex.etree.SubElement(gw, 'text', txt_atts).text = wday
+ inkex.etree.SubElement(gw, 'text', txt_atts).text = unicode(wday, "iso-8859-1")
week_x += 1
def create_month(self, m):
style = self.style_day
if self.is_weekend(week_x): style = self.style_weekend
if day == 0: style = self.style_nmd
- txt_atts = {'style': simplestyle.formatStyle(style),\r
+ txt_atts = {'style': simplestyle.formatStyle(style),
'x': str( self.day_w * week_x ),
'y': str( self.day_h * (week_y+2) ) }
if day==0 and not self.options.fill_edb:
txt_atts = {
'id': 'year_'+str(self.options.year) }
self.year_g = inkex.etree.SubElement(parent, 'g', txt_atts)
- txt_atts = {'style': simplestyle.formatStyle(self.style_year),\r
+ txt_atts = {'style': simplestyle.formatStyle(self.style_year),
'x': str( self.doc_w / 2 ),
'y': str( self.day_w * 1.5 ) }
inkex.etree.SubElement(self.year_g, 'text', txt_atts).text = str(self.options.year)
self.create_month(self.options.month)
-if __name__ == '__main__':\r
- e = SVGCalendar()\r
- e.affect()\r
+if __name__ == '__main__':
+ e = SVGCalendar()
+ e.affect()