Code

adding configurable system encoding input for calendar extension
authoraurium <aurium@users.sourceforge.net>
Mon, 26 Jan 2009 15:02:43 +0000 (15:02 +0000)
committeraurium <aurium@users.sourceforge.net>
Mon, 26 Jan 2009 15:02:43 +0000 (15:02 +0000)
share/extensions/svgcalendar.inx
share/extensions/svgcalendar.py

index 7a33639a74c3718cc1c514da33194d9d48a84528..d4bd3dbbedd0a3731765bfa991714d360d639eb2 100644 (file)
@@ -1,16 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
 <inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">\r
-  <_name>Calendar</_name>
+  <_name>Calendar</_name>\r
   <id>org.inkscape.calendar</id>\r
-
-  <dependency type="executable" location="extensions">svgcalendar.py</dependency>
+\r
+  <dependency type="executable" location="extensions">svgcalendar.py</dependency>\r
   <dependency type="executable" location="extensions">inkex.py</dependency>\r
-
+\r
   <param name="tab" type="notebook">\r
     <page name="tab" _gui-text="Configuration">\r
-      <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="Ano (0 for current)">0</param>
-      <param name="fill-empty-day-boxes" type="boolean" _gui-text="Fill empty day boxes with next month days">true</param>
+      <param name="month" type="int" min="0" max="12" _gui-text="Month (0 for all)">0</param>\r
+      <param name="year" type="int" min="0" max="3000" _gui-text="Ano (0 for current)">0</param>\r
+      <param name="fill-empty-day-boxes" type="boolean" _gui-text="Fill empty day boxes with next month days">true</param>\r
       <param name="start-day" type="enum" _gui-text="Week start day">\r
         <_item value="sun">Sunday</_item>\r
         <_item value="mon">Monday</_item>\r
         <_item value="sat">Saturday</_item>\r
         <_item value="sun">Sunday</_item>\r
       </param>\r
-    </page>
+    </page>\r
     <page name="tab" _gui-text="Colors">\r
-      <param name="color-year"     type="string" _gui-text="Year color">#808080</param>
-      <param name="color-month"    type="string" _gui-text="Month color">#686868</param>
-      <param name="color-day-name" type="string" _gui-text="Week day name color ">#909090</param>
-      <param name="color-day"      type="string" _gui-text="Day color">#000000</param>
-      <param name="color-weekend"  type="string" _gui-text="Weekend day color">#787878</param>
-      <param name="color-nmd"      type="string" _gui-text="Next month day color">#B0B0B0</param>
-    </page>
+      <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
+      <param name="color-day-name" type="string" _gui-text="Week day name color ">#909090</param>\r
+      <param name="color-day"      type="string" _gui-text="Day color">#000000</param>\r
+      <param name="color-weekend"  type="string" _gui-text="Weekend day color">#787878</param>\r
+      <param name="color-nmd"      type="string" _gui-text="Next month day color">#B0B0B0</param>\r
+    </page>\r
     <page name="tab" _gui-text="Localization">\r
       <_param name="l10n-help" type="description">You may change the names for other languages:</_param>\r
-      <_param name="month-names"  type="string" _gui-text="Month names">January February March April May June July August September October November December</_param>
-      <_param name="day-names"  type="string" _gui-text="Day names">Sun Mon Tue Wed Thu Fri Sat</_param>
+      <_param name="month-names"  type="string" _gui-text="Month names">January February March April May June July August September October November December</_param>\r
+      <_param name="day-names"  type="string" _gui-text="Day names">Sun Mon Tue Wed Thu Fri Sat</_param>\r
       <_param name="day-names-help" type="description">(The day name list must start in sunday)</_param>\r
-    </page>
-  </param>
-  <effect>
-    <object-type>all</object-type>
+      <param name="encoding" type="enum" _gui-text="Char Encoding">\r
+        <item>arabic</item>\r
+        <item>big5-tw</item>\r
+        <item>big5-hkscs</item>\r
+        <item>chinese</item>\r
+        <item>cp737</item>\r
+        <item>cp856</item>\r
+        <item>cp874</item>\r
+        <item>cp875</item>\r
+        <item>cp1006</item>\r
+        <item>cyrillic</item>\r
+        <item>cyrillic-asian</item>\r
+        <item>eucjis2004</item>\r
+        <item>eucjisx0213</item>\r
+        <item>gbk</item>\r
+        <item>gb18030-2000</item>\r
+        <item>greek</item>\r
+        <item>hebrew</item>\r
+        <item>hz-gb</item>\r
+        <item>IBM037</item>\r
+        <item>IBM424</item>\r
+        <item>IBM437</item>\r
+        <item>IBM500</item>\r
+        <item>IBM775</item>\r
+        <item>IBM850</item>\r
+        <item>IBM852</item>\r
+        <item>IBM855</item>\r
+        <item>IBM857</item>\r
+        <item>IBM860</item>\r
+        <item>IBM861</item>\r
+        <item>IBM862</item>\r
+        <item>IBM863</item>\r
+        <item>IBM864</item>\r
+        <item>IBM865</item>\r
+        <item>IBM866</item>\r
+        <item>IBM869</item>\r
+        <item>IBM1026</item>\r
+        <item>IBM1140</item>\r
+        <item>iso-2022-jp</item>\r
+        <item>iso-2022-jp-1</item>\r
+        <item>iso-2022-jp-2</item>\r
+        <item>iso-2022-jp-2004</item>\r
+        <item>iso-2022-jp-3</item>\r
+        <item>iso-2022-jp-ext</item>\r
+        <item>iso-2022-kr</item>\r
+        <item>johab</item>\r
+        <item>korean</item>\r
+        <item>koi8_r</item>\r
+        <item>koi8_u</item>\r
+        <item>latin1</item>\r
+        <item>latin2</item>\r
+        <item>latin3</item>\r
+        <item>latin4</item>\r
+        <item>latin5</item>\r
+        <item>latin6</item>\r
+        <item>latin8</item>\r
+        <item value="iso-8859-15">Latin - iso-8859-15 - Western Europe</item>\r
+        <item>macgreek</item>\r
+        <item>maciceland</item>\r
+        <item>maccentraleurope</item>\r
+        <item>macroman</item>\r
+        <item>macturkish</item>\r
+        <item>ms932</item>\r
+        <item>ms949</item>\r
+        <item>ms950</item>\r
+        <item>sjis</item>\r
+        <item>sjis2004</item>\r
+        <item>sjisx0213</item>\r
+        <item>u-jis</item>\r
+        <item>us-ascii</item>\r
+        <item value="windows-1250">Windows - Central and Eastern Europe</item>\r
+        <item value="windows-1251">Windows - Russian and more</item>\r
+        <item value="windows-1252">Windows - Western Europe</item>\r
+        <item value="windows-1253">Windows - Greek</item>\r
+        <item value="windows-1254">Windows - Turkish</item>\r
+        <item value="windows-1255">Windows - Hebrew</item>\r
+        <item value="windows-1256">Windows - Arabic</item>\r
+        <item value="windows-1257">Windows - Baltic languages</item>\r
+        <item value="windows-1258">Windows - Vietnamese</item>\r
+        <item value="utf_32">UTF-32 - All languages</item>\r
+        <item value="utf_16">UTF-16 - All languages</item>\r
+        <item value="utf_8">UTF-8 - All languages</item>\r
+      </param>\r
+      <_param name="encoding-help" type="description">(Select your system encoding. More information at http://docs.python.org/library/codecs.html#standard-encodings)</_param>\r
+    </page>\r
+  </param>\r
+  <effect>\r
+    <object-type>all</object-type>\r
     <effects-menu>\r
       <submenu _name="Render"/>\r
     </effects-menu>\r
-  </effect>
-  <script>
-    <command reldir="extensions" interpreter="python">svgcalendar.py</command>
-  </script>
-</inkscape-extension>
+  </effect>\r
+  <script>\r
+    <command reldir="extensions" interpreter="python">svgcalendar.py</command>\r
+  </script>\r
+</inkscape-extension>\r
index 0dca58fc5a409fd4ac4e978f547e9ef144b1cc86..7ba2f772a578de720aece672b45b91837abdc49c 100755 (executable)
@@ -22,7 +22,7 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 '''
 
-__version__ = "0.1"
+__version__ = "0.2"
 
 import inkex, simplestyle, re, calendar
 from datetime import *
@@ -87,8 +87,13 @@ class SVGCalendar (inkex.Effect):
           action="store", type="string",
           dest="day_names", default='Sun Mon Tue Wed Thu Fri Sat',
           help='The week day names for localization.')
+        self.OptionParser.add_option("--encoding",
+          action="store", type="string",
+          dest="input_encode", default='utf-8',
+          help='The input encoding of the names.')
 
     def validate_options(self):
+        #inkex.errormsg( self.options.input_encode )
         # Convert string names lists in real lists:
         m = re.match( '\s*(.*[^\s])\s*', self.options.month_names )
         self.options.month_names = re.split( '\s+', m.group(1) )
@@ -189,7 +194,11 @@ class SVGCalendar (inkex.Effect):
         txt_atts = {'style': simplestyle.formatStyle(self.style_month),
                     'x': str( (self.month_w - self.day_w) / 2 ),
                     'y': str( self.day_h / 5 ) }
-        inkex.etree.SubElement(g, 'text', txt_atts).text = unicode(self.options.month_names[m-1], "iso-8859-1")
+        try:
+          inkex.etree.SubElement(g, 'text', txt_atts).text = unicode(self.options.month_names[m-1], self.options.input_encode)
+        except:
+          inkex.errormsg('You must select your correct system encode.')
+          exit(1)
         gw = inkex.etree.SubElement(g, 'g')
         week_x = 0
         if self.options.start_day=='sun':
@@ -197,7 +206,11 @@ class SVGCalendar (inkex.Effect):
             txt_atts = {'style': simplestyle.formatStyle(self.style_day_name),
                         'x': str( self.day_w * week_x ),
                         'y': str( self.day_h ) }
-            inkex.etree.SubElement(gw, 'text', txt_atts).text = unicode(wday, "iso-8859-1")
+            try:
+              inkex.etree.SubElement(gw, 'text', txt_atts).text = unicode(wday, self.options.input_encode)
+            except:
+              inkex.errormsg('You must select your correct system encode.')
+              exit(1)
             week_x += 1
         else:
           w2 = self.options.day_names[1:]
@@ -206,7 +219,11 @@ class SVGCalendar (inkex.Effect):
             txt_atts = {'style': simplestyle.formatStyle(self.style_day_name),
                         'x': str( self.day_w * week_x ),
                         'y': str( self.day_h ) }
-            inkex.etree.SubElement(gw, 'text', txt_atts).text = unicode(wday, "iso-8859-1")
+            try:
+              inkex.etree.SubElement(gw, 'text', txt_atts).text = unicode(wday, self.options.input_encode)
+            except:
+              inkex.errormsg('You must select your correct system encode.')
+              exit(1)
             week_x += 1
 
     def create_month(self, m):