Code

More options for Calendar extension
authoraurium <aurium@users.sourceforge.net>
Sat, 4 Apr 2009 15:38:23 +0000 (15:38 +0000)
committeraurium <aurium@users.sourceforge.net>
Sat, 4 Apr 2009 15:38:23 +0000 (15:38 +0000)
share/extensions/svgcalendar.inx
share/extensions/svgcalendar.py

index e2368965ef69d69efe1b59b45ce546fe9f9a87e5..8d8f2d5670c8d3fcdf70f2c97844596253e3f901 100644 (file)
         <_item value="sun">Sunday</_item>\r
       </param>\r
     </page>\r
+    <page name="tab" _gui-text="Organization">\r
+      <param name="auto-organize" type="boolean" _gui-text="Set authomaticaly the size and positions">true</param>\r
+      <_param name="organize-help" type="description">The options above has no value with the upper checked.</_param>\r
+      <param name="months-per-line" type="int" min="1" max="12" _gui-text="Months per line">3</param>
+      <param name="month-width" type="string" _gui-text="Month Width">6cm</param>
+      <param name="month-margin" type="string" _gui-text="Month Margin">1cm</param>\r
+    </page>\r
     <page name="tab" _gui-text="Colors">\r
       <param name="color-year"     type="string" _gui-text="Year color">#808080</param>\r
       <param name="color-month"    type="string" _gui-text="Month color">#686868</param>\r
index 7ba2f772a578de720aece672b45b91837abdc49c..5f70bc3c6e766ab193e2b301b1d6d2e7fe2272ce 100755 (executable)
@@ -54,6 +54,22 @@ class SVGCalendar (inkex.Effect):
           action="store", type="string",
           dest="weekend", default="sat+sun",
           help='Define the weekend days. ("sat+sun" or "sat" or "sun")')
+        self.OptionParser.add_option("--auto-organize",
+          action="store", type="inkbool",
+          dest="auto_organize", default=True,
+          help='Authomaticaly set the size and positions.')
+        self.OptionParser.add_option("--months-per-line",
+          action="store", type="int",
+          dest="months_per_line", default=3,
+          help='Number of months side by side.')
+        self.OptionParser.add_option("--month-width",
+          action="store", type="string",
+          dest="month_width", default="6cm",
+          help='The width of the month days box.')
+        self.OptionParser.add_option("--month-margin",
+          action="store", type="string",
+          dest="month_margin", default="1cm",
+          help='The space between the month boxes.')
         self.OptionParser.add_option("--color-year",
           action="store", type="string",
           dest="color_year", default="#888",
@@ -120,21 +136,32 @@ class SVGCalendar (inkex.Effect):
           calendar.setfirstweekday(6)
         else:
           calendar.setfirstweekday(0)
+        # Convert string numbers with unit to user space float numbers:
+        self.options.month_width  = inkex.unittouu( self.options.month_width )
+        self.options.month_margin = inkex.unittouu( self.options.month_margin )
 
     # initial values:
     month_x_pos = 0
     month_y_pos = 0
 
     def calculate_size_and_positions(self):
+        #month_margin month_width months_per_line auto_organize
         self.doc_w = inkex.unittouu(self.document.getroot().get('width'))
         self.doc_h = inkex.unittouu(self.document.getroot().get('height'))
-        if self.doc_h > self.doc_w:
-          self.months_per_line = 3
+        if self.options.auto_organize:
+          if self.doc_h > self.doc_w:
+            self.months_per_line = 3
+          else:
+            self.months_per_line = 4
         else:
-          self.months_per_line = 4
+          self.months_per_line = self.options.months_per_line
         #self.month_w = self.doc_w / self.months_per_line
-        self.month_w = (self.doc_w * 0.8) / self.months_per_line
-        self.month_margin = self.month_w / 10
+        if self.options.auto_organize:
+          self.month_w = (self.doc_w * 0.8) / self.months_per_line
+          self.month_margin = self.month_w / 10
+        else:
+          self.month_w = self.options.month_width
+          self.month_margin = self.options.month_margin
         self.day_w = self.month_w / 7
         self.day_h = self.month_w / 9
         self.month_h = self.day_w * 7