Code

Resolves the year 1 problem on the calendar render extension.
authorAurélio A. Heckert (a) <auriumgmaildotcom>
Wed, 3 Nov 2010 03:06:36 +0000 (00:06 -0300)
committerAurélio A. Heckert (a) <auriumgmaildotcom>
Wed, 3 Nov 2010 03:06:36 +0000 (00:06 -0300)
It includes the patch code by Craig Marshall, posted on bug492173
This commit changes the default inx year value and its description to stop misunderstands about how it works.

share/extensions/svgcalendar.inx
share/extensions/svgcalendar.py

index dee9da0c694f3759103cc3e4d4090dd440f3bfa5..56f5f62ab1b2dea5b13aa2d77a29bb9af1fe2f66 100644 (file)
@@ -6,8 +6,8 @@
     <dependency type="executable" location="extensions">inkex.py</dependency>
     <param name="tab" type="notebook">
         <page name="config" _gui-text="Configuration">
+            <param name="year" type="int" min="0" max="3000" _gui-text="Year (4 digits):">2011</param>
             <param name="month" type="int" min="0" max="12" _gui-text="Month (0 for all):">0</param>
-            <param name="year" type="int" min="0" max="3000" _gui-text="Year (0 for current):">0</param>
             <param name="fill-empty-day-boxes" type="boolean" _gui-text="Fill empty day boxes with next month's days">true</param>
             <param name="start-day" type="enum" _gui-text="Week start day">
                 <_item value="sun">Sunday</_item>
             <_param name="encoding-help" type="description">Select your system encoding. More information at http://docs.python.org/library/codecs.html#standard-encodings.</_param>
         </page>
     </param>
-    <effect>
+    <effect needs-live-preview="false">
         <object-type>all</object-type>
         <effects-menu>
           <submenu _name="Render"/>
index b62863927fee3b29653952512b993aca06935b7d..8390c33f732aa1ab8ff01461b3fd943eb2484996 100755 (executable)
@@ -131,6 +131,8 @@ class SVGCalendar (inkex.Effect):
           self.options.day_names = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
         # Convert year 0 to current year:
         if self.options.year == 0: self.options.year = datetime.today().year
+        # Year 1 starts it's week at monday, obligatorily
+        if self.options.year == 1: self.options.start_day = 'mon'
         # Set the calendar start day:
         if self.options.start_day=='sun':
           calendar.setfirstweekday(6)
@@ -266,8 +268,9 @@ class SVGCalendar (inkex.Effect):
         gdays = inkex.etree.SubElement(g, 'g')
         cal = calendar.monthcalendar(self.options.year,m)
         if m == 1:
-          before_month = \
-            self.in_line_month( calendar.monthcalendar(self.options.year-1, 12) )
+          if self.options.year > 1:
+            before_month = \
+              self.in_line_month( calendar.monthcalendar(self.options.year-1, 12) )
         else:
           before_month = \
             self.in_line_month( calendar.monthcalendar(self.options.year, m-1) )
@@ -297,8 +300,8 @@ class SVGCalendar (inkex.Effect):
                         'x': str( self.day_w * week_x ),
                         'y': str( self.day_h * (week_y+2) ) }
             if day==0 and not self.options.fill_edb:
-             pass # draw nothing
-           elif day==0:
+              pass # draw nothing
+            elif day==0:
               if before:
                 inkex.etree.SubElement(gdays, 'text', txt_atts).text = str( before_month[-bmd] )
                 bmd -= 1