From d04fdb8e3c74ab565590728d96c52b5f3bbedf98 Mon Sep 17 00:00:00 2001 From: aurium Date: Mon, 26 Jan 2009 15:02:43 +0000 Subject: [PATCH] adding configurable system encoding input for calendar extension --- share/extensions/svgcalendar.inx | 136 +++++++++++++++++++++++++------ share/extensions/svgcalendar.py | 25 +++++- 2 files changed, 131 insertions(+), 30 deletions(-) diff --git a/share/extensions/svgcalendar.inx b/share/extensions/svgcalendar.inx index 7a33639a7..d4bd3dbbe 100644 --- a/share/extensions/svgcalendar.inx +++ b/share/extensions/svgcalendar.inx @@ -1,16 +1,16 @@ - <_name>Calendar + <_name>Calendar org.inkscape.calendar - - svgcalendar.py + + svgcalendar.py inkex.py - + - 0 - 0 - true + 0 + 0 + true <_item value="sun">Sunday <_item value="mon">Monday @@ -20,29 +20,113 @@ <_item value="sat">Saturday <_item value="sun">Sunday - + - #808080 - #686868 - #909090 - #000000 - #787878 - #B0B0B0 - + #808080 + #686868 + #909090 + #000000 + #787878 + #B0B0B0 + <_param name="l10n-help" type="description">You may change the names for other languages: - <_param name="month-names" type="string" _gui-text="Month names">January February March April May June July August September October November December - <_param name="day-names" type="string" _gui-text="Day names">Sun Mon Tue Wed Thu Fri Sat + <_param name="month-names" type="string" _gui-text="Month names">January February March April May June July August September October November December + <_param name="day-names" type="string" _gui-text="Day names">Sun Mon Tue Wed Thu Fri Sat <_param name="day-names-help" type="description">(The day name list must start in sunday) - - - - all + + arabic + big5-tw + big5-hkscs + chinese + cp737 + cp856 + cp874 + cp875 + cp1006 + cyrillic + cyrillic-asian + eucjis2004 + eucjisx0213 + gbk + gb18030-2000 + greek + hebrew + hz-gb + IBM037 + IBM424 + IBM437 + IBM500 + IBM775 + IBM850 + IBM852 + IBM855 + IBM857 + IBM860 + IBM861 + IBM862 + IBM863 + IBM864 + IBM865 + IBM866 + IBM869 + IBM1026 + IBM1140 + iso-2022-jp + iso-2022-jp-1 + iso-2022-jp-2 + iso-2022-jp-2004 + iso-2022-jp-3 + iso-2022-jp-ext + iso-2022-kr + johab + korean + koi8_r + koi8_u + latin1 + latin2 + latin3 + latin4 + latin5 + latin6 + latin8 + Latin - iso-8859-15 - Western Europe + macgreek + maciceland + maccentraleurope + macroman + macturkish + ms932 + ms949 + ms950 + sjis + sjis2004 + sjisx0213 + u-jis + us-ascii + Windows - Central and Eastern Europe + Windows - Russian and more + Windows - Western Europe + Windows - Greek + Windows - Turkish + Windows - Hebrew + Windows - Arabic + Windows - Baltic languages + Windows - Vietnamese + UTF-32 - All languages + UTF-16 - All languages + UTF-8 - All languages + + <_param name="encoding-help" type="description">(Select your system encoding. More information at http://docs.python.org/library/codecs.html#standard-encodings) + + + + all - - - + + + diff --git a/share/extensions/svgcalendar.py b/share/extensions/svgcalendar.py index 0dca58fc5..7ba2f772a 100755 --- a/share/extensions/svgcalendar.py +++ b/share/extensions/svgcalendar.py @@ -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): -- 2.30.2