Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import inkex
- from simplestyle import *
- import datetime
- class Calend(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=10.0,
- help="Month")
- self.OptionParser.add_option("--year",
- action="store", type="int",
- dest="year", default=10.0,
- help="Year")
- self.OptionParser.add_option("--start_month",
- action="store", type="string",
- dest="start_month",
- help="Startmonth")
- self.OptionParser.add_option("--start_week",
- action="store", type="string",
- dest="start_week",
- help="Start week")
- self.OptionParser.add_option("--hspace",
- action="store", type="int",
- dest="hspace", default=10.0,
- help="HSpace")
- self.OptionParser.add_option("--vspace",
- action="store", type="int",
- dest="vspace", default=10.0,
- help="VSpace")
- self.OptionParser.add_option("--weekend",
- action="store", type="string",
- dest="weekend",
- help="Weekend")
- self.OptionParser.add_option("--color_day",
- action="store", type="string",
- dest="color_day",
- help="Color day")
- self.OptionParser.add_option("--color_weekend",
- action="store", type="string",
- dest="color_weekend",
- help="Color weekend")
- self.OptionParser.add_option("--month_names",
- action="store", type="string",
- dest="month_names",
- help="Month names")
- self.OptionParser.add_option("--day_names",
- action="store", type="string",
- dest="day_names",
- help="Day names")
- def drawMonth(self):
- svg = self.document.getroot()
- layer = inkex.etree.SubElement(svg, 'g')
- week = self.options.day_names
- color_w = self.options.color_weekend
- color_d = self.options.color_day
- x = 0
- y = 0
- months = self.options.month_names
- mn = []
- while months.find(',') != -1: # Заполнение списка месяцев
- mn.append(months[0:months.find(',')])
- months = months[(months.find(',')+1):]
- text=inkex.etree.Element(inkex.addNS('text', 'svg'))
- text.text=mn[self.options.month-1]
- text.set('x', str(x))
- text.set('y', str(y))
- style = {'text-align' : 'center', 'text-anchor': 'start' }
- text.set('style', formatStyle(style))
- layer.append(text)
- x = x + 5*self.options.vspace
- text=inkex.etree.Element(inkex.addNS('text', 'svg'))
- text.text=str(self.options.year)
- text.set('x', str(x))
- text.set('y', str(y))
- style = {'text-align' : 'center', 'text-anchor': 'start' }
- text.set('style', formatStyle(style))
- layer.append(text)
- x=0
- y = y + self.options.hspace
- l=len(week)
- wd = []
- while week.find(',') != -1: # Заполнение списка дней недели
- wd.append(week[0:week.find(',')])
- week = week[(week.find(',')+1):]
- if self.options.start_week == 'mon': # Проверка нач. дня недели
- wd.append(week)
- mon = 1
- else:
- wd.insert(0,week)
- mon = 0
- for i in range(len(wd)): # Вывод дней недели
- text=inkex.etree.Element(inkex.addNS('text', 'svg'))
- text.text=wd[i]
- text.set('x', str(x))
- text.set('y', str(y))
- style = {'text-align' : 'center', 'text-anchor': 'start' }
- text.set('style', formatStyle(style))
- layer.append(text)
- x = x + self.options.vspace
- if self.options.year %4 == 0: # Проверка високосного года
- mcd=[31,29,31,30,31,30,31,31,30,31,30,31]
- else:
- mcd=[31,28,31,30,31,30,31,31,30,31,30,31]
- if mon == 1: # Смещение дня
- x=0 + (int(self.options.start_month)-1) * self.options.vspace
- else:
- x=0 + (int(self.options.start_month)) * self.options.vspace
- y = y + self.options.hspace
- for i in range(mcd[self.options.month-1]): # Вывод дней
- if x == self.options.vspace * len(wd):
- x = 0
- y = y + self.options.hspace
- text=inkex.etree.Element(inkex.addNS('text', 'svg'))
- text.text=str(i+1)
- text.set('x', str(x))
- text.set('y', str(y))
- if int(self.options.weekend) == 0 and mon == 1 and (x%5 == 0 or x%6 == 0):
- style = {'text-align' : 'center', 'text-anchor': 'start', 'fill': color_w }
- else:
- style = {'text-align' : 'center', 'text-anchor': 'start', 'fill': color_d }
- text.set('style', formatStyle(style))
- layer.append(text)
- x = x + self.options.vspace
- def effect(self):
- self.drawMonth()
- effect = Calend()
- effect.affect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement