
    BPcL                         d Z dZddlZddlZddlZddlZddlZddlmZ ddlm	Z
 ej        d         dk    rd Z G d d	ej                  Zed
k    r e                                             dS dS )a  
A calendar generator plugin for Inkscape, but also can be used as a standalone
command line application.
#
More on ISO week number calculation on:
http://en.wikipedia.org/wiki/ISO_week_date
(The first week of a year is the week that contains the first Thursdayof the year.)
z0.4    N)TextElement)inkex_gettext   c                 Z    t          | t                    r|                     |          S | S )z"Compatibility for python 2 strings)
isinstancebytesdecode)
stringlikeencodings     -/usr/share/inkscape/extensions/svgcalendar.pyunicoder   +   s.    j%(( 	/$$X...    c                   N    e Zd ZdZd Zd ZdZdZdZd Z	d Z
d Zd Zd	 Zd
 ZdS )CalendarzGenerate Calendar in SVGc                    |                     dt          d           |                     dt          dd           |                     dt          dd	           |                     d
t          j        ddd           |                     dt          j        ddd           |                     ddd           |                     ddd           |                     dt          j        ddd           |                     dt          ddd            |                     d!t          d"d#d$           |                     d%t          d&d'd(           |                     d)t          j        d*t          j        d+          d,           |                     d-t          j        d.t          j        d/          d0           |                     d1t          j        d2t          j        d3          d4           |                     d5t          j        d6t          j        d7          d8           |                     d9t          j        d:t          j        d;          d<           |                     d=t          j        d>t          j        d?          d@           |                     dAt          j        dBt          j        d;          dC           |                     dDt          dEdFdG           |                     dHt          dIdFdJ           |                     dKt          dLdFdM           |                     dNt          dOdFdP           |                     dQt          dRdSdT           |                     dUt          dVdWdX           |                     dYt          dZd[d\           |                     d]t          d^d_d`           d S )aNz--tabtab)typedestz--monthr   zCMonth to be generated. If 0, then the entry year will be generated.)r   defaulthelpz--yearzDYear to be generated. If 0, then the current year will be generated.z--fill-empty-day-boxesfill_edbTz*Fill empty day boxes with next month days.)r   r   r   r   z--show-week-numbershow_weeknrFzInclude a week number column.z--start-daysunz Week start day. ("sun" or "mon"))r   r   z	--weekendsat+sunz6Define the weekend days. ("sat+sun" or "sat" or "sun")z--auto-organizeauto_organizez)Automatically set the size and positions.z--months-per-linemonths_per_line   zNumber of months side by side.z--month-widthmonth_width6cmz The width of the month days box.z--month-marginmonth_margin1cmz"The space between the month boxes.z--color-year
color_yearl     zColor for the year header.z--color-monthcolor_monthihhhz Color for the month name header.z--color-day-namecolor_day_namel   !! z$Color for the week day names header.z--color-day	color_day   zColor for the common day box.z--color-weekendcolor_weekendixxxzColor for the weekend days.z--color-nmd	color_nmdl   0aa z1Color for the next month day, in empty day boxes.z--color-weeknrcolor_weeknrzColor for the week numbers.z--font-year	font_yeararialzFont for the year string.z--font-month
font_monthzFont for the month strings.z--font-day-namefont_day_namez&Font for the days of the week strings.z
--font-dayfont_dayzFont for the day strings.z--month-namesmonth_nameszUJanuary February March April May June July August September October November Decemberz!The month names for localization.z--day-names	day_nameszSun Mon Tue Wed Thu Fri Satz$The week day names for localization.z--weeknr-nameweeknr_nameWkz-The week number column name for localization.z
--encodinginput_encodearabicz The input encoding of the names.)add_argumentstrintinkexBooleanColor)selfparss     r   add_argumentszCalendar.add_arguments5   s   '%888V	 	 	
 	
 	
 	W	 	 	
 	
 	
 	$= 	 	
 	
 	
 	 0 	 	
 	
 	
 	5/Q 	 	
 	
 	
 	I 	 	
 	
 	

 	 < 	 	
 	
 	
 	"1 	 	
 	
 	
 	3 	 	
 	
 	
 	5 	 	
 	
 	
 	K
++- 	 	
 	
 	
 	K
++3 	 	
 	
 	
 	!K
++7 	 	
 	
 	
 	K
++0 	 	
 	
 	
 	 K
++. 	 	
 	
 	
 	K
++D 	 	
 	
 	
 	K
++. 	 	
 	
 	
 	, 	 	
 	
 	
 	. 	 	
 	
 	
 	 9 	 	
 	
 	
 	, 	 	
 	
 	
 	  5 	 		
 		
 		
 	17 	 	
 	
 	
 	@ 	 	
 	
 	
 	3 	 	
 	
 	
 	
 	
r   c                    t          j        d| j        j                  }t          j        d|                    d                    | j        _        t          j        d| j        j                  }t          j        d|                    d                    | j        _        t          | j        j                  dk    r?t          j	        dt          | j        j                  z   dz              g d| j        _        t          | j        j                  dk    r?t          j	        d	t          | j        j                  z   dz              g d
| j        _        | j        j        dk    r-t          j                                        j        | j        _        | j        j        dk    rd| j        _        | j        j        dk    rt          j        d           nt          j        d           | j                            | j        j                  | j        _        | j                            | j        j                  | j        _        dS )z&Validity check for various text inputsz\s*(.*[^\s])\s*z\s+      zThe month name list "z" is invalid. Using default.)JanuaryFebruaryMarchAprilMayJuneJulyAugust	SeptemberOctoberNovemberDecember   zThe day name list ")SunMonTueWedThuFriSatr   monr      N)rematchoptionsr/   splitgroupr0   lenr8   errormsgr6   yeardatetimetoday	start_daycalendarsetfirstweekdaysvgunittouur   r    )r;   
month_names     r   validate_optionszCalendar.validate_options   s    X0$,2JKK
#%8FJ4D4DQ4G4G#H#H X0$,2HII
!#&*2B2B12E2E!F!F t|'((B..N'dl.//001  
( ( (DL$ t|%&&!++N%dl,--.01  
 &W%V%VDL"<!! ( 1 7 7 9 9 >DL<!!%*DL"<!U**$Q''''$Q'''#'8#4#4T\5M#N#N $(H$5$5dl6O$P$P!!!r   r   c                    | j                             | j                                                            d                    | _        | j                             | j                                                            d                    | _        | j        j        rd| _	        nd| _	        | j        j
        r | j        | j        k    rd| _        nd| _        n| j        j        | _        | j        j
        r'| j        dz  | j        z  | _        | j        dz  | _        n"| j        j        | _        | j        j        | _        | j        d	| j	        z   z  | _        | j        d
z  | _        | j        d	z  | _        | j        j        dk    r;| j        | j        z   | j        | j        z  z
  | j        | j        dz
  z  z
  dz  | _        n| j        | j        z
  dz  | _        t)          | j        dz            | j        j        dd| j        j        d| _        | j                                        | _        | j        j        | j        d<   | j                                        | _        | j        j        | j        d<   | j                                        | _        | j        j        | j        d<   | j        j        | j        d<   t)          | j        dz            | j        d<   d| j        d<   | j                                        | _         | j        j!        | j         d<   | j        j"        | j         d<   t)          | j        dz            | j         d<   | j                                        | _#        | j        j$        | j#        d<   | j        j%        | j#        d<   t)          | j        dz            | j#        d<   d| j#        d<   | j                                        | _&        | j        j'        | j&        d<   t)          | j        dz            | j&        d<   dS )z6month_margin month_width months_per_line auto_organizewidthheightr?   r   r      g?
   rM   	   r   middlecenter)	font-sizefont-familyztext-anchorz
text-alignfillrr   rq         ?rp   boldzfont-weightN)(rd   re   documentgetrootgetdoc_wdoc_hrY   r   cols_beforer   r   month_wr    r   day_wday_hmonth_hmonthyear_marginr6   r.   r%   	style_daycopystyle_weekendr'   	style_nmdr(   style_monthr#   r,   style_day_namer$   r-   
style_yearr"   r*   style_weeknrr)   )r;   s    r   calculate_size_and_positionsz%Calendar.calculate_size_and_positions  s   X&&t}'<'<'>'>'B'B7'K'KLL
X&&t}'<'<'>'>'B'B8'L'LMM
<# 	! D D<% 	@zDJ&&'($$'($$#'<#?D <% 	: J,0DDDL $r 1D<3DL $ 9D\Q)9%9:
\A%
zA~<""
*<$"668 $(<q(@AC  D !%
T\ 9Q>DTZ!^,,<0#"L*
 
 "^0022%)\%?6",,..!%!7v>..00#'<#; *.,*A'(+DJ,<(=(=%*0'"n1133&*l&AF#-1\-GM*+.tzA~+>+>K(.--//"&,"9)-)?&'*4:>':':$)/& N//11$(L$=&!),TZ!^)<)<+&&&r   c                    | j         j        dk    ra| j         j        dk    r|dk    rdS | j         j        dk    r|dk    rdS | j         j        dk    r|dk    rdS | j         j        dk    r|dk    rdS n`| j         j        dk    r|dk    rdS | j         j        dk    r|dk    rdS | j         j        dk    r|dk    rdS | j         j        dk    r|dk    rdS dS )	zADetect weekend days; weekend values: "sat+sun" or "sat" or "sun" r   r   r   TrV   sat   F)rY   ra   weekend)r;   poss     r   
is_weekendzCalendar.is_weekendZ  s    <!U**|#y00SAXXt|#y00SAXXt|#u,,t|#u,,t|#y00SAXXt|#y00SAXXt|#u,,t|#u,,tur   c                 T    g }|D ]"}|D ]}|dk    r|                     |           #|S )z!Lay out days of week in each weekr   )append)r;   calcal2weekdays        r   in_line_monthzCalendar.in_line_monthp  sM     	% 	%D % %!88KK$$$% r   c           	      z   t          t          j        | j                            t          | j        | j        z
  dz            t          | j        dz            d}	 t          | j        j	        |dz
           | j        j
                  |                    t          d	i |          _        n!#  t          t          d                    xY w|                    t          j                              }d}| j        j        dk    r| j        j        dd         }n9| j        j        dd         }|                    | j        j        d                    | j        j        r |                    d| j        j                   |D ]}t          t          j        | j                            t          | j        |z            t          | j                  d}	 t          || j        j
                  |                    t          d	i |          _        n!#  t          t          d                    xY w|dz  }dS )
zWrite month headerr   r   stylexyr?   z*You must select a correct system encoding.r   r   N )r6   r8   Styler   r{   r|   r}   r   rY   r/   r3   addr   text
ValueError_Groupra   r0   r   r   insertr1   r   )r;   gmtxt_atts
week_groupweek_xr0   wdays           r   write_month_headerzCalendar.write_month_headery  s!    T%56677dlTZ/1455TZ!^$$
 

	N29(Q/1J3 3AEE+))))**//	NQKLLMMMUU5;==))
<!U**.qqq1II.qrr2IT\3A6777<# 	:Q 8999 	 	DU[)<==>>f,--__ H
R?F$,3@ @
{66X6677<<R #O!P!PQQQaKFF	 	s   AB. .C<HH2c           
         dt          | j        | j        | j        z   | j        z  z             z   dz   t          | j        dz  | j        | j        z  z             z   dz   dt          |          z   dz   t          | j        j	                  z   d}| j
                            t          j        di |          }|                     ||           |                    t          j                              }t          j        | j        j	        |          }|dk    rF| j        j	        dk    r5|                     t          j        | j        j	        dz
  d	                    }n5|                     t          j        | j        j	        |dz
                      }|d	k    r6|                     t          j        | j        j	        dz   d                    }n5|                     t          j        | j        j	        |dz                       }t%          |          d
k     r|                    g d           t%          |          d
k     r?|                                 |                    g d           |                                 |d                             d          |d                             d          z   }d}	d}
|D ]}| j        dk    r8| j        j        dk    r|d         dk    s_| j        j        dk    r|d         dk    sC| j        dk    rH| j        j        dk    r|d         dk    s| j        j        dk    r|d         dk    r| xj        dz  c_        d}| j        j        r| j        dk    r|d         dk    r|d
         dk    s| j        }t          t          j        |                    t          | j        |z            t          | j        |
dz   z            d}t          | j                  |                    t9          di |          _        |dz  }n|dz  }|D ]}| j        }|                     || j         z
            r| j!        }|dk    r| j"        }t          t          j        |                    t          | j        |z            t          | j        |
dz   z            d}d}|dk    r| j        j#        snP|dk    r9|	rt          ||                    }|dz  }n,t          ||                   }|dz  }nt          |          }d}	|r$||                    t9          di |          _        |dz  }|
dz  }
| xj        dz  c_        | j        | j$        k    rd| _        | xj        dz  c_        dS dS )z*Lay out one month in place on the calendarz
translate(,rk   )month_r   )	transformidr?   r@   rV   )r   r   r   r   r   r   r   r   TrU   r   r   r   r   NFr   )%r6   r   r{   r    month_x_posr}   r~   month_y_posrY   r^   year_gr   r8   r   r   rb   monthcalendarr   r\   r   reversecountweeknrra   r   r   r   r|   r   r   r   r   rz   r   r   r   r   )r;   r   r   r   gdaysr   before_month
next_monthbmdbeforeweek_yr   r   r   r   r   s                   r   create_monthzCalendar.create_month  s    & DL43D$DHX#XX  	
 4:>dlT5E&EFGGH  SVV#c)C0A,B,BB	
 	
 KOOEK33(33441%%%ekmm$$$T\%6::66| 1$$#11*4<+<q+@"EE     --&t|'8!a%@@ L 77++&t|'81'<a@@ JJ ++&t|'8!a%@@ J s88a<<JJ,,,---s88a<<KKMMMJJ,,,---KKMMM!fll1ooAQ/ 8	 8	Dq  \+u44aA.%77DGqLL q  \+u44a1.%77DGaKK q F|'  ;!##T!W\\d1gll -E!$U[%7%7!8!8 f!455 vz!:;;   H
 ?B$+>N>NEIIk55H5566;aKFFaKF  ??6D,<#<== / .E!88 NE U!3!344TZ&011TZ6A:677 
 !88DL$98AXX !"<#566q":c?33qs88D"F C>BEIIk55H5566;!aKFFAt333 D! 43r   c                 b   |                                   |                                  | j                                        }ddt	          | j        j                  z   i}|                    t          j	        d	i |          | _
        t	          t          j        | j                            t	          | j        dz            t	          | j        dz            d}t	          | j        j                  | j
                            t          d	i |          _        	 | j        j        dk    r)t%          dd          D ]}|                     |           n|                     | j        j                   n8# t(          $ r+}t          j        t	          |                    cY d }~S d }~ww xY wd S )
Nr   year_r   rs   r   r   r?      r   )rg   r   ru   rv   r6   rY   r^   r   r8   r   r   r   r   rx   r|   r   r   r   ranger   r   r]   )r;   parentr   r   errs        r   effectzCalendar.effect  s   ))+++&&(('C(9$:$::;jj!8!8x!8!899T_5566TZ!^$$TZ#%&&
 

 9<DL<M8N8N//h//005	,|!Q&&q" ) )A%%a(((() !!$,"4555 	, 	, 	,>#c((++++++++	,ts   AE7 7
F, F'!F,'F,N)__name__
__module____qualname____doc__r=   rg   r   r   r   r   r   r   r   r   r   r   r   r   r   r   2   s        ""k
 k
 k
Z2Q 2Q 2Qj KKF== == ==~  ,  & & &Pi" i" i"V    r   r   __main__)r   __version__r_   rb   rW   sysr8   r   inkex.localizationr   r   version_infor   EffectExtensionr   r   runr   r   r   <module>r      s   *     				 



        1 1 1 1 1 1A  n n n n nu$ n n nb zHJJNN r   