home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / LanguageSelector / xkb.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  3.3 KB  |  88 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import libxml2
  5. import sys
  6.  
  7. class Variant:
  8.     
  9.     def __init__(self, name, desc, raw_desc):
  10.         self.name = name
  11.         self.desc = desc
  12.         self.raw_desc = raw_desc
  13.  
  14.     
  15.     def __str__(self):
  16.         return '%s: %s, %s' % (self.name, self.desc, self.raw_desc)
  17.  
  18.  
  19.  
  20. class Layout:
  21.     
  22.     def __init__(self, name, desc, raw_desc, short_desc, raw_short_desc, variants):
  23.         self.name = name
  24.         self.desc = desc
  25.         self.raw_desc = raw_desc
  26.         self.short_desc = short_desc
  27.         self.raw_short_desc = raw_short_desc
  28.         self.variants = variants
  29.  
  30.     
  31.     def __str__(self):
  32.         return self.desc % (self.raw_desc, self.short_desc, self.raw_short_desc, [], [], [ '%s' % x for x in self.variants ])
  33.  
  34.  
  35.  
  36. def get_all_layout_possibilities():
  37.     possibility_list = list()
  38.     doc = libxml2.parseFile('/etc/X11/xkb/rules/xorg.xml')
  39.     ctxt = doc.xpathNewContext()
  40.     for i in ctxt.xpathEval('/xkbConfigRegistry/layoutList/layout/configItem/name/text()'):
  41.         possibility_list.append(i.content)
  42.     
  43.     return possibility_list
  44.  
  45.  
  46. def get_variants(layout_node, lang):
  47.     variant_list = list()
  48.     variant_nodes = layout_node.xpathEval('../../../variantList/variant/configItem/name/text()')
  49.     for i in variant_nodes:
  50.         if len(i.xpathEval("../description[@xml:lang='%s']" % lang)) > 0:
  51.             trans = i.xpathEval("../description[@xml:lang='%s']" % lang)[0]
  52.         else:
  53.             trans = ''
  54.         v = Variant(i.content, trans, i.xpathEval('../../description[position()=1]')[0].content)
  55.         variant_list.append(v)
  56.     
  57.     return variant_list
  58.  
  59.  
  60. def get_layouts(lang):
  61.     layout_list = list()
  62.     doc = libxml2.parseFile('/etc/X11/xkb/rules/xorg.xml')
  63.     ctxt = doc.xpathNewContext()
  64.     layout_nodes = ctxt.xpathEval('/xkbConfigRegistry/layoutList/layout/configItem/name/text()')
  65.     for i in layout_nodes:
  66.         if i.content == lang:
  67.             if len(i.xpathEval("../description[@xml:lang='%s']" % lang)) > 0:
  68.                 translation = i.xpathEval("../description[@xml:lang='%s']" % lang)[0]
  69.             else:
  70.                 translation = ''
  71.             if len(i.xpathEval("../description[@xml:lang='%s']" % lang)) > 0:
  72.                 short_trans = i.xpathEval("../shortDescription[@xml:lang='%s']" % lang)[0]
  73.             else:
  74.                 short_trans = ''
  75.             layout_list.append(Layout(i.content, translation, i.xpathEval('../../description[position()=1]')[0].content, short_trans, i.xpathEval('../../shortDescription[position()=1]')[0].content, get_variants(i, lang)))
  76.             continue
  77.     
  78.     return layout_list
  79.  
  80. if __name__ == '__main__':
  81.     for i in get_layouts('fr'):
  82.         print i
  83.     
  84.     for i in get_all_layout_possibilities():
  85.         print i
  86.     
  87.  
  88.