Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.45 KB | None | 0 0
  1. import inkex
  2. from simplestyle import *
  3. import datetime
  4.  
  5. class Calend(inkex.Effect):
  6.     def __init__(self):
  7.         inkex.Effect.__init__(self)
  8.         self.OptionParser.add_option("--tab",
  9.           action="store", type="string",
  10.           dest="tab")
  11.         self.OptionParser.add_option("--month",
  12.             action="store", type="int",
  13.             dest="month", default=10.0,
  14.             help="Month")
  15.         self.OptionParser.add_option("--year",
  16.             action="store", type="int",
  17.             dest="year", default=10.0,
  18.             help="Year")
  19.         self.OptionParser.add_option("--start_month",
  20.             action="store", type="string",
  21.             dest="start_month",
  22.             help="Startmonth")
  23.         self.OptionParser.add_option("--start_week",
  24.             action="store", type="string",
  25.             dest="start_week",
  26.             help="Start week")
  27.         self.OptionParser.add_option("--hspace",
  28.             action="store", type="int",
  29.             dest="hspace", default=10.0,
  30.             help="HSpace")
  31.         self.OptionParser.add_option("--vspace",
  32.             action="store", type="int",
  33.             dest="vspace", default=10.0,
  34.             help="VSpace")
  35.         self.OptionParser.add_option("--weekend",
  36.             action="store", type="string",
  37.             dest="weekend",
  38.             help="Weekend")
  39.         self.OptionParser.add_option("--color_day",
  40.             action="store", type="string",
  41.             dest="color_day",
  42.             help="Color day")      
  43.         self.OptionParser.add_option("--color_weekend",
  44.             action="store", type="string",
  45.             dest="color_weekend",
  46.             help="Color weekend")
  47.         self.OptionParser.add_option("--month_names",
  48.             action="store", type="string",
  49.             dest="month_names",
  50.             help="Month names")
  51.         self.OptionParser.add_option("--day_names",
  52.             action="store", type="string",
  53.             dest="day_names",
  54.             help="Day names")
  55.    
  56.     def drawMonth(self):
  57.         svg = self.document.getroot()
  58.         layer = inkex.etree.SubElement(svg, 'g')
  59.         week = self.options.day_names
  60.         color_w = self.options.color_weekend
  61.         color_d = self.options.color_day
  62.         x = 0
  63.         y = 0
  64.         months = self.options.month_names
  65.         mn = []
  66.         while months.find(',') != -1: # Заполнение списка месяцев
  67.             mn.append(months[0:months.find(',')])
  68.             months = months[(months.find(',')+1):]
  69.         text=inkex.etree.Element(inkex.addNS('text', 'svg'))
  70.         text.text=mn[self.options.month-1]
  71.         text.set('x', str(x))
  72.         text.set('y', str(y))
  73.         style = {'text-align' : 'center', 'text-anchor': 'start' }
  74.         text.set('style', formatStyle(style))
  75.         layer.append(text)
  76.        
  77.         x = x + 5*self.options.vspace
  78.         text=inkex.etree.Element(inkex.addNS('text', 'svg'))
  79.         text.text=str(self.options.year)
  80.         text.set('x', str(x))
  81.         text.set('y', str(y))
  82.         style = {'text-align' : 'center', 'text-anchor': 'start' }
  83.         text.set('style', formatStyle(style))
  84.         layer.append(text)
  85.        
  86.         x=0
  87.         y = y + self.options.hspace
  88.         l=len(week)
  89.         wd = []
  90.         while week.find(',') != -1: # Заполнение списка дней недели
  91.             wd.append(week[0:week.find(',')])
  92.             week = week[(week.find(',')+1):]
  93.        
  94.         if self.options.start_week == 'mon': # Проверка нач. дня недели
  95.             wd.append(week)
  96.             mon = 1
  97.         else:
  98.             wd.insert(0,week)
  99.             mon = 0
  100.        
  101.         for i in range(len(wd)): # Вывод дней недели
  102.             text=inkex.etree.Element(inkex.addNS('text', 'svg'))
  103.             text.text=wd[i]
  104.             text.set('x', str(x))
  105.             text.set('y', str(y))
  106.             style = {'text-align' : 'center', 'text-anchor': 'start' }
  107.             text.set('style', formatStyle(style))
  108.             layer.append(text)
  109.             x = x + self.options.vspace
  110.        
  111.         if self.options.year %4 == 0: # Проверка високосного года
  112.             mcd=[31,29,31,30,31,30,31,31,30,31,30,31]
  113.         else:
  114.             mcd=[31,28,31,30,31,30,31,31,30,31,30,31]
  115.        
  116.         if mon == 1: # Смещение дня
  117.             x=0 + (int(self.options.start_month)-1) * self.options.vspace
  118.         else:
  119.             x=0 + (int(self.options.start_month)) * self.options.vspace
  120.         y = y + self.options.hspace
  121.        
  122.         for i in range(mcd[self.options.month-1]): # Вывод дней
  123.             if x == self.options.vspace * len(wd):
  124.                 x = 0
  125.                 y = y + self.options.hspace
  126.             text=inkex.etree.Element(inkex.addNS('text', 'svg'))
  127.             text.text=str(i+1)
  128.             text.set('x', str(x))
  129.             text.set('y', str(y))
  130.             if int(self.options.weekend) == 0 and mon == 1 and (x%5 == 0 or x%6 == 0):
  131.                 style = {'text-align' : 'center', 'text-anchor': 'start', 'fill': color_w }
  132.             else:
  133.                 style = {'text-align' : 'center', 'text-anchor': 'start', 'fill': color_d }
  134.             text.set('style', formatStyle(style))
  135.             layer.append(text)
  136.             x = x + self.options.vspace
  137.        
  138.     def effect(self):
  139.         self.drawMonth()
  140.  
  141. effect = Calend()
  142. effect.affect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement